forked from TrueCloudLab/neoneo-go
- Add Add
OpCode
- Add Opcode Function map
This commit is contained in:
parent
101d48cd27
commit
c7fb4c3bdf
2 changed files with 32 additions and 0 deletions
7
pkg/vm/vm_ops.go
Normal file
7
pkg/vm/vm_ops.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import "github.com/CityOfZion/neo-go/pkg/vm/stack"
|
||||||
|
|
||||||
|
var opFunc = map[stack.Instruction]func(ctx *stack.Context, istack *stack.Invocation) error{
|
||||||
|
stack.ADD: Add,
|
||||||
|
}
|
25
pkg/vm/vm_ops_maths.go
Normal file
25
pkg/vm/vm_ops_maths.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import "github.com/CityOfZion/neo-go/pkg/vm/stack"
|
||||||
|
|
||||||
|
// Add adds two stack Items together.
|
||||||
|
// Returns an error if either items cannot be casted to an integer
|
||||||
|
// or if integers cannot be added together
|
||||||
|
func Add(ctx *stack.Context, istack *stack.Invocation) error {
|
||||||
|
operandA, err := ctx.Estack.PopInt()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
operandB, err := ctx.Estack.PopInt()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
res, err := operandA.Add(operandB)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Estack.Push(res)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue