-
Notifications
You must be signed in to change notification settings - Fork 2
/
dup.go
104 lines (89 loc) · 2.1 KB
/
dup.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
101
102
103
104
package stack
import "../../instructions/base"
import "../../rtda"
type Dup struct {
base.NoOperandsInstruction
}
type Dup_X1 struct {
base.NoOperandsInstruction
}
type Dup_X2 struct {
base.NoOperandsInstruction
}
type Dup2 struct {
base.NoOperandsInstruction
}
type Dup2_X1 struct {
base.NoOperandsInstruction
}
type Dup2_X2 struct {
base.NoOperandsInstruction
}
// Duplicate the top operandStack value
func (self *Dup) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
slot := stack.PopSlot()
stack.PushSlot(slot)
stack.PushSlot(slot)
}
/*
Duplicate the top operand stack value and insert two values down
before : top ->down 1,2,3,4
after : 1,2,1,3,4 . top value 1 duplicate and then insert two values down
*/
func (self *Dup_X1) Execute(frame *rtda.Frame) {
f := frame.OperandStack()
slot1 := f.PopSlot()
slot2 := f.PopSlot()
f.PushSlot(slot1)
f.PushSlot(slot2)
f.PushSlot(slot1)
}
/*
Duplicate the top operand stack value and insert three values down
before : top ->down 1,2,3,4
after : 1,2,3,1,4 . top value 1 duplicate and then insert three values down
*/
func (self *Dup_X2) Execute(frame *rtda.Frame) {
f := frame.OperandStack()
slot1 := f.PopSlot()
slot2 := f.PopSlot()
slot3 := f.PopSlot()
f.PushSlot(slot1)
f.PushSlot(slot3)
f.PushSlot(slot2)
f.PushSlot(slot1)
}
func (self *Dup2) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
slot1 := stack.PopSlot()
slot2 := stack.PopSlot()
stack.PushSlot(slot2)
stack.PushSlot(slot1)
stack.PushSlot(slot2)
stack.PushSlot(slot1)
}
func (self *Dup2_X1) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
slot1 := stack.PopSlot()
slot2 := stack.PopSlot()
slot3 := stack.PopSlot()
stack.PushSlot(slot2)
stack.PushSlot(slot1)
stack.PushSlot(slot3)
stack.PushSlot(slot2)
stack.PushSlot(slot1)
}
func (self *Dup2_X2) Execute(frame *rtda.Frame) {
stack := frame.OperandStack()
slot1 := stack.PopSlot()
slot2 := stack.PopSlot()
slot3 := stack.PopSlot()
slot4 := stack.PopSlot()
stack.PushSlot(slot2)
stack.PushSlot(slot1)
stack.PushSlot(slot4)
stack.PushSlot(slot3)
stack.PushSlot(slot2)
stack.PushSlot(slot1)
}