BlockstreamResearch / rust-simplicity

Creative Commons Zero v1.0 Universal
58 stars 12 forks source link

Human-readable encoding 1: serialization and README #152

Closed apoelstra closed 1 year ago

apoelstra commented 1 year ago

This PR introduces the human-readable serialization of Simplicity programs. Right now it will serialize disconnect nodes as having only one child (and the next PR will parse such programs). Later, when we introduce typed holes, we will correct this so that disconnect nodes always have two children (the rightmost one being a named hole). But for now disconnect is more-or-less unusable. To avoid too much complexity at once I think this is a reasonable order of operations.

It also slightly changes the syntax from the last PR to allow ' in symbol names. This is so I can do stuff like x' := pair x unit or whatever, where I use the prime symbol to indicate a slightly tweaked version of a different expression.

apoelstra commented 1 year ago

I have a crappy CLI tool that I've been mostly interacting with this code through. If you'd like I can clean that up a little and add it to this PR, so you can feed it hex-encoded Simplicity programs and get the serialization.

Could also finally switch to base64..

sanket1729 commented 1 year ago

I started reviewing this PR. Only read the README so far. Will play around with this over the next couple days.

Any CLI tool would be helpful. it doesn't have to be cleaned up. I can navigate through the CLI code to figure out stuff

apoelstra commented 1 year ago

@sanket1729 you may also be interested in the full branch (which I keep reasonably up to date) https://github.com/BlockstreamResearch/rust-simplicity/tree/2023-06--simplang which includes the CLI tool and also parsing logic.

apoelstra commented 1 year ago

Updated README and also removed the name_map from Program because I don't use it yet and it was complicating some later code. Will restore it in a later PR.

uncomputable commented 1 year ago

Resolved. ~This error message confused me because bound 1 looks like bound one.~

diff --git a/src/types/mod.rs b/src/types/mod.rs
index cdf106b..1ddb37d 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -128,7 +128,7 @@ impl fmt::Display for Error {
             } => {
                 write!(
                     f,
-                    "failed to apply bound {} to existing bound {}: {}",
+                    "failed to apply bound `{}` to existing bound `{}`: {}",
                     new_bound, existing_bound, hint,
                 )
             }
apoelstra commented 1 year ago

Force pushed to

apoelstra commented 1 year ago

No other changes.

apoelstra commented 1 year ago

Changed :: to : and updated README again.

We have another TODO to change # to #{...} but I think we can do that in a followup PR. Up to you.