Skip to content

Commit

Permalink
implement map_del
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Nov 12, 2024
1 parent d11a46f commit 6dd693c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/komet/kdist/soroban-semantics/host/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ module HOST-MAP
```

## map_del

```k
rule [hostfun-map-del]:
<instrs> hostCall ( "m" , "2" , [ i64 i64 .ValTypes ] -> [ i64 .ValTypes ] )
=> loadObjectFull(HostVal(KEY))
~> loadObject(HostVal(M))
~> hostCallAux("m", "2")
...
</instrs>
<locals>
0 |-> < i64 > M
1 |-> < i64 > KEY
</locals>
rule [hostCallAux-map-del]:
<instrs> hostCallAux("m", "2")
=> allocObject(ScMap( M [ KEY <- undef ] ))
~> returnHostVal
...
</instrs>
<hostStack> ScMap(M) : KEY:ScVal : S => S </hostStack>
requires KEY in_keys(M)
rule [hostCallAux-map-del-not-found]:
<instrs> hostCallAux("m", "2") => trap ... </instrs>
<hostStack> ScMap(M) : KEY:ScVal : S => S </hostStack>
requires notBool( KEY in_keys(M) )
```

## map_len

```k
Expand Down
20 changes: 20 additions & 0 deletions src/tests/integration/data/map.wast
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,24 @@ callTx(
U32(123)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; map_del
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

callTx(
Account(b"test-caller"),
Contract(b"test-sc"),
"del",
ListItem(ScMap(
Symbol(str("foo")) |-> U32(123)
Symbol(str("bar")) |-> Symbol(str("456"))
Symbol(str("baz")) |-> U128(789)
))
ListItem(Symbol(str("foo"))),
ScMap(
Symbol(str("bar")) |-> Symbol(str("456"))
Symbol(str("baz")) |-> U128(789)
)
)

setExitCode(0)

0 comments on commit 6dd693c

Please sign in to comment.