Skip to content

Commit

Permalink
Convert rel handles to abs when creating maps and vecs
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Sep 12, 2024
1 parent ed78e76 commit 1d91bcd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/komet/kdist/soroban-semantics/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ If `SCV` is a small value, `allocObject(SCV)` returns a small `HostVal` directly
rule [loadObject-rel]:
<instrs> loadObject(VAL)
=> loadObject(RELS {{ getIndex(VAL) }} orDefault HostVal(0))
=> loadObject(rel2abs(RELS, VAL))
...
</instrs>
<relativeObjects> RELS </relativeObjects>
Expand Down Expand Up @@ -371,6 +371,24 @@ If `SCV` is a small value, `allocObject(SCV)` returns a small `HostVal` directly
```

- rel2abs, rel2absMany: Convert relative handles to absolute handles

```k
syntax HostVal ::= rel2abs(List, HostVal) [function, total, symbol(rel2abs)]
// ------------------------------------------------------------------------
rule rel2abs(RELS, HV) => RELS {{ getIndex(HV) }} orDefault HV
requires isObject(HV) andBool isRelativeObjectHandle(HV)
rule rel2abs(_, HV) => HV
[owise]
syntax List ::= rel2absMany(List, List) [function, total, symbol(rel2absMany)]
// --------------------------------------------------------------------------------
rule rel2absMany(RELS, ListItem(HV) L) => ListItem(rel2abs(RELS, HV)) rel2absMany(RELS, L)
rule rel2absMany(_, L) => L
[owise]
```

### Auxiliary functions

```k
Expand Down
3 changes: 2 additions & 1 deletion src/komet/kdist/soroban-semantics/host/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ The function returns a `HostVal` pointing to the new map object.
ScMap(
mapFromLists(
KEYS,
Bytes2Vals(VALS_BS)
rel2absMany(RELS, Bytes2Vals(VALS_BS))
)
)
)
~> returnHostVal
...
</instrs>
<hostStack> KEYS : VALS_BS : S => S </hostStack>
<relativeObjects> RELS </relativeObjects>
requires size(KEYS) ==Int lengthBytes(VALS_BS) /Int 8
```
Expand Down
9 changes: 8 additions & 1 deletion src/komet/kdist/soroban-semantics/host/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ module HOST-VECTOR
<hostStack> U32(VALS_POS) : U32(LEN) : S => S </hostStack>
rule [vecNewFromLinearMemoryAux]:
<instrs> vecNewFromLinearMemoryAux => allocObject(ScVec(Bytes2Vals(BS))) ... </instrs>
<instrs> vecNewFromLinearMemoryAux
=> allocObject(
ScVec(
rel2absMany(RELS, Bytes2Vals(BS))
)
) ...
</instrs>
<hostStack> BS : S => S </hostStack>
<relativeObjects> RELS </relativeObjects>
syntax Bytes ::= Vals2Bytes(List) [function, total]
Expand Down

0 comments on commit 1d91bcd

Please sign in to comment.