-
Notifications
You must be signed in to change notification settings - Fork 2
/
local_vars.go
82 lines (64 loc) · 1.82 KB
/
local_vars.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
package rtda
import (
"./heap"
"math"
)
type LocalVars struct {
slots []Slot
}
func NewLocalVars(maxLocals uint) *LocalVars {
if maxLocals > 0 {
//fmt.Printf("[gvm][LocalVars.NewLocalVars] maxLocals : %v \n", maxLocals)
localvars := &LocalVars{
slots: make([]Slot, maxLocals),
}
//fmt.Println("[gvm][NewLocalVars] done")
return localvars
}
return nil
}
func (self *LocalVars) SetInt(index uint, val int32) {
//fmt.Printf("[gvm][SetInt] index : %v, val : %v \n", index, val)
self.slots[index].num = val
//fmt.Printf("[gvm][SetInt] 设置后的结果 val : %v \n", self.GetInt(index))
}
func (self *LocalVars) GetInt(index uint) int32 {
return self.slots[index].num
}
func (self *LocalVars) SetFloat(index uint, val float32) {
bits := math.Float32bits(val)
self.slots[index].num = int32(bits)
}
func (self *LocalVars) GetFloat(index uint) float32 {
bits := uint32(self.slots[index].num)
return math.Float32frombits(bits)
}
func (self *LocalVars) SetLong(index uint, val int64) {
self.slots[index].num = int32(val)
self.slots[index+1].num = int32(val >> 32)
}
func (self *LocalVars) GetLong(index uint) int64 {
low := uint32(self.slots[index].num)
high := uint32(self.slots[index+1].num)
return int64(high)<<32 | int64(low)
}
func (self LocalVars) SetDouble(index uint, val float64) {
bits := math.Float64bits(val)
self.SetLong(index, int64(bits))
}
func (self LocalVars) GetDouble(index uint) float64 {
bits := uint64(self.GetLong(index))
return math.Float64frombits(bits)
}
func (self LocalVars) SetRef(index uint, ref *heap.Object) {
self.slots[index].ref = ref
}
func (self LocalVars) GetRef(index uint) *heap.Object {
return self.slots[index].ref
}
func (self LocalVars) SetSlot(index uint, slot Slot) {
self.slots[index] = slot
}
func (self LocalVars) GetThis() *heap.Object {
return self.GetRef(0)
}