-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (44 loc) · 1008 Bytes
/
main.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
// bytecode interpreter
// 32-bit stack machine with minimized code size (for IoT application)
package main
import "fmt"
// config
const (
Msz = 0x1000 // main memory size, bytes
Rsz = 0x100 // return stack size, cells
Dsz = 0x10 // data stack size, cells
)
// ============================================ virtual machine data structures
var Sp uint = 0 //data stack pointer
var Rp uint = 0 // return stack pointer
var Ip uint = 0 // instruction pointer
var Cp uint = 0 // compiler pointer
// ======================================================= bytecode definitions
const (
NOP = iota
JMP
qJMP
CALL
RET
LIT
DUP
DROP
SWAP
OVER
PRESS
DROPALL
ADD
SUB
MUL
DIV
)
// ================================================================ system init
func main() {
fmt.Println("")
fmt.Println("bytecode interpreter")
fmt.Println("")
fmt.Println("main memory\tM[", Msz, "]")
fmt.Println("return stack\tM[", Rsz, "]")
fmt.Println("data stack\tM[", Dsz, "]")
fmt.Println("")
}