mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-11 15:30:07 +00:00
1fb66d6b73
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. |
||
---|---|---|
.. | ||
array.go | ||
array_test.go | ||
boolean.go | ||
builder.go | ||
bytearray.go | ||
context.go | ||
instruction.go | ||
Int.go | ||
int_test.go | ||
invocationstack.go | ||
map.go | ||
map_test.go | ||
Readme.md | ||
stack.go | ||
stack_test.go | ||
stackitem.go | ||
stackitem_test.go | ||
test_helper.go |
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 }