After writing , and , using JavaScript as implementation language, I started to use these projects to design and build a simple programming language compiler: . As usual, I’m using TDD (Test-Driven Development) as code workflow. It helps me to follow KISS (keep-it-simple-stuped), baby steps, and emergent design.
The target of compilation is the Virtual Machine. The process of compilation is:
Current implementation is still incomplete, but a sample with code, compilation, deploy and invocation .
The code of the simple contract is
contract Counterpublic void increment()
public void add(uint value)
}
You can compile the code with
node compile
And you can compile, deploy to (usually a ganache-cli node instance), and invoke it, executing:
node deploy
The only type supported is uint (unsigned 32 bytes integer). Next steps:
- Support for other numeric types
- Support for static and dynamic arrays (a bit challenging, memory management with bytecodes)
- Support for strings (another challenge: using keccak256 hash functions to allocate dynamically the string in 32-bytes storage cells)
- Constructor code (it’s code that is used only once, and should be compiled in different ways)
- Inheritance
Related posts:
Angel “Java” Lopez
Published at Tue, 21 May 2019 15:21:17 +0000