Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 22 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
35de5d4
adding test case for nonprimitive fields in the main contract
ivoysey Nov 10, 2021
8017e1e
adding an ownership to the test field to make it valid obsidian
ivoysey Nov 10, 2021
d42050a
removing some dead code
ivoysey Nov 10, 2021
505ce51
removing unused childContracts argument from YulObject
ivoysey Nov 11, 2021
5f18b0e
scraps
ivoysey Nov 11, 2021
18afba7
new test
ivoysey Nov 11, 2021
443b8a4
fixing local util script for new version of solc, adding a little cod…
ivoysey Nov 11, 2021
6d118e8
scraps
ivoysey Nov 12, 2021
486f344
rewriting yulobject to take an optional int to indicate the size of t…
ivoysey Nov 12, 2021
51ca00b
removing what i am nearly positive is dead code
ivoysey Nov 12, 2021
6d59889
first half of a big rewrite of the YulObject class
ivoysey Nov 12, 2021
7b7b7a5
back half of the refactor to update code generation
ivoysey Nov 12, 2021
422d3dd
adding some todos and notes
ivoysey Nov 13, 2021
f6238c1
scraps, scala style and whitespace
ivoysey Nov 13, 2021
9f98d3c
scraps
ivoysey Nov 13, 2021
521e6e2
updating the implementation of switch toString to not print out inval…
ivoysey Nov 13, 2021
58fddf1
scraps
ivoysey Nov 15, 2021
9a33746
add the this argument uniformly in codegen not printing, and only rem…
ivoysey Nov 15, 2021
65736cd
pulling the body of local invocation out into a helper so that it can…
ivoysey Nov 15, 2021
37549be
documentation, cleaning up todos
ivoysey Nov 15, 2021
a92ccec
scraps
ivoysey Nov 15, 2021
e223ace
adding a little more documentation
ivoysey Nov 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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();
}
}
Loading