essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

Refactor the `Contract`/`Predicate` data types. #774

Closed otrho closed 2 months ago

otrho commented 3 months ago

While implementing the compiler the design of the language has changed, from having a single 'root' implicit predicate only, to having a 'root' predicate along with optional 'child' predicates, to now having no 'root' predicate and only explicit named predicates.

The data structures used to represent a collection of predicates is now unfit for use. In particular, much of what was in the implicit predicate is copied into the child predicates as they're created, which is data that can go stale and also breaks values which are in a global namespace, especially const declarations.

The solution is to move most of what is in a Predicate back into the Contract. The predicate declarations have namespaces though and some data need to remain in the explicit predicate structs.

But which items should be allowed to be declared within predicate { ... } blocks? Currently the parser accepts anything except macros, storage, interfaces and consts.

This is probably OK. We could perhaps also disallow enum and new-type declarations (or they should at least be stored in the Contract and namespaced to the Predicate). Vars, state, constraints, if/else, non-expression macro calls and instances are the other items currently allowed.

All expressions must be stored in the Contract and only referred to from the Predicates though.

Tasks