Skip to content

Commit

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

## map_put

```k
rule [hostfun-map-put]:
<instrs> hostCall ( "m" , "0" , [ i64 i64 i64 .ValTypes ] -> [ i64 .ValTypes ] )
=> pushStack(HostVal(VAL))
~> loadObjectFull(HostVal(KEY))
~> loadObject(HostVal(M))
~> hostCallAux("m", "0")
...
</instrs>
<locals>
0 |-> < i64 > M
1 |-> < i64 > KEY
2 |-> < i64 > VAL
</locals>
rule [hostCallAux-map-put]:
<instrs> hostCallAux("m", "0")
=> allocObject(ScMap( M [ KEY <- VAL ] ))
~> returnHostVal
...
</instrs>
<hostStack> ScMap(M) : KEY:ScVal : VAL:HostVal : S => S </hostStack>
```

## map_get

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; map_put
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

callTx(
Account(b"test-caller"),
Contract(b"test-sc"),
"put",
ListItem(ScMap(.Map)) ListItem(Symbol(str("foo"))) ListItem(U32(123456)),
ScMap(Symbol(str("foo")) |-> U32(123456))
)

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

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

setExitCode(0)

0 comments on commit dd53694

Please sign in to comment.