neo-go/pkg/vm/stack
Roman Khimov 1fb66d6b73 pkg/vm/stack: improve Array testing code slightly
GolangCI complained:
  testArray is unused (from deadcode)

But this function was actually wrong being a copy-paste of testMakeStackMap(),
it also didn't conform to testMake... naming scheme, so this fixes it. To make
thing more uniform NewArray() was also changed to return error, map_test.go
code adjusted to this changes and finally array_test.go was added as a stub
for future Array testing.
2019-08-12 17:12:05 +03:00
..
array.go pkg/vm/stack: improve Array testing code slightly 2019-08-12 17:12:05 +03:00
array_test.go pkg/vm/stack: improve Array testing code slightly 2019-08-12 17:12:05 +03:00
boolean.go Implemented Map Stack Item: 2019-04-02 22:38:41 +02:00
builder.go Add Builder 2019-03-15 22:27:34 +00:00
bytearray.go Implemented Map Stack Item: 2019-04-02 22:38:41 +02:00
context.go Merge branch 'vm' into dauTT/vm-NOP-JMP-JMPIF-JMPIFNOT-opcodes 2019-08-12 12:42:21 +03:00
instruction.go Move opcode file 2019-03-15 22:35:12 +00:00
Int.go Merge branch 'vm' into dauTT/vm-bitwise-opcodes-191 2019-08-12 12:21:52 +03:00
int_test.go Refactor Int, Boolean, ByteArray conversion 2019-03-15 22:30:25 +00:00
invocationstack.go [Stack] 2019-03-18 21:15:09 +00:00
map.go Implemented Map Stack Item: 2019-04-02 22:38:41 +02:00
map_test.go pkg/vm/stack: improve Array testing code slightly 2019-08-12 17:12:05 +03:00
Readme.md - Add guide to stack readme 2019-02-28 13:51:02 +00:00
stack.go Merge branch 'vm' into dauTT/vm-XSWAP-XTUCK-DEPTH-DROP-opcode 2019-08-12 13:02:24 +03:00
stack_test.go VM: removed helper functions from stack_test.go 2019-02-27 21:40:31 +00:00
stackitem.go Implemented Map Stack Item: 2019-04-02 22:38:41 +02:00
stackitem_test.go VM: Add tests for stack item 2019-02-27 20:56:19 +00:00
test_helper.go pkg/vm/stack: improve Array testing code slightly 2019-08-12 17:12:05 +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 }