neo-go/_pkg.dev/vm/stack
Roman Khimov ddd1d92ff1 pkg: hide it by moving to _pkg.dev
The idea here is to preserve the history of `dev` branch development and its
code when merging with the `master`. Later this code could be moved into the
masters code where appropriate.
2019-08-20 18:39:50 +03:00
..
array.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
array_test.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
boolean.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
builder.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
bytearray.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
context.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
instruction.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
Int.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
int_test.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
invocationstack.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
map.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
map_test.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
Readme.md pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
stack.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
stack_test.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
stackitem.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
stackitem_test.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00
test_helper.go pkg: hide it by moving to _pkg.dev 2019-08-20 18:39:50 +03:00

VM - Stack

  • How do i implement a new StackItem?

Answer: You add it's type to the Item interface, then you implement the default return method on the abstract stack item, this should be the behaviour of the stack item, if it is not the new type. Then you embed the abstract item in the new struct and override the method.

For example, If I wanted to add a new type called HashMap

type Item interface{ HashMap()(*HashMap, error) }

func (a *abstractItem) HashMap() (*HashMap, error) { return nil, errors.New(This stack item is not a hashmap) }

type HashMap struct { *abstractItem // Variables needed for hashmap }

func (h *HashMap) HashMap()(*HashMap, error) { // logic to override default behaviour }