[ [ "LineComment", "// A contract consists of a single object with sub-objects representing" ], [ "Whitespace", "\n" ], [ "LineComment", "// the code to be deployed or other contracts it can create." ], [ "Whitespace", "\n" ], [ "LineComment", "// The single \"code\" node is the executable code of the object." ], [ "Whitespace", "\n" ], [ "LineComment", "// Every (other) named object or data section is serialized and" ], [ "Whitespace", "\n" ], [ "LineComment", "// made accessible to the special built-in functions datacopy / dataoffset / datasize" ], [ "Whitespace", "\n" ], [ "LineComment", "// The current object, sub-objects and data items inside the current object" ], [ "Whitespace", "\n" ], [ "LineComment", "// are in scope." ], [ "Whitespace", "\n" ], [ "Object", "object" ], [ "Whitespace", " " ], [ "LiteralString", "\"Contract1\"" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "LineComment", "// This is the constructor code of the contract." ], [ "Whitespace", "\n " ], [ "Code", "code" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Function", "function" ], [ "Whitespace", " " ], [ "Identifier", "allocate" ], [ "ParenOpen", "(" ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", " " ], [ "Returns", "->" ], [ "Whitespace", " " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "mload" ], [ "ParenOpen", "(" ], [ "LiteralHex", "0x40" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "If", "if" ], [ "Whitespace", " " ], [ "Identifier", "iszero" ], [ "ParenOpen", "(" ], [ "Identifier", "ptr" ], [ "ParenClose", ")" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", " " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "LiteralHex", "0x60" ], [ "Whitespace", " " ], [ "BraceClose", "}" ], [ "Whitespace", "\n " ], [ "Identifier", "mstore" ], [ "ParenOpen", "(" ], [ "LiteralHex", "0x40" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "add" ], [ "ParenOpen", "(" ], [ "Identifier", "ptr" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "LineComment", "// first create \"Contract2\"" ], [ "Whitespace", "\n " ], [ "Let", "let" ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "datasize" ], [ "ParenOpen", "(" ], [ "LiteralString", "\"Contract2\"" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "Let", "let" ], [ "Whitespace", " " ], [ "Identifier", "offset" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "allocate" ], [ "ParenOpen", "(" ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "LineComment", "// This will turn into codecopy for EVM" ], [ "Whitespace", "\n " ], [ "Identifier", "datacopy" ], [ "ParenOpen", "(" ], [ "Identifier", "offset" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "dataoffset" ], [ "ParenOpen", "(" ], [ "LiteralString", "\"Contract2\"" ], [ "ParenClose", ")" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "LineComment", "// constructor parameter is a single number 0x1234" ], [ "Whitespace", "\n " ], [ "Identifier", "mstore" ], [ "ParenOpen", "(" ], [ "Identifier", "add" ], [ "ParenOpen", "(" ], [ "Identifier", "offset" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "LiteralHex", "0x1234" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "Identifier", "pop" ], [ "ParenOpen", "(" ], [ "Identifier", "create" ], [ "ParenOpen", "(" ], [ "Identifier", "offset" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "add" ], [ "ParenOpen", "(" ], [ "Identifier", "size" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "LiteralInt", "32" ], [ "ParenClose", ")" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "LiteralInt", "0" ], [ "ParenClose", ")" ], [ "ParenClose", ")" ], [ "Whitespace", "\n\n " ], [ "LineComment", "// now return the runtime object (the currently" ], [ "Whitespace", "\n " ], [ "LineComment", "// executing code is the constructor code)" ], [ "Whitespace", "\n " ], [ "Identifier", "size" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "datasize" ], [ "ParenOpen", "(" ], [ "LiteralString", "\"runtime\"" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "Identifier", "offset" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "allocate" ], [ "ParenOpen", "(" ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "LineComment", "// This will turn into a memory->memory copy for eWASM and" ], [ "Whitespace", "\n " ], [ "LineComment", "// a codecopy for EVM" ], [ "Whitespace", "\n " ], [ "Identifier", "datacopy" ], [ "ParenOpen", "(" ], [ "Identifier", "offset" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "dataoffset" ], [ "ParenOpen", "(" ], [ "LiteralString", "\"runtime\"" ], [ "ParenClose", ")" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "Identifier", "return" ], [ "ParenOpen", "(" ], [ "Identifier", "offset" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "Data", "data" ], [ "Whitespace", " " ], [ "LiteralString", "\"Table2\"" ], [ "Whitespace", " " ], [ "LiteralStringHex", "hex\"4123\"" ], [ "Whitespace", "\n\n " ], [ "Object", "object" ], [ "Whitespace", " " ], [ "LiteralString", "\"runtime\"" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Code", "code" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Function", "function" ], [ "Whitespace", " " ], [ "Identifier", "allocate" ], [ "ParenOpen", "(" ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "Whitespace", " " ], [ "Returns", "->" ], [ "Whitespace", " " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "Identifier", "mload" ], [ "ParenOpen", "(" ], [ "LiteralHex", "0x40" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "If", "if" ], [ "Whitespace", " " ], [ "Identifier", "iszero" ], [ "ParenOpen", "(" ], [ "Identifier", "ptr" ], [ "ParenClose", ")" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", " " ], [ "Identifier", "ptr" ], [ "Whitespace", " " ], [ "Assign", ":=" ], [ "Whitespace", " " ], [ "LiteralHex", "0x60" ], [ "Whitespace", " " ], [ "BraceClose", "}" ], [ "Whitespace", "\n " ], [ "Identifier", "mstore" ], [ "ParenOpen", "(" ], [ "LiteralHex", "0x40" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "add" ], [ "ParenOpen", "(" ], [ "Identifier", "ptr" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "Identifier", "size" ], [ "ParenClose", ")" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "LineComment", "// runtime code" ], [ "Whitespace", "\n\n " ], [ "Identifier", "mstore" ], [ "ParenOpen", "(" ], [ "LiteralInt", "0" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "LiteralString", "\"Hello, World!\"" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "Identifier", "return" ], [ "ParenOpen", "(" ], [ "LiteralInt", "0" ], [ "Comma", "," ], [ "Whitespace", " " ], [ "LiteralHex", "0x20" ], [ "ParenClose", ")" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "LineComment", "// Embedded object. Use case is that the outside is a factory contract," ], [ "Whitespace", "\n " ], [ "LineComment", "// and Contract2 is the code to be created by the factory" ], [ "Whitespace", "\n " ], [ "Object", "object" ], [ "Whitespace", " " ], [ "LiteralString", "\"Contract2\"" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Code", "code" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "LineComment", "// code here ..." ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "Object", "object" ], [ "Whitespace", " " ], [ "LiteralString", "\"runtime\"" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "Code", "code" ], [ "Whitespace", " " ], [ "BraceOpen", "{" ], [ "Whitespace", "\n " ], [ "LineComment", "// code here ..." ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n\n " ], [ "Data", "data" ], [ "Whitespace", " " ], [ "LiteralString", "\"Table1\"" ], [ "Whitespace", " " ], [ "LiteralStringHex", "hex\"4123\"" ], [ "Whitespace", "\n " ], [ "BraceClose", "}" ], [ "Whitespace", "\n" ], [ "BraceClose", "}" ], [ "Whitespace", "\n" ] ]