Protean-Labs / mesh

The Mesh Engine that implements the Mesh Language, a computational language for web3.
Apache License 2.0
1 stars 0 forks source link

Add mechanism for loading modules in environment #52

Closed cvauclair closed 3 years ago

cvauclair commented 3 years ago

Description

The Mesh Engine should support loading (opening) modules.

Proposed approach

Add grammar support for the open keyword which will be used to load modules into the environment.

Two approaches are possible to handle the type checking and evaluation of Mesh expressions involving modules. Let E = [E0, ..., EN] be the list of expressions in a Mesh code block and let the module M be opened in the first expression of the block (i.e.: the first expression is an open expression). Let F = [F0, ..., FM] be the variables defined in the module M. Then either:

  1. All expressions in F are type-checked and evaluated. The type signatures are loaded into the type environment and the values are loaded into the value environment. All expressions in E are type-checked and evaluated using these updated environments.
  2. All expressions in F are prepended to E and the resulting implicit Mesh code block E' = [F0, ..., FM, E0, ..., EN] is evaluated normally.