- main calls playground
- playground doesn't take any input.
- playground returns Result. (pub enum Result)
- Result is a type that represents either success (Ok) or failure (Err).
- Inside playground (playground is for passing all the instructoins)
- we make a mutable stack of type Stack
- Stack is a struct a variable named values.
- values is a variable-sized Vec
- we return the "default value" for a type Stack. zero initialize the structure.
- Default value is []. i.e., empty
- Then we create a instructions vec![]
- The instructions are push 1 and 2, then add
- Instruction is an Enum
- The variants of the Enum are Add and Push1
- These variants are used so that we can choose their respective functionalities in the match {} for instructions
- Add doesn't have any value, Push1 variant needs a value
- for loop on instructions
- for each instruction in the instructions vec, we run execute funcion (execute is to execute the instructions)
- Here execute returns a Result type.
- insead of taking the return to any variable, you can use the ? to check if the return is a success or error.
- execute takes the stack and an instruction variant.
- use match to match each variant with its function
- for Push1, Push1 comes with a value. Use that value to push it into the vec. The value should be converted to Word type.
- instruction is immutable. So consider dereferencing the borrow as &.
- casting
&u8
asu32
is invalid, so dereference the expression: `*value. - create a VMError enum to pass the appropriate variants of errors
- for Add, take top two values of the stack, add them and push it back
- pop returns you an Option. if there is error in popping, then it is an underflow, so handle it.
- If there is error, error will be returned, or else the NULL tuple Ok(()) will be passed.
- If there is an error from execute, the program will return there itself and stop.
- else return Ok(())
- match the return values of playground with the specific functionalities.
nagendraputhane/rusty_ethereum
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published