-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgolightly.go
71 lines (55 loc) · 1.54 KB
/
golightly.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
// TODO: Further work on the memory page model and how that interacts with the register model
// TODO: Add more support for debugging to ProcessorCore
// TODO: Consider alternatives for VLIW
// 1 pool of channels all working against current processor state
// 2 duplicated processors each feeding back results
// synchoronous or asynchronous operation?
package golightly
import . "golightly/vm"
type Processor struct {
ProcessorCore
data_stack []int
}
func (p *Processor) Init(registers int) {
p.ProcessorCore.Init(registers, new(InstructionSet))
p.Movement("ijump", "r", func(o *OpCode) {
p.PC = p.R.At(o.Data.(int)).(int)
})
p.Movement("zjump", "r, n", func(o *OpCode) {
if p.R.Equal(o.a, 0) {
p.PC = o.b
}
})
p.Movement("icall", "r", func(o *OpCode) {
p.Call(p.R.At(o.a).(int))
})
p.Operator("ld", "r1, r2", func(o *OpCode) {
p.R.Copy(o.a, o.b)
})
p.Operator("push", "r", func(o *OpCode) {
p.data_stack = append(p.data_stack, p.R[o.ia])
})
p.Operator("cpush", "v", func(o *OpCode) {
p.data_stack.Append(o.ia)
})
p.Operator("ipush", "m", func(o *OpCode) {
p.data_stack.Append(p.MP[o.ia])
})
p.Operator("pop", "r", func(o *OpCode) {
p.R.Set(o.a, p.data_stack.Pop())
})
p.Operator("ipop", "m", func(o *OpCode) {
p.MP.Set(o.a, p.data_stack.Pop())
})
/*
p.Operator("pselect", "p", func(o *OpCode) {
p.MP = IntBuffer(o.a)
})
*/
p.Operator("ild", "r1, r2", func(o *OpCode) {
p.R.Set(o.a, p.R.At(p.MP.At(o.b)))
})
p.Operator("istore", "r, m", func(o *OpCode) {
p.MP.Set(p.R.At(o.b), p.R.At(o.a))
})
}