/
func_splice.go
executable file
·100 lines (95 loc) · 2.1 KB
/
func_splice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package vm
func opCat(e *ExecutionEngine) (VMState, error) {
if e.evaluationStack.Count() < 2 {
return FAULT, nil
}
x2 := e.evaluationStack.Pop()
x1 := e.evaluationStack.Pop()
b1 := AssertStackItem(x1).GetByteArray()
b2 := AssertStackItem(x2).GetByteArray()
if len(b1) != len(b2) {
return FAULT, nil
}
r := ByteArrZip(b1, b2, CAT)
pushData(e, r)
return NONE, nil
}
func opSubStr(e *ExecutionEngine) (VMState, error) {
if e.evaluationStack.Count() < 3 {
return FAULT, nil
}
count := int(AssertStackItem(e.evaluationStack.Pop()).GetBigInteger().Int64())
if count < 0 {
return FAULT, nil
}
index := int(AssertStackItem(e.evaluationStack.Pop()).GetBigInteger().Int64())
if index < 0 {
return FAULT, nil
}
x := e.evaluationStack.Pop()
s := AssertStackItem(x).GetByteArray()
l1 := index + count
l2 := len(s)
if l1 > l2 {
return FAULT, nil
}
b := s[index : l2-l1+1]
err := pushData(e, b)
if err != nil {
return FAULT, err
}
return NONE, nil
}
func opLeft(e *ExecutionEngine) (VMState, error) {
if e.evaluationStack.Count() < 2 {
return FAULT, nil
}
count := int(AssertStackItem(e.evaluationStack.Pop()).GetBigInteger().Int64())
if count < 0 {
return FAULT, nil
}
x := e.evaluationStack.Pop()
s := AssertStackItem(x).GetByteArray()
if count > len(s) {
return FAULT, nil
}
b := s[:count]
err := pushData(e, b)
if err != nil {
return FAULT, err
}
return NONE, nil
}
func opRight(e *ExecutionEngine) (VMState, error) {
if e.evaluationStack.Count() < 2 {
return FAULT, nil
}
count := int(AssertStackItem(e.evaluationStack.Pop()).GetBigInteger().Int64())
if count < 0 {
return FAULT, nil
}
x := e.evaluationStack.Pop()
s := AssertStackItem(x).GetByteArray()
l := len(s)
if count > l {
return FAULT, nil
}
b := s[l-count:]
err := pushData(e, b)
if err != nil {
return FAULT, err
}
return NONE, nil
}
func opSize(e *ExecutionEngine) (VMState, error) {
if e.evaluationStack.Count() < 1 {
return FAULT, nil
}
x := e.evaluationStack.Peek(0)
s := AssertStackItem(x).GetByteArray()
err := pushData(e, len(s))
if err != nil {
return FAULT, err
}
return NONE, nil
}