From dd53694d034f8bfa69ca66623dda21fb1dc21655 Mon Sep 17 00:00:00 2001 From: Burak Bilge Yalcinkaya Date: Tue, 12 Nov 2024 16:26:08 +0300 Subject: [PATCH] implement `map_put` --- src/komet/kdist/soroban-semantics/host/map.md | 27 +++++++++++ src/tests/integration/data/map.wast | 48 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/komet/kdist/soroban-semantics/host/map.md b/src/komet/kdist/soroban-semantics/host/map.md index 2a6da9a..0f738fe 100644 --- a/src/komet/kdist/soroban-semantics/host/map.md +++ b/src/komet/kdist/soroban-semantics/host/map.md @@ -29,6 +29,33 @@ module HOST-MAP .Map ``` +## map_put + +```k + rule [hostfun-map-put]: + hostCall ( "m" , "0" , [ i64 i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) + => pushStack(HostVal(VAL)) + ~> loadObjectFull(HostVal(KEY)) + ~> loadObject(HostVal(M)) + ~> hostCallAux("m", "0") + ... + + + 0 |-> < i64 > M + 1 |-> < i64 > KEY + 2 |-> < i64 > VAL + + + rule [hostCallAux-map-put]: + hostCallAux("m", "0") + => allocObject(ScMap( M [ KEY <- VAL ] )) + ~> returnHostVal + ... + + ScMap(M) : KEY:ScVal : VAL:HostVal : S => S + +``` + ## map_get ```k diff --git a/src/tests/integration/data/map.wast b/src/tests/integration/data/map.wast index bcc9996..29d3842 100644 --- a/src/tests/integration/data/map.wast +++ b/src/tests/integration/data/map.wast @@ -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) \ No newline at end of file