neoneo-go/pkg/vm/stack
BlockChainDev 9eb11d2822 Make Next() method on Context failable
refactor peekContext and Peek
2019-03-16 21:45:48 +00:00
..
array.go VM: Add stackItems; Array, Boolean, Int and ByteArray 2019-02-27 20:55:48 +00:00
boolean.go remove error on NewBoolean 2019-03-16 21:44:03 +00:00
builder.go Add Builder 2019-03-15 22:27:34 +00:00
bytearray.go remove error on NewBoolean 2019-03-16 21:44:03 +00:00
context.go Make Next() method on Context failable 2019-03-16 21:45:48 +00:00
context_test.go Add Context stack Item 2019-03-15 22:32:08 +00:00
instruction.go Move opcode file 2019-03-15 22:35:12 +00:00
Int.go remove error on NewBoolean 2019-03-16 21:44:03 +00:00
int_test.go Refactor Int, Boolean, ByteArray conversion 2019-03-15 22:30:25 +00:00
invocation.go Make Next() method on Context failable 2019-03-16 21:45:48 +00:00
Readme.md - Add guide to stack readme 2019-02-28 13:51:02 +00:00
stack.go Make Next() method on Context failable 2019-03-16 21:45:48 +00:00
stack_test.go VM: removed helper functions from stack_test.go 2019-02-27 21:40:31 +00:00
stackitem.go Add Context stack Item 2019-03-15 22:32:08 +00:00
stackitem_test.go VM: Add tests for stack item 2019-02-27 20:56:19 +00:00
test_helper.go rename testhelper to test_helper 2019-03-15 22:34:04 +00: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 }