-
Notifications
You must be signed in to change notification settings - Fork 200
/
inst_table.go
73 lines (59 loc) · 1.13 KB
/
inst_table.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
package vm
import . "luago/api"
/* number of list items to accumulate before a SETLIST instruction */
const LFIELDS_PER_FLUSH = 50
// R(A) := {} (size = B,C)
func newTable(i Instruction, vm LuaVM) {
a, b, c := i.ABC()
a += 1
vm.CreateTable(Fb2int(b), Fb2int(c))
vm.Replace(a)
}
// R(A) := R(B)[RK(C)]
func getTable(i Instruction, vm LuaVM) {
a, b, c := i.ABC()
a += 1
b += 1
vm.GetRK(c)
vm.GetTable(b)
vm.Replace(a)
}
// R(A)[RK(B)] := RK(C)
func setTable(i Instruction, vm LuaVM) {
a, b, c := i.ABC()
a += 1
vm.GetRK(b)
vm.GetRK(c)
vm.SetTable(a)
}
// R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
func setList(i Instruction, vm LuaVM) {
a, b, c := i.ABC()
a += 1
if c > 0 {
c = c - 1
} else {
c = Instruction(vm.Fetch()).Ax()
}
bIsZero := b == 0
if bIsZero {
b = int(vm.ToInteger(-1)) - a - 1
vm.Pop(1)
}
vm.CheckStack(1)
idx := int64(c * LFIELDS_PER_FLUSH)
for j := 1; j <= b; j++ {
idx++
vm.PushValue(a + j)
vm.SetI(a, idx)
}
if bIsZero {
for j := vm.RegisterCount() + 1; j <= vm.GetTop(); j++ {
idx++
vm.PushValue(j)
vm.SetI(a, idx)
}
// clear stack
vm.SetTop(vm.RegisterCount())
}
}