Struct sway_core::asm_generation::evm::EvmAsmBuilder
source · pub struct EvmAsmBuilder<'ir> { /* private fields */ }
Expand description
A smart contract is created by sending a transaction with an empty “to” field. When this is done, the Ethereum virtual machine (EVM) runs the bytecode which is set in the init byte array which is a field that can contain EVM bytecode
The EVM bytecode that is then stored on the blockchain is the value that is returned by running the content of init on the EVM.
The bytecode can refer to itself through the opcode CODECOPY opcode, which reads three values on the stack where two of those values are pointers to the bytecode, one marking the beginning and one marking the end of what should be copied to memory.
The RETURN opcode is then used, along with the correct values placed on the stack, to return bytecode from the initial run of the EVM code. RETURN reads and removes two pointers from the stack. These pointers define the part of the memory that is a return value. The return value of the initial contract creating run of the bytecode defines the bytecode that is stored on the blockchain and associated with the address on which you have created the smart contract.
The code that is compiled but not stored on the blockchain is thus the code needed to store the correct code on the blockchain but also any logic that is contained in a (potential) constructor of the contract.
Implementations§
source§impl<'ir> EvmAsmBuilder<'ir>
impl<'ir> EvmAsmBuilder<'ir>
pub fn new(program_kind: ProgramKind, context: &'ir Context) -> Self
pub fn finalize(&self) -> AsmBuilderResult
pub fn compile_function(&mut self, function: Function) -> CompileResult<()>
Trait Implementations§
source§impl<'ir> AsmBuilder for EvmAsmBuilder<'ir>
impl<'ir> AsmBuilder for EvmAsmBuilder<'ir>
fn func_to_labels(&mut self, func: &Function) -> (Label, Label)
fn compile_function(&mut self, function: Function) -> CompileResult<()>
fn finalize(&self) -> AsmBuilderResult
Auto Trait Implementations§
impl<'ir> RefUnwindSafe for EvmAsmBuilder<'ir>
impl<'ir> !Send for EvmAsmBuilder<'ir>
impl<'ir> !Sync for EvmAsmBuilder<'ir>
impl<'ir> Unpin for EvmAsmBuilder<'ir>
impl<'ir> UnwindSafe for EvmAsmBuilder<'ir>
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.