Skip to content

Commit

Permalink
function calls (#321)
Browse files Browse the repository at this point in the history
* updating the test for #305

* adding cases for an exhaustive switch

* adding cases for an exhaustive switch

* end of day scraps, working on #305

* actual implementation of the hash for function names

* code style tweaks

* rename

* less hardecoded mapping from Obsidian to Yul types but it still needs work

* comment about outputting type annotations

* end of day scraps

* removing two big blocks of redundant code, neither of which was getting run

* removing possibly silly assertion

* pulling funcscope into its own file

* fixing selector case syntax

* removing an assertion about what functions can be called on that i think does not make sense

* comments and imports clean up

* adding some hard coded library functions to the mustache file, code to dispatch table

* adding json file so that travis will also run simple call as a test

* comment about boilerplate origin

* tightening up funcscope implementation

* callvalue check to util

* end of day scraps

* whitespace
  • Loading branch information
ivoysey committed Apr 15, 2021
1 parent 3fed30c commit f98f401
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 194 deletions.
45 changes: 39 additions & 6 deletions Obsidian_Runtime/src/main/yul_templates/object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,46 @@ object "{{creationObject}}" {
{{#dispatch}}
{{! TODO 224 is a magic number offset to shift to follow the spec above; check that it's right }}
let selector := shr(224, calldataload(0))
switch selector
{{#dispatchCase}}
case {{hash}} {
{{dispatchCall}}
}
{{/dispatchCase}}
{{dispatchCase}}
{{/dispatch}}
{{! todo: this is deadcode for at least the empty contract but gets emitted anyway; trim it down somehow? }}
{{! these functions for memory management are produced by the solc IR backend for
Solidity programs analagous to our test Obsidian programs.
}}
function abi_decode_tuple(headStart, dataEnd) {
if slt(sub(dataEnd, headStart), 0) { revert(0, 0) }
}
function abi_encode_tuple_to_fromStack(headStart ) -> tail {
tail := add(headStart, 0)
}
function allocate_memory(size) -> memPtr {
memPtr := allocate_unbounded()
finalize_allocation(memPtr, size)
}
function allocate_unbounded() -> memPtr {
memPtr := mload(64)
}
function finalize_allocation(memPtr, size) {
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
// protect against overflow
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
}
function panic_error_0x41() {
mstore(0, 35408467139433450592217433187231851964531694900788300625387963629091585785856)
mstore(4, 0x41)
revert(0, 0x24)
}
function round_up_to_mul_of_32(value) -> result {
result := and(add(value, 31), not(31))
}
{{#runtimeFunctions}}
{{code}}
{{/runtimeFunctions}}
Expand Down
6 changes: 6 additions & 0 deletions resources/tests/GanacheTests/SimpleCall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"gas" : 30000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 5000000,
"numaccts" : 1
}
16 changes: 9 additions & 7 deletions resources/tests/GanacheTests/SimpleCall.obs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
main contract SimpleCall{
transaction incr(int x) returns int {
return 4;
int x;
transaction updatex() {
x = 4;
return;
}

transaction main(int x) returns int {
int y = incr (x);
return y;
transaction main(){
x = 9;
updatex();
return;
}
}
}

0 comments on commit f98f401

Please sign in to comment.