Skip to content

Commit

Permalink
Implement call
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Aug 15, 2024
1 parent 04eeb12 commit b93a81b
Show file tree
Hide file tree
Showing 3 changed files with 409 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/ksoroban/kdist/soroban-semantics/host/call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Call

```k
requires "../configuration.md"
requires "../switch.md"
requires "../soroban.md"
requires "integer.md"
module HOST-CALL
imports CONFIG-OPERATIONS
imports SOROBAN-SYNTAX
imports HOST-INTEGER
imports SWITCH-SYNTAX
```

## call

```k
// TODO Check reentry
rule [hostfun-require-auth]:
<instrs> hostCall ( "d" , "_" , [ i64 i64 i64 .ValTypes ] -> [ i64 .ValTypes ] )
=> loadObject(HostVal(ARGS))
~> loadObject(HostVal(FUNC))
~> loadObject(HostVal(ADDR))
~> call
...
</instrs>
<locals>
0 |-> < i64 > ADDR // Address
1 |-> < i64 > FUNC // Symbol
2 |-> < i64 > ARGS // Vec
</locals>
syntax InternalInstr ::= "call" [symbol(call)]
// ------------------------------------------
rule [call]:
<instrs> call
=> #waitCommands
~> returnCallResult
...
</instrs>
<hostStack> ScAddress(TO) : Symbol(FUNC) : ScVec(ARGS) : S => S </hostStack>
<callee> FROM </callee>
<k> (.K => callContract(FROM, TO, FUNC, ARGS)) ... </k>
syntax InternalInstr ::= "returnCallResult" [symbol(returnCallResult)]
// ------------------------------------------------------------------------
rule [returnCallResult-error]:
<instrs> returnCallResult => trap ... </instrs>
<hostStack> Error(_,_) : _ </hostStack>
rule [returnCallResult]:
<instrs> returnCallResult
=> allocObject(RES)
~> returnHostVal
...
</instrs>
<hostStack> RES:ScVal : S => S </hostStack>
[owise]
endmodule
```
2 changes: 2 additions & 0 deletions src/ksoroban/kdist/soroban-semantics/host/hostfuns.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
```k
requires "address.md"
requires "buffer.md"
requires "call.md"
requires "context.md"
requires "integer.md"
requires "ledger.md"
Expand All @@ -12,6 +13,7 @@ requires "vector.md"
module HOSTFUNS
imports HOST-ADDRESS
imports HOST-BUFFER
imports HOST-CALL
imports HOST-CONTEXT
imports HOST-INTEGER
imports HOST-LEDGER
Expand Down
Loading

0 comments on commit b93a81b

Please sign in to comment.