Skip to content

Commit

Permalink
functions with arguments, pointer fields (#395)
Browse files Browse the repository at this point in the history
* disabling the pager in my pretty printing run script

* change the elaboration of `new` and non-local Invocations to match the flat yul object style (#367)

* making a change to double check work flow

* adding a stub for computing the size of a contract; that'll be its own PR entirely one day fairly soon, but for now, we assume that we just need 32 bytes

* using hex values for some boilerplate so that it matches the docs

* reworking constructors to just allocate memory

* adding some helper functions in util. one is a renaming for transactions from child contracts; the other is basically a type-checked comment pointing out uses of some pretty substantian technical debt

* temporarily removing the code to translate child contracts. rewriting the translation of Invocations to remap everything to local invocations instead, into the names that will be created in the flat yul object

* removing an assertion and adding translation of string literals

* whitespace, scala style

* utility function for undoing the transaction renaming

* generate flat yul object from child contracts (#369)

* rename, add boolean for main-ness in translate decl

* changing signature of translateDeclaration to remove a return that doesn't do anything

* whitespace, scala style

* comments

* scraps; adding an assert

* changing how child contracts are processed

* rewrite of translateTransaction

* chainging signature of translateStatement

* more threading through inMain

* whitespace, scala style

* adding some docs

* removing the nicer output for typed names in favor of a bland one, per solc's current limitations. adding a comment about why.

* adding a temporary fix to the top of the dispatch table pending talking with MC"

* removing a stale comment

* comments

* adding missing declarations to invocations

* cleaning up comments and some messy logic around temporary variables

* removing comment

* more hacks for specific tests in advance of type info

* changing hardcoded value in the mustache file for this to be the current contract address

* adding a couple of args to get this to typecheck

* use type annotations in Yul codegen (#377)

* removing a util function to rename functions in the dispatch table; that no longer makes sense with the solution for flattening that we've settled on for now

* adding comments; expanding getcontractname

* ripping out some code, adding comments

* adding a comment that may help to locate a bug later

* moving comment closer to the source and updating it

* comments

* scraps; this change seemed likely but breaks a bunch of tests

* quick function to traverse over an expression and check a given predicate on all the annotations

* fixing some import dependencies

* traversal of a program rather than just an expression; i sure hope i don't have to come back and make this the fully polymorphic map reduce but i bet i will

* adding updates to the expression returned in the checker from just the ReferenceIdentifier cases, after some debugging with @mcoblenz

* adding additional ParserUtil.updateExprType uses as seems right. bunch of tests fail, some of which i expected some i didn't, and i don't know how to fix a lot of them

* updating width calculation to actually inspect the type, now that we know it

* removing an assert that caused a bunch of false negatives.

* small changes per PR comments

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* compute the sizes of contracts for allocation (#378)

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* computing sizes of types recursively

* adding some simple hard coded unit tests

* copying over a helper from type checker tests to test on actual contracts in files

* adding more general tests; it doesn't work but i think i know why

* scraps and printlines from trying to debug sizes

* changing the type of the size computation function so it has enough information, per MC. reworking tests

* renaming size function; fixing the main test

* adding some comments and a variable for pointer sizes

* formatting, reworking base test

* removing the two simpler unit tests. it is hard and somewhat pointless to be the parser and create a contract table by hand, the existing test is informative enough

* fixing type checker errors (#380)

* debugging scraps

* copying a slightly cut down version of linked lists, but this needs to be edited down even more to be the right goal for a demo.

* commenting out spammy prints

* patch from MC

* updating override syntax to not introduce a new field

* updating expr type update to set the location and use the one field rather than build new ones

* removing printlines

* updating logged errors in a few places; this fixes some but not all of #379

* error in resourcesTest was in the test itself; it was incorrectly looking for m to be at int

* formatting, whitespace

* fixed permission passing test; also errors in the definition of the test, not the checker

* fixing all permowned error

* scala style, whitespace

* scraps

* adding a comment, removing a comment, removing an assert

* compute offsets, store fields in memory (#384)

* fixing a bug in computing sizes by translating from set to list; adding an assert; whitespace and style

* adding helper to compute offsets

* typoe and adding a test to demonstrate that the bug computing sizes is gone

* adding a sandbox test case file

* adding a traversal of the declarations sequence in the contract rather than relying on the toList of an unordered collection; using that helper function both in computing sizes and offsets

* refactoring tests for util functions to reuse the code to produce a symbol table; adding tests for computing offests

* style, whitespace

* a couple more tests for offsets

* a couple more tests for offsets

* updating tests, adding comments for myself

* helper to wrap call to field offsets, changing sload and sstore to m*

* updating test to show that fields get overwritten; adding json so it gets run because it passes

* messing with test files

* changing the ganache test script to use the test skipping checking script that i think works across platforms, per #361

* adding sort, per #631

* scala style, fussy fixes to doc strings etc

* scala style, fussy fixes to doc strings etc

* scala style, fussy fixes to doc strings etc

* scala style, fussy fixes to doc strings etc

* some house keeping to clean up a util function, removing a source of bugs related to computing sizes

* refactoring to change the definition of typed name to have an actual type in it, not just its string representation

* adding clause to type name helper for contracts

* whitespace in obsidian files

* housekeeping, adding docs and removing stale todos

* Adding another passing test

* updating travis test script to work with solc 0.8.10

* iterating on travis script

* allocate fields with pointers, rewrite yulobject and mustache interaction to reflect current object layout (#388)

* adding test case for nonprimitive fields in the main contract

* adding an ownership to the test field to make it valid obsidian

* removing some dead code

* removing unused childContracts argument from YulObject

* scraps

* new test

* fixing local util script for new version of solc, adding a little code for #389 but not a complete idea yet

* scraps

* rewriting yulobject to take an optional int to indicate the size of the main contract and if the contract being elaborated is the main one (if it has as size). this is temporary and not going to last

* removing what i am nearly positive is dead code

* first half of a big rewrite of the YulObject class

* back half of the refactor to update code generation

* adding some todos and notes

* scraps, scala style and whitespace

* scraps

* updating the implementation of switch toString to not print out invalid switches with no branches. this fixes the emptycontract dispatch table.

* scraps

* add the this argument uniformly in codegen not printing, and only remove it for the hashed dispatch table entries

* pulling the body of local invocation out into a helper so that it can get called in both places with different  arguments

* documentation, cleaning up todos

* scraps

* adding a little more documentation

* functions with arguments (#394)

* adding test case for nonprimitive fields in the main contract

* adding an ownership to the test field to make it valid obsidian

* removing some dead code

* removing unused childContracts argument from YulObject

* scraps

* new test

* fixing local util script for new version of solc, adding a little code for #389 but not a complete idea yet

* scraps

* rewriting yulobject to take an optional int to indicate the size of the main contract and if the contract being elaborated is the main one (if it has as size). this is temporary and not going to last

* removing what i am nearly positive is dead code

* first half of a big rewrite of the YulObject class

* back half of the refactor to update code generation

* adding some todos and notes

* scraps, scala style and whitespace

* scraps

* updating the implementation of switch toString to not print out invalid switches with no branches. this fixes the emptycontract dispatch table.

* scraps

* add the this argument uniformly in codegen not printing, and only remove it for the hashed dispatch table entries

* pulling the body of local invocation out into a helper so that it can get called in both places with different  arguments

* documentation, cleaning up todos

* scraps

* renaming some files

* removing half baked linked list test

* typo

* adding json so this test gets run in Travis
  • Loading branch information
ivoysey committed Nov 16, 2021
1 parent abe8b8a commit 440bdd6
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 501 deletions.
36 changes: 9 additions & 27 deletions Obsidian_Runtime/src/main/yul_templates/object.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,28 @@ ethereum/solidity/libsolidity/codegen/ir/IRGenerator.cpp
Consulting example yul code is also helpful in understanding the template.
https://solidity.readthedocs.io/en/latest/yul.html#specification-of-yul-object
}}
object "{{creationObject}}" {
object "{{contractName}}" {
code {
{{! init free memory pointer, see chatper "Layout in Memory" of the Solidity doc}}
{{memoryInit}}
{{! protection against sending Ether }}
{{callValueCheck}}
{{! not impletmented by the current stage, cited from IRGenerator.cpp (link in file comment above) }}
{{#notLibrary}}
{{#constructorHasParams}} let {{constructorParams}} := {{copyConstructorArguments}}() {{/constructorHasParams}}
{{implicitConstructor}}({{constructorParams}})
{{/notLibrary}}
{{! todo: write and call constructor }}
{{#deploy}}
{{call}}
{{/deploy}}
{{! functions related to constructor }}
{{#deployFunctions}}
{{code}}
{{/deployFunctions}}
{{codeCopy}}
{{defaultReturn}}
}
object "{{runtimeObjectName}}" {
object "{{deployedName}}" {
code {
{{! init free memory pointer, see chatper "Layout in Memory" of the Solidity doc}}
{{memoryInitRuntime}}
{{memoryInit}}

{{! obtain which runtime function is called, https://solidity.readthedocs.io/en/latest/abi-spec.html#function-selector}}

{{! todo: is 4 a magic number or should it be generated based on the object in question? check the ABI }}
if iszero(lt(calldatasize(), 4)) {
{{#dispatch}}
{{! TODO 224 is a magic number offset to shift to follow the spec above; check that it's right }}
let this := address()
let selector := shr(224, calldataload(0))
{{dispatchCase}}
{{/dispatch}}
{{! TODO 224 is a magic number offset to shift to follow the spec above; check that it's right }}
let this := allocate_memory({{mainSize}})
let selector := shr(224, calldataload(0))
{{dispatchTable}}
}
if iszero(calldatasize()) { }
revert(0, 0)
Expand Down Expand Up @@ -101,11 +87,7 @@ object "{{creationObject}}" {
cleaned := value
}

{{#runtimeFunctions}}
{{code}}
{{/runtimeFunctions}}
{{transactions}}
}

{{childContracts}}
}
}
9 changes: 1 addition & 8 deletions bin/run_any_yul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ then
exit 1
fi

echo "Yul that produced the binary:"
TOP=$(echo "$output" | grep -n "Pretty printed source:" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Binary representation:" | cut -f1 -d:)
TOP=$((TOP+1)) # drop the line with the name
BOT=$((BOT-2)) # drop the empty line after the binary
echo -ne "$output" | sed -n $TOP','$BOT'p' | bat -l javascript --style=plain -P

TOP=$(echo "$output" | grep -n "Binary representation" | cut -f1 -d:)
BOT=$(echo "$output" | grep -n "Text representation" | cut -f1 -d:)
BOT=$(echo "$output" | wc -l | awk '{print $1}' )
TOP=$((TOP+1)) # drop the line with the name
BOT=$((BOT-1)) # drop the empty line after the binary
EVM_BIN=$(echo "$output" | sed -n $TOP','$BOT'p' )
Expand Down
110 changes: 0 additions & 110 deletions resources/tests/GanacheTests/LinkedList.obs

This file was deleted.

8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/SetGetPointer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 5000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "1800"
}
34 changes: 34 additions & 0 deletions resources/tests/GanacheTests/SetGetPointer.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
contract IntContainer{
int x;
int y;
int z;
int f;

transaction set() {
x = -1;
f = -1;
z = -1;
y = -1;
x = 5;
y = 10;
z = 4;
f = 9;
}

transaction get() returns int{
return x*y*z*f; // 1800
}
}


// this differs from the test in SG.obs in that the main contract
// not only has a field but that field is at a non-primitive type
main contract SetGetPointer {
IntContainer@Owned ic;

transaction main() returns int{
ic = new IntContainer();
ic.set();
return ic.get();
}
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/SetGetWithArgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 5000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract IntContainer{
}
}

main contract SetGet{
main contract SetGetWithArgs{
transaction main() returns int{
IntContainer ic = new IntContainer();
ic.set(5);
Expand Down

0 comments on commit 440bdd6

Please sign in to comment.