Skip to content

Commit

Permalink
add more inline IR examples
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Nov 25, 2023
1 parent 2a0d84f commit 269f17f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
18 changes: 16 additions & 2 deletions examples/venom.dasy
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
(defn absoluteValue [] :external
(venom "(seq (mstore (add 32 31) 5945936342127) (mstore 0 20) (return 0 0))"))
(defn storeInMem [] :external
(venom "(seq (mstore (add 32 31) 5945936342127)
(mstore 0 20)
(return 0 0))"))

(defn retOne [] :uint256 :external
(defvar x :uint256 0)
(venom "(mstore 64 1)")
x)


;; 41 gas
(defn addTwoNums [:uint256 x y] :uint256 :external
(defvar z :uint256 0) ;; first variable is at offset 64
(venom "(mstore 64 (add (calldataload 4) (calldataload 36)))")
z)
11 changes: 11 additions & 0 deletions examples/venom_comp.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@external
def retOne() -> uint256:
x: uint256 = 0
x = 1
return x


# 71 gas
@external
def addTwoNums(a: uint256, b: uint256) -> uint256:
return a + b
9 changes: 8 additions & 1 deletion tests/test_dasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

def test_venom():
c = compile("examples/venom.dasy")
c.absoluteValue()
assert c.retOne() == 1

def test_compare_venom_vyper():
c = compile("examples/venom.dasy")
v = boa.load("examples/venom_comp.vy")

for contract in [c, v]:
assert contract.retOne() == 1
assert contract.addTwoNums(1, 2) == 3

def compile_src(src: str, *args) -> VyperContract:
ast = dasy.compile(src, include_abi=True)
Expand Down

0 comments on commit 269f17f

Please sign in to comment.