Chia-Network / clvm_tools_rs

clvm_tools ported to rust based on https://github.com/Chia-Mine/clvm_tools-js/, and chialisp-21 dialect with a new compiler.
Apache License 2.0
11 stars 13 forks source link

"module style" chialisp. moves toplevel forms to the top level (instead of enclosed) and allows import to be more intelligent ala es2015. Introduces namespaces. #62

Open prozacchiwawa opened 8 months ago

prozacchiwawa commented 8 months ago

new forms:

(import std.prelude) ;; spills contents of std.prelude into the current namespace
(import qualified std.hash) ;; if shatree is in std.hash, adds std.hash.shatree into this namespace
(import qualified std.hash as H) ;; as above, but adds H.shatree
(import std.hash exposing shatree sha) ;; Adds only shatree and sha to the current namespace
(import std.hash hiding sha) ;; adds shatree to the current namespace

(export (args) body) ;; Creates one clvm program (as with toplevel mod)

(defun F (X) ...)
(defun G (X) ...)
(export F) ;; creates a program from F and writes it to disk
(export G) ;; also G simultaneously

;; Module style provides the hashes of exports to the program exporting them,
;; making it possible to build some coin structures entirely within a chialisp program.
;; The hash functions will be arranged to be as efficient as they can be (constant if
;; not recursively defined, otherwise with as much precalculation as possible).
(defun F (X) (G_hash)) ;; Construct the modhash of G if it's exported
(defun G (X) (F_hash)) ;; Construct the modhash of F if it's exported

example of what can be got up to:

(include *standard-cl-23*)
(import qualified programs.two-outputs as two.outputs)

;; When imported, F_hash and G_hash of foreign programs are constants.
(export (X Y) (list two.outputs.F_hash (a two.outputs.F (list X)) two.outputs.F two.outputs.G_hash (a two.outputs.G (list Y)) two.outputs.G))