2 # Build and test all included Mu and SubX programs on Linux:
3 # translate them into ELF binaries
4 # if possible, compare the generated binaries with what's already in git
5 # run/test the ELF binaries in emulated mode
6 # run/test the ELF binaries in native mode
10 # test_apps record # don't compare with what's in git
15 echo "== translating using the bootstrap C++ translator"
20 bootstrap
/bootstrap translate
000init.subx apps
/ex1.subx
-o ex1
22 bootstrap
/bootstrap run ex1 || ret
=$?
23 test $ret -eq 42 # life, the universe and everything
28 test $ret -eq 42 # life, the universe and everything
32 bootstrap
/bootstrap translate
000init.subx apps
/ex2.subx
-o ex2
34 bootstrap
/bootstrap run ex2 || ret
=$?
35 test $ret -eq 7 # 3 + 4
40 test $ret -eq 7 # 3 + 4
44 bootstrap
/bootstrap translate
000init.subx apps
/ex3.subx
-o ex3
46 bootstrap
/bootstrap run ex3 || ret
=$?
47 test $ret -eq 55 # 1 + 2 + ... + 10
52 test $ret -eq 55 # 1 + 2 + ... + 10
56 bootstrap
/bootstrap translate
000init.subx apps
/ex4.subx
-o ex4
58 echo a | bootstrap
/bootstrap run ex4
>ex4.out || true
59 test `cat ex4.out` = 'a'
63 echo a | .
/ex4
>ex4.out || true
64 test `cat ex4.out` = 'a'
68 bootstrap
/bootstrap translate
000init.subx apps
/ex5.subx
-o ex5
70 echo a | bootstrap
/bootstrap run ex5
>ex5.out || true
71 test `cat ex5.out` = 'a'
75 echo a | .
/ex5
>ex5.out || true
76 test `cat ex5.out` = 'a'
80 bootstrap
/bootstrap translate
000init.subx apps
/ex6.subx
-o ex6
82 bootstrap
/bootstrap run ex6
>ex6.out || true
83 test "`cat ex6.out`" = 'Hello world!'
87 .
/ex6
>ex6.out || true
88 test "`cat ex6.out`" = 'Hello world!'
92 bootstrap
/bootstrap translate
000init.subx apps
/ex7.subx
-o ex7
94 bootstrap
/bootstrap run ex7 || ret
=$?
95 test $ret -eq 97 # 'a'
100 test $ret -eq 97 # 'a'
104 bootstrap
/bootstrap translate
000init.subx apps
/ex8.subx
-o ex8
106 bootstrap
/bootstrap run ex8 abcd || ret
=$?
107 test $ret -eq 4 # length('abcd')
112 test $ret -eq 4 # length('abcd')
116 bootstrap
/bootstrap translate
000init.subx apps
/ex9.subx
-o ex9
118 bootstrap
/bootstrap run ex9 z x || ret
=$?
119 test $ret -eq 2 # 'z' - 'x'
124 test $ret -eq 2 # 'z' - 'x'
128 bootstrap
/bootstrap translate
000init.subx apps
/ex10.subx
-o ex10
130 bootstrap
/bootstrap run ex10 abc abc || ret
=$?
131 test $ret -eq 1 # equal
132 bootstrap
/bootstrap run ex10 abc abcd
# 0; not equal
136 .
/ex10 abc abc || ret
=$?
137 test $ret -eq 1 # equal
138 .
/ex10 abc abcd
# 0; not equal
142 bootstrap
/bootstrap translate
000init.subx apps
/ex11.subx
-o ex11
144 bootstrap
/bootstrap run ex11
154 bootstrap
/bootstrap translate
000init.subx apps
/ex12.subx
-o ex12
155 bootstrap
/bootstrap run ex12
# final byte of mmap'd address is well-nigh guaranteed to be 0
160 bootstrap
/bootstrap translate
000init.subx apps
/ex13.subx
-o ex13
162 bootstrap
/bootstrap run ex13 || ret
=$?
163 test $ret -eq 1 # 3 == 3
168 test $ret -eq 1 # 3 == 3
171 # Larger apps that use the standard library.
174 bootstrap
/bootstrap translate
[01]*.subx apps
/factorial.subx
-o factorial
176 bootstrap
/bootstrap run factorial || ret
=$?
177 test $ret -eq 120 # factorial(5)
178 bootstrap
/bootstrap run factorial
test
183 .
/factorial || ret
=$?
184 test $ret -eq 120 # factorial(5)
190 bootstrap
/bootstrap translate
[01]*.subx apps
/random.subx
-o random
193 # Phases of the self-hosted SubX translator.
195 for phase
in hex survey_elf survey_baremetal labels_baremetal pack assort dquotes tests
198 bootstrap
/bootstrap translate
[01]*.subx subx-params.subx
$phase.subx
-o $phase
199 test "$1" = 'record' || git
diff --exit-code $phase
201 bootstrap
/bootstrap run
$phase test
211 # Higher-level syntax.
213 # Certain phases of translation run native beyond this point. We're starting
214 # to go beyond functionality of the C++ bootstrap_bin.
217 bootstrap
/bootstrap translate
[012]*.subx subx-params.subx sigils.subx
-o sigils
218 test "$1" = 'record' || git
diff --exit-code sigils
220 bootstrap
/bootstrap run sigils
test
230 cat [012]*.subx subx-params.subx calls.subx | .
/sigils
> a.sigils
231 bootstrap
/bootstrap translate a.sigils
-o calls
232 test "$1" = 'record' || git
diff --exit-code calls
234 bootstrap
/bootstrap run calls
test
244 cat [012]*.subx subx-params.subx braces.subx | .
/calls | .
/sigils
> a.sigils
245 bootstrap
/bootstrap translate a.sigils
-o braces
246 test "$1" = 'record' || git
diff --exit-code braces
248 bootstrap
/bootstrap run braces
test
258 cat [0-2]*.subx mu.subx | .
/braces | .
/calls | .
/sigils
> a.sigils
259 bootstrap
/bootstrap translate a.sigils
-o mu
260 test "$1" = 'record' || git
diff --exit-code mu
262 bootstrap
/bootstrap run mu
test
271 echo "== translating using the self-hosted translator"
278 .
/translate_subx
000init.subx apps
/ex
$n.subx
282 # Larger apps that use the standard library.
287 .
/translate_subx
[01]*.subx apps
/$app.subx
291 # Phases of the self-hosted SubX translator.
293 for app
in hex survey_elf survey_baremetal labels_baremetal pack assort dquotes tests
296 .
/translate_subx
[01]*.subx subx-params.subx
$app.subx
300 for app
in sigils calls braces
303 .
/translate_subx
[012]*.subx subx-params.subx
$app.subx
309 .
/translate_subx
[0-2]*.subx mu.subx
315 .
/translate apps
/ex1.mu
317 bootstrap
/bootstrap run a.elf || ret
=$?
318 test $ret -eq 42 # life, the universe and everything
322 test $ret -eq 42 # life, the universe and everything
326 .
/translate apps
/ex2.mu
328 bootstrap
/bootstrap run a.elf || ret
=$?
337 .
/translate apps
/ex3.mu
339 bootstrap
/bootstrap run a.elf || ret
=$?
348 .
/translate apps
/ex3.2.mu
350 bootstrap
/bootstrap run a.elf || ret
=$?
359 .
/translate apps
/factorial.mu
361 bootstrap
/bootstrap run a.elf || ret
=$?
363 bootstrap
/bootstrap run a.elf
test