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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#!/bin/sh
# Alternative to build2 that can stop after any step. For example:
# $ ./build3 mu.cc
set -e # stop immediately on error
# Some environment variables that can be passed in. For example, to turn off
# optimization:
# $ CFLAGS=-g ./build3
test "$CXX" || export CXX=c++
test "$CC" || export CC=cc
test "$CFLAGS" || export CFLAGS="-g -O2"
export CFLAGS="$CFLAGS -Wall -Wextra -ftrapv -fno-strict-aliasing"
# Outline:
# [0-9]*.cc -> mu.cc -> .build/*.cc -> .build/*.o -> .build/mu_bin
# (layers) | | | |
# tangle cleave $CXX $CXX
## arg parsing
# can be called with a target to stop after a partial build
# $ ./build3 mu.cc
# can also be called with a layer to only build until
# $ ./build3 --until 050
# scenarios:
# ./build3 => TARGET= UNTIL_LAYER=zzz
# ./build3 x => TARGET=x UNTIL_LAYER=zzz
# ./build3 --until => TARGET= UNTIL_LAYER=zzz
# ./build3 --until 050 => TARGET=//: Spaces help isolate recipes from each other. You can create them at will,
//: and all addresses in arguments are implicitly based on the 'default-space'
//: (unless they have the /raw property)
:(scenario set_default_space)
# if default-space is 10, and if an array of 5 locals lies from location 12 to 16 (inclusive),
# then local 0 is really location 12, local 1 is really location 13, and so on.
def main [
# pretend address:array:location; in practice we'll use new
10:number <- copy 0 # refcount
11:number <- copy 5 # length
default-space:address:array:location <- copy 10/unsafe
1:number <- copy 23
]
+mem: storing 23 in location 13
:(scenario lookup_sidesteps_default_space)
def main [
# pretend pointer from outside (2000 reserved for refcount)
2001:number <- copy 34
# pretend address:array:location; in practice we'll use new
1000:number <- copy 0 # refcount
1001:number <- copy 5 # length
# actual start of this recipe
default-space:address:array:location <- copy 1000/unsafe
1:address:number <- copy 2000/unsafe # even local variables always contain raw addresses
8:number/raw <- copy *1:address:number
]
+mem: storing 34 in location 8
//:: first disable name conversion for 'default-space'
:(scenario convert_names_passes_default_space)
% Hide_errors = true;
def main [
default-space:number, x:number <- copy 0, 1
]
+name: assign x 1
-name: assign default-space 1
:(before "End is_disqualified Cases")
if (x.name == "default-space")
x.initialized = true;
:(before "End is_special_name Cases")
if (s == "default-space") return true;
//:: now implement space support
:(before "End call Fields")
int default_space;
:(before "End call Constructor")
default_space = 0;
:(before "End canonize(x) Special-cases")
absolutize(x);
:(code)
void absolutize(reagent& x) {
if (is_raw(x) || is_dummy(x)) return;
if (x.name == "default-space") return;
if (!x.initialized) {
raise << to_original_string(current_instruction()) << ": reagent not initialized: '" << x.original_string << "'\n" << end();
}
x.set_value(address(x.value, space_base(x)));
x.properties.push_back(pair<string, string_tree*>("raw", NULL));
assert(is_raw(x));
}
int space_base(const reagent& x) {
// temporary stub; will be replaced in a later layer
return current_call().default_space ? (current_call().default_space+/*skip refcount*/1) : 0;
}
int address(int offset, int base) {
assert(offset >= 0);
if (base == 0) return offset; // raw
int size = get_or_insert(Memory, base);
if (offset >= size) {
// todo: test
raise << "location " << offset << " is out of bounds " << size << " at " << base << '\n' << end();
return 0;
}
return base + /*skip length*/1 + offset;
}
|