exp7l / dasy

a lisp built on top of vyper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dasy

The Dasypeltis, gansi, is considered an egg-eating snake. Their diet consists of all forms of eggs considering they have no teeth in which to eat living prey with.

Dasy is a lisp built on top of vyper

it is parsed into a vyper AST to leverage all the optimizations of the vyper compiler

Installation

For use as a library

pip install dasy

For use as an executable

pipx install dasy

Example

In hello_world.dasy

(defcontract hello_world
  [base [:uint256 :public]]
  (defn addUints [:uint256 x y] :uint256 :external
    (+ x y))
  (defn multipleRets [:uint256 x y] '(:uint256 :uint256 :uint256) :external
    '((+ x 1) (+ y 1) 3))
  (defn setBase [:uint256 x] :uint256 :external
    (setv (. self base) x)
    x)
  (defn addToBase [:uint256 x] :uint256 :external
    (+ (. self base) x))
  )

via this fork of titanoboa

import boa

c = boa.load("hello_world.dasy")
print(c.addUints(10, 20)) # outputs 30
print(c.subUints(100, 20)) # outputs 80
c.setBase(10)
print(c.addToBase(10)) # outputs 20

via hy (lisp based on python)

(import rich [print]
        boa.contract [VyperContract]
        dasy)

(let [src (with [f (open "hello_world.dasy" "r")]
            (.read f))
      compilation_data (.compile dasy src)
      contract (VyperContract compilation_data)]
  (print f"calling (.addUints contract 10 20): {(.addUints contract 10 20)}")
  (print f"calling (.subUints contract 10 20): {(.subUints contract 100 20)}"))

Command line compilation

> dasy hello_world.dasy
0x61004f61000f60003961004f6000f36003361161000c57610037565b60003560e01c3461003d5763c29855788118610035576004361861003d57600860405260206040f35b505b60006000fd5b600080fda165767970657283000306000b

Motivation

Macros

There’s a lot of opportunities for macros in smart contracts. They could also be used as a proof of concept for features before implementing them at a lower level in the compiler.

While macros are not implemented yet, the goal is to be able to implement constructs like “while” using macros similarly to the following example from Common Lisp.

(defmacro while (condition &body body)
  `(loop while ,condition do (progn ,@body)))

The macro’s inner body would be made up of a pre-initialized for-loop.

For fun

About

a lisp built on top of vyper


Languages

Language:Python 89.9%Language:Hy 7.9%Language:Vyper 2.2%