This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instr.go
127 lines (119 loc) · 2.07 KB
/
instr.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package fidgetlang
type instruction byte
const (
iIncrPtr instruction = 1 << iota
iDecrPtr
iIncrVal
iDecrVal
iPutVal
iGetVal
iJumpAhead
iJumpBehind
iNop instruction = 0
sIncrPtr = "߷"
sDecrPtr = "߷߷"
sIncrVal = "߷߷߷"
sDecrVal = "߷߷߷߷"
sPutVal = "߷߷߷߷߷"
sGetVal = "߷߷߷߷߷߷"
sJumpAhead = "߷߷߷߷߷߷߷"
sJumpBehind = "߷߷߷߷߷߷߷߷"
sNop = " "
dIncrPtr = "IncrPtr"
dDecrPtr = "DecrPtr"
dIncrVal = "IncrVal"
dDecrVal = "DecrVal"
dPutVal = "PutVal"
dGetVal = "GetVal"
dJumpAhead = "JumpAhead"
dJumpBehind = "JumpBehind"
dNop = "Nop"
)
func stringToInstruction(d string) instruction {
switch d {
case sIncrPtr:
return iIncrPtr
case sDecrPtr:
return iDecrPtr
case sIncrVal:
return iIncrVal
case sDecrVal:
return iDecrVal
case sPutVal:
return iPutVal
case sGetVal:
return iGetVal
case sJumpAhead:
return iJumpAhead
case sJumpBehind:
return iJumpBehind
default:
return iNop
}
}
func instructionToString(i instruction) string {
switch i {
case iIncrPtr:
return sIncrPtr
case iDecrPtr:
return sDecrPtr
case iIncrVal:
return sIncrVal
case iDecrVal:
return sDecrVal
case iPutVal:
return sPutVal
case iGetVal:
return sGetVal
case iJumpAhead:
return sJumpAhead
case iJumpBehind:
return sJumpBehind
default:
return sNop
}
}
func debugToInstruction(d string) instruction {
switch d {
case dIncrPtr:
return iIncrPtr
case dDecrPtr:
return iDecrPtr
case dIncrVal:
return iIncrVal
case dDecrVal:
return iDecrVal
case dPutVal:
return iPutVal
case dGetVal:
return iGetVal
case dJumpAhead:
return iJumpAhead
case dJumpBehind:
return iJumpBehind
default:
return iNop
}
}
func instructionToDebug(i instruction) string {
switch i {
case iIncrPtr:
return dIncrPtr
case iDecrPtr:
return dDecrPtr
case iIncrVal:
return dIncrVal
case iDecrVal:
return dDecrVal
case iPutVal:
return dPutVal
case iGetVal:
return dGetVal
case iJumpAhead:
return dJumpAhead
case iJumpBehind:
return dJumpBehind
default:
return dNop
}
}