-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.txt
119 lines (105 loc) · 1.68 KB
/
example.txt
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
function fac(a) {
if (a == 1) return 1
return a * fac(a - 1);
}
=>
function fac(a) {
if (=(a, int.$create1)) return int.$create1;
}
#define ObjectFlags int
#define OBJ_LEXIMMUTABLE 0x1
// immutable objects are also lex immutable
#define OBJ_IMMUTABLE 0x3
struct object {
struct object *parent;
ObjectFlags flags;
int refs;
struct table tbl;
}
sys {
int
bool
function
const_ints {
int0
int1
int5
etc.
}
= <- function
+ <- function
- <- function
* <- function
}
fac(%0):
[
null: [
get_root %2
access %3 = %2 . 'const_ints'
access %4 = %3 . 'int1'
get_context %5
access %6 = %5 . '='
call %7 = %6 ( %0 %4 )
testbr %7 'if_body' 'past_if'
]
'if_body': [
return %4
]
'past_if': [
get_context %8
access %9 = %8 . '-'
call %10 = %9 ( %0 %4 )
access %11 = %8 . 'fac'
call %12 = %11 ( %10 )
access %13 = %8 . '*'
call %14 = %13 ( %0 %12 )
return %14
]
]
fac(%0):
[
[
get_root %2
access %3 = %2 . 'const_ints'
access %4 = %3 . 'int1'
get_context %5
access %6 = %5 . '='
call %7 = %6 ( %0 %4 )
testbr %7 1 2
],
[
return %4
],
[
get_context %8
access %9 = %8 . '-'
call %10 = %9 ( %0 %4 )
access %11 = %8 . 'fac'
call %12 = %11 ( %10 )
access %13 = %8 . '*'
call %14 = %13 ( %0 %12 )
return %14
]
]
instructions:
statements:
get_root [var]
get_context [var]
access [var] = [var] . [key]
call [var] = [function] ( [arg]* )
block enders:
return [var]
br [block]
testbr [var] [trueblock] [falseblock]
typedef enum {
GetRoot
Access
Lookup
Call
Return
Br
TestBr
} InstrType;
struct Instr {
InstrType type;
}