CLVM compiler.
Low maintenance activity. Last release over 2 years ago, commits in 4 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install clvm-toolsIntroduction
This is the in-development version of clvm_tools for clvm, which implements, a LISP-like language for encumbering and releasing funds with smart-contract capabilities.
Set up
Set up your virtual environments
$ python3 -m venv venv
$ . ./venv/bin/activate (windows: venv\Scripts\activate.bat)
$ pip install -e .
If you run into any issues, be sure to check out this section of the wiki
Optionally, run unit tests for a sanity check.
$ pip install pytest
$ py.test tests
Quick examples
The language has two components: the higher level language and the compiled lower level language which runs on the clvm. To compile the higher level language into the lower level language use:
$ run '(mod ARGUMENT (+ ARGUMENT 3))'
(+ 1 (q . 3))
To execute this code:
$ brun '(+ 1 (q . 3))' '2'
5
The Compiler
Basic example
The high level language is a superset of clvm, adding several operators. The main supported operator is mod which lets you define a set of macros and functions, and an entry point that calls them. Here's an example.
(mod (INDEX)
(defun factorial (VALUE) (if (= VALUE 1) 1 (* VALUE (factorial (- VALUE 1)))))
(factorial INDEX)
)
You can copy this to a file fact.clvm, then compile it with run fact.clvm and you'll see output like
(a (q 2 2 (c 2 (c 5 ()))) (c (q 2 (i (= 5 (q . 1)) (q 1 . 1) (q 18 5 (a 2 (c 2 (c (- 5 (q . 1)) ()))))) 1) 1))
You can then run this code with brun, passing in a parameter. Or pipe it using this bash quoting trick:
$ brun "`run fact.clvm`" "(5)"
120
This affirms that 5! = 120.
Auto-quoting of literals
Note that the 1 is not quoted. The compiler recognizes and auto-quotes constant values.
$ run 15
15
$ brun 15
FAIL: not a list 15
Known operators
Besides mod and defun, the compiler has a few more built-in operators:
@
Instead of evaluating 1 to return the arguments, you should use in the higher level language.
This is easier for humans to read, and calling will be compiled to 2, etc.