Merge pull request #8189 from ethereum/makeYulExampleCompilable

Make yul example compilable.
This commit is contained in:
chriseth 2020-01-27 09:30:36 +01:00 committed by GitHub
commit a651eb149b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -919,9 +919,8 @@ An example Yul Object is shown below:
// The single "code" node is the executable code of the object. // The single "code" node is the executable code of the object.
// Every (other) named object or data section is serialized and // Every (other) named object or data section is serialized and
// made accessible to the special built-in functions datacopy / dataoffset / datasize // made accessible to the special built-in functions datacopy / dataoffset / datasize
// Access to nested objects can be performed by joining the names using ``.``. // The current object, sub-objects and data items inside the current object
// The current object and sub-objects and data items inside the current object // are in scope.
// are in scope without nested access.
object "Contract1" { object "Contract1" {
// This is the constructor code of the contract. // This is the constructor code of the contract.
code { code {
@ -931,11 +930,11 @@ An example Yul Object is shown below:
mstore(0x40, add(ptr, size)) mstore(0x40, add(ptr, size))
} }
// first create "runtime.Contract2" // first create "Contract2"
let size := datasize("runtime.Contract2") let size := datasize("Contract2")
let offset := allocate(size) let offset := allocate(size)
// This will turn into codecopy for EVM // This will turn into codecopy for EVM
datacopy(offset, dataoffset("runtime.Contract2"), size) datacopy(offset, dataoffset("Contract2"), size)
// constructor parameter is a single number 0x1234 // constructor parameter is a single number 0x1234
mstore(add(offset, size), 0x1234) mstore(add(offset, size), 0x1234)
pop(create(offset, add(size, 32), 0)) pop(create(offset, add(size, 32), 0))
@ -962,13 +961,9 @@ An example Yul Object is shown below:
// runtime code // runtime code
let size := datasize("Contract2") mstore(0, "Hello, World!")
let offset := allocate(size) return(0, 0x20)
// This will turn into codecopy for EVM }
datacopy(offset, dataoffset("Contract2"), size)
// constructor parameter is a single number 0x1234
mstore(add(offset, size), 0x1234)
pop(create(offset, add(size, 32), 0))
} }
// Embedded object. Use case is that the outside is a factory contract, // Embedded object. Use case is that the outside is a factory contract,
@ -987,7 +982,6 @@ An example Yul Object is shown below:
data "Table1" hex"4123" data "Table1" hex"4123"
} }
} }
}
Yul Optimizer Yul Optimizer
============= =============