Skip to content

Commit

Permalink
fix: add Dict literals for struct literals
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Feb 9, 2024
1 parent 4ca57d8 commit 2e8a549
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dasy/parser/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def parse_node(
)
case models.Float(node):
raise NotImplementedError("Floating point not supported (yet)")
case models.Dict(node):
keys = [parse_node(k) for k in node.keys()]
values = [parse_node(v) for v in node.values()]
ast_node = build_node(vy_nodes.Dict, keys=keys, values=values)
case _:
raise ValueError(f"No match for node {node}. Unsupported node type.")
return add_src_map(SRC, node, ast_node)
Expand Down
6 changes: 6 additions & 0 deletions examples/nonreentrantenforcer.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma evm-version cancun

@nonreentrant("lock")
@external
def func0():
raw_call(msg.sender, b"", value=0)
4 changes: 4 additions & 0 deletions examples/reference_types.dasy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(pragma :evm-version "cancun")
(defstruct Person
name (string 100)
age :uint256)
Expand Down Expand Up @@ -33,3 +34,6 @@
;; Person struct is copied into memory
(defvar p Person self/person)
(set-in p name "Solidity"))

(defn literalPerson [] Person :external
(Person {:name "Foo" :age 100}))
4 changes: 4 additions & 0 deletions examples/transient_nonreentrant.dasy
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

;; use `pragma` to specify the EVM version
(pragma :evm-version "cancun")

;; this reentrancy lock will use tstore/tload
(defn func0 [] [:external (nonreentrant "lock")]
(raw_call msg/sender b"" :value 0))

4 changes: 4 additions & 0 deletions tests/test_dasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_if_expr():
def test_struct():
c = compile_src(
"""
(pragma :evm-version "cancun")
(defstruct Person
age :uint256)
(defvars person (public Person))
Expand All @@ -149,10 +150,13 @@ def test_struct():
(def mPers Person self/person)
(set-in mPers age 10)
mPers)
(defn literalPerson [] Person :external
(Person {:age 100 :name "Foo"}))
"""
)
assert c.person()[0] == 12
assert c.memoryPerson() == (10,)
# assert c.literalPerson() == (100,"Foo")


def test_arrays():
Expand Down

0 comments on commit 2e8a549

Please # to comment.