run_tests.sh 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. #!/bin/sh
  2. # Step-1 regression: M2 -> gen_ssa/*.ssa -> qbe -> cc -> exit code.
  3. # Usage: ./run_tests.sh (from the compiler directory)
  4. pass=0; fail=0
  5. SHIM="../runtime/syslib/shim.c"
  6. modof() {
  7. sed -n 's/^MODULE \([A-Za-z][A-Za-z0-9]*\).*/\1/p' "tests/$1" | head -n 1
  8. }
  9. expect_run() {
  10. # $1 = test file (no dir), $2 = expected exit code
  11. name="$1"; want="$2"; mod=$(modof "$name")
  12. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod"
  13. if ./M2 "tests/$name" 2>&1 | grep -q "Parsed correctly"; then :; else
  14. fail=$((fail+1)); echo "FAIL(run): $name rejected"; return
  15. fi
  16. if [ ! -f "gen_ssa/$mod.ssa" ]; then
  17. fail=$((fail+1)); echo "FAIL(run): $name no gen_ssa/$mod.ssa"; return
  18. fi
  19. if ! qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2> "gen_ssa/$mod.qbeerr"; then
  20. fail=$((fail+1)); echo "FAIL(run): $name qbe:"; cat "gen_ssa/$mod.qbeerr"; return
  21. fi
  22. if ! cc "gen_ssa/$mod.s" "$SHIM" -o "gen_ssa/$mod" 2> "gen_ssa/$mod.ccerr"; then
  23. fail=$((fail+1)); echo "FAIL(run): $name cc:"; cat "gen_ssa/$mod.ccerr"; return
  24. fi
  25. timeout 10 "gen_ssa/$mod" > /dev/null 2>&1; got=$?
  26. if [ "$got" = "$want" ]; then
  27. pass=$((pass+1)); echo "PASS(run): $name -> $got"
  28. else
  29. fail=$((fail+1)); echo "FAIL(run): $name got $got want $want"
  30. fi
  31. }
  32. expect_fail() {
  33. # $1 = test file, $2 = message text expected in the .LST
  34. name="$1"; want="$2"
  35. if ./M2 "tests/$name" 2>&1 | grep -q "Incorrect source"; then :; else
  36. fail=$((fail+1)); echo "FAIL(fail): $name accepted"; return
  37. fi
  38. lst="tests/$(basename "$name" .mod).LST"
  39. if grep -q "$want" "$lst" 2>/dev/null; then
  40. pass=$((pass+1)); echo "PASS(fail): $name [$want]"
  41. else
  42. fail=$((fail+1)); echo "FAIL(fail): [$want] not found in $lst"
  43. fi
  44. }
  45. mkdir -p gen_ssa
  46. expect_run t_minimal.mod 0
  47. expect_run t_exit.mod 7
  48. expect_run t_arith.mod 25
  49. expect_run showcase1.mod 50
  50. expect_run t_types.mod 8
  51. expect_run showcase2.mod 71
  52. expect_run t_if.mod 25
  53. expect_run t_while.mod 55
  54. expect_run t_repeat.mod 55
  55. expect_run t_loop.mod 55
  56. expect_run t_for.mod 85
  57. expect_run t_case.mod 103
  58. expect_run t_setcase.mod 42
  59. expect_run t_varsame.mod 42
  60. expect_run t_bareproc.mod 42
  61. expect_run t_variantext.mod 42
  62. expect_run t_bool.mod 42
  63. expect_run t_real.mod 31
  64. expect_run t_lfloat.mod 42
  65. expect_run t_array.mod 108
  66. expect_run t_multidim.mod 42
  67. expect_run t_multidim_local.mod 42
  68. expect_run t_open2d.mod 42
  69. expect_run t_open2d_high.mod 42
  70. expect_run t_open2d_size.mod 42
  71. expect_run t_open1d_size_adr.mod 42
  72. expect_run t_open_row_adr.mod 42
  73. expect_run t_record_multidim.mod 42
  74. expect_run t_record_multidim_ctor.mod 42
  75. expect_run t_record_multidim_const.mod 42
  76. expect_run t_record_multidim_arrctor.mod 42
  77. expect_run t_open2d_adr.mod 42
  78. expect_run t_open2d_value.mod 42
  79. expect_run t_open3d.mod 42
  80. expect_run t_open3d_row.mod 42
  81. expect_run t_open_row_to_1d.mod 42
  82. expect_run t_open_flatten_byte.mod 42
  83. expect_run t_open2d_nested.mod 42
  84. expect_run t_subrange.mod 42
  85. expect_run t_emptychar.mod 42
  86. expect_run t_system.mod 42
  87. expect_run t_proctype2.mod 42
  88. expect_run t_byte.mod 42
  89. expect_run t_word16.mod 42
  90. expect_run t_packedset.mod 42
  91. expect_run t_ptrchain.mod 42
  92. expect_run t_finally.mod 43
  93. expect_run t_finally_return.mod 43
  94. expect_run t_finally_except.mod 42
  95. expect_run t_finally_local.mod 43
  96. expect_run t_except_parse.mod 42
  97. expect_run t_except_throw.mod 42
  98. expect_run t_except_retry.mod 42
  99. expect_run t_except_return.mod 43
  100. expect_run t_except_nested.mod 42
  101. expect_run t_except_module.mod 42
  102. expect_run t_except_signal.mod 42
  103. expect_fail t_retry_bad.mod "RETRY outside EXCEPT"
  104. expect_run t_smallgaps.mod 42
  105. expect_run t_ctor1.mod 0
  106. expect_run t_ctor2.mod 0
  107. expect_run t_ctor3.mod 0
  108. expect_run t_ctor4.mod 0
  109. expect_run t_ctor5.mod 0
  110. expect_run t_ctor6.mod 0
  111. expect_run t_ctor7.mod 42
  112. expect_run t_minmax.mod 42
  113. expect_run t_minmax2.mod 42
  114. expect_run t_setops.mod 42
  115. expect_run t_ptrfwd.mod 42
  116. expect_run t_libc.mod 42
  117. expect_run t_libc2.mod 42
  118. expect_run t_variant2.mod 42
  119. expect_run t_addrptr.mod 42
  120. expect_run t_nestedmod.mod 42
  121. expect_run t_nestidx.mod 42
  122. expect_run t_proctype.mod 42
  123. expect_run t_compat.mod 42
  124. expect_run t_constfold.mod 42
  125. expect_run t_resultsfx.mod 42
  126. expect_run t_coroutine.mod 42
  127. expect_fail t_fwdvar.mod "undeclared identifier"
  128. expect_fail t_fwdsel.mod "undeclared identifier"
  129. expect_fail t_fwdprop.mod "undeclared identifier"
  130. expect_run t_fwdproc.mod 7
  131. expect_run t_fwdok.mod 42
  132. expect_run t_emptystat.mod 42
  133. expect_run t_highlen.mod 18
  134. expect_run t_builtins.mod 42
  135. expect_run t_long.mod 42
  136. expect_run t_truncfloat.mod 42
  137. expect_run t_enumidx.mod 42
  138. expect_run t_setenum.mod 42
  139. expect_run t_setconst.mod 42
  140. expect_run t_constbuiltin.mod 42
  141. expect_run t_constreal.mod 42
  142. expect_run t_constlong.mod 42
  143. expect_run t_procaddr.mod 42
  144. expect_run t_convert.mod 42
  145. expect_run t_builtinname.mod 42
  146. expect_run t_setword.mod 42
  147. expect_run t_procval.mod 42
  148. expect_run t_real64.mod 42
  149. expect_run t_shiftneg.mod 42
  150. expect_run t_unicode.mod 31
  151. expect_run t_charbounds.mod 3
  152. expect_run t_record.mod 160
  153. expect_run t_recarr.mod 42
  154. expect_run t_recptr.mod 42
  155. expect_run t_nestarr.mod 42
  156. expect_run t_arrrecfld.mod 42
  157. expect_run t_arrrecbig.mod 42
  158. expect_run t_stmtsfx.mod 42
  159. expect_run t_retrec.mod 42
  160. expect_run t_retmeth.mod 42
  161. expect_run t_chain.mod 42
  162. expect_run t_goto.mod 42
  163. expect_fail t_gotobad.mod "undeclared identifier"
  164. expect_run t_under.mod 42
  165. expect_run t_with.mod 114
  166. expect_run t_set.mod 131
  167. expect_run t_setchar.mod 77
  168. expect_run t_setrange.mod 55
  169. expect_run t_classmethod.mod 7
  170. expect_run t_classinherit.mod 7
  171. expect_run t_virtual.mod 3
  172. expect_run t_valconv.mod 15
  173. expect_run t_conv.mod 42
  174. expect_run t_convconst.mod 42
  175. expect_run t_classsibling.mod 7
  176. expect_run t_classinit.mod 42
  177. expect_run t_class.mod 0
  178. expect_run t_longline.mod 0
  179. expect_fail t_bad_parent.mod "undeclared identifier"
  180. expect_run showcase3.mod 183
  181. expect_run showcase4.mod 44
  182. expect_fail showcase5.mod "not supported yet"
  183. expect_run showcase6.mod 34
  184. expect_run showcase7.mod 219
  185. expect_run showcase8.mod 170
  186. expect_run showcase9.mod 140
  187. expect_run showcase10.mod 86
  188. expect_run t_pointer.mod 42
  189. expect_run t_ptrarray.mod 15
  190. expect_run t_ptrrec.mod 15
  191. expect_run t_ptrnest.mod 10
  192. expect_fail t_opaqueptr.mod ""
  193. expect_run t_enumdecl.mod 0
  194. expect_run t_enum.mod 15
  195. expect_run t_strcat.mod 63
  196. expect_run t_charcat.mod 15
  197. expect_run t_variant.mod 31
  198. expect_run t_ustrassign.mod 63
  199. expect_run t_ustrformal.mod 3
  200. expect_run t_ustrcat.mod 63
  201. expect_run t_proc.mod 0
  202. expect_run t_forward.mod 0
  203. expect_run t_call.mod 125
  204. expect_run t_varpar.mod 40
  205. expect_run t_mutual.mod 11
  206. expect_run t_withfield.mod 13
  207. expect_run t_valarray.mod 6
  208. expect_run t_openarr.mod 7
  209. expect_run t_nestedproc.mod 20
  210. expect_run t_nestdeep.mod 211
  211. expect_run t_nestrec.mod 15
  212. expect_fail t_bad_undecl.mod "undeclared identifier"
  213. expect_fail t_bad_dup.mod "duplicate identifier"
  214. expect_fail t_bad_mismatch.mod "module name mismatch"
  215. expect_fail t_bad_opaque.mod "opaque type outside definition"
  216. expect_fail t_bad_while.mod "BOOLEAN condition required"
  217. expect_fail t_bad_exit.mod "not supported yet"
  218. expect_fail t_bad_return.mod "bad RETURN"
  219. expect_fail t_bad_for.mod "FOR needs integer variable and bounds"
  220. expect_fail t_bad_mixed.mod "incompatible assignment"
  221. expect_fail t_bad_fwd.mod "incompatible assignment"
  222. expect_fail t_bad_nestfwd.mod "undeclared identifier"
  223. expect_fail t_fwdtype.mod "undeclared identifier"
  224. expect_fail t_fwdset.mod "undeclared identifier"
  225. expect_fail t_manyproc.mod "not supported yet"
  226. expect_fail t_bad_overlong.mod "invalid UTF-8"
  227. expect_fail t_bad_surrogate.mod "invalid UTF-8"
  228. expect_fail t_bad_utf8big.mod "invalid UTF-8"
  229. expect_fail t_bad_truncutf.mod "invalid UTF-8"
  230. expect_fail t_bad_arity.mod "invalid call"
  231. expect_fail t_bad_actual.mod "invalid call"
  232. expect_fail t_bad_funstmt.mod "invalid call"
  233. expect_fail t_bad_deref.mod "not a POINTER type"
  234. expect_fail t_bad_new.mod "not a POINTER type"
  235. expect_fail t_bad_field.mod "unknown field"
  236. expect_fail t_bad_with.mod "not a RECORD type"
  237. expect_fail t_bad_recassign.mod "incompatible assignment"
  238. expect_fail t_bad_setelem.mod "set operand mismatch"
  239. expect_fail t_bad_setbase.mod "not supported yet"
  240. expect_fail t_bad_setconst.mod "not supported yet"
  241. expect_fail t_bad_in.mod "set operand mismatch"
  242. expect_fail t_bad_index.mod "array index must be integer"
  243. expect_fail t_bad_bounds.mod "not supported yet"
  244. expect_fail t_bad_varbound.mod "not supported yet"
  245. expect_fail t_bad_manydims.mod "not supported yet"
  246. expect_run t_openformal.mod 0
  247. expect_run t_valopen.mod 15
  248. expect_fail t_bad_open.mod "not supported yet"
  249. expect_trap() {
  250. # $1 = test file — must parse, assemble, link, then abort (rc=134)
  251. name="$1"; mod=$(modof "$name")
  252. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod"
  253. if ./M2 "tests/$name" 2>&1 | grep -q "Parsed correctly"; then :; else
  254. fail=$((fail+1)); echo "FAIL(trap): $name rejected"; return
  255. fi
  256. if ! qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2> "gen_ssa/$mod.qbeerr"; then
  257. fail=$((fail+1)); echo "FAIL(trap): $name qbe"; return
  258. fi
  259. if ! cc "gen_ssa/$mod.s" "$SHIM" -o "gen_ssa/$mod" 2> "gen_ssa/$mod.ccerr"; then
  260. fail=$((fail+1)); echo "FAIL(trap): $name cc"; return
  261. fi
  262. timeout 10 "gen_ssa/$mod" > /dev/null 2>&1; got=$?
  263. if [ "$got" = "134" ]; then
  264. pass=$((pass+1)); echo "PASS(trap): $name -> abort"
  265. else
  266. fail=$((fail+1)); echo "FAIL(trap): $name rc=$got want 134"
  267. fi
  268. }
  269. expect_trap t_trap_index.mod
  270. expect_trap t_trap_range.mod
  271. expect_trap t_trap_range_arg.mod
  272. expect_trap t_trap_range_ret.mod
  273. expect_run t_strtrunc.mod 42
  274. expect_trap t_trap_setspan.mod
  275. expect_run t_strempty.mod 42
  276. expect_trap t_trap_chr8.mod
  277. expect_trap t_except_unhandled.mod
  278. expect_trap t_trap_funcret.mod
  279. expect_fail t_defunit.mod ""
  280. expect_fail t_implunit.mod ""
  281. expect_run t_nested.mod 42
  282. # --- separate compilation (step 4.3): $1 prog module, $2 exit code,
  283. # then the session's source files (program last by convention) ---
  284. # Build a session image; echoes 0 on success, non-zero on failure.
  285. build_session() {
  286. prog="$1"; shift
  287. files=""
  288. for f in "$@"; do
  289. case "$f" in */*) files="$files $f";; *) files="$files tests/$f";; esac
  290. done
  291. rm -f "gen_ssa/$prog.ssa" "gen_ssa/$prog.s" "gen_ssa/$prog"
  292. if ./M2 $files 2>&1 | grep -q "Parsed correctly"; then :; else
  293. echo "rejected"; return 1
  294. fi
  295. [ -f "gen_ssa/$prog.ssa" ] || { echo "no image"; return 1; }
  296. qbe -o "gen_ssa/$prog.s" "gen_ssa/$prog.ssa" 2> "gen_ssa/$prog.qbeerr" \
  297. || { echo "qbe"; cat "gen_ssa/$prog.qbeerr"; return 1; }
  298. cc "gen_ssa/$prog.s" "$SHIM" -o "gen_ssa/$prog" -lm 2> "gen_ssa/$prog.ccerr" \
  299. || { echo "cc"; cat "gen_ssa/$prog.ccerr"; return 1; }
  300. return 0
  301. }
  302. expect_run_files() {
  303. prog="$1"; want="$2"; shift 2
  304. if ! build_session "$prog" "$@"; then
  305. fail=$((fail+1)); echo "FAIL(session): $prog $? ($(build_session "$prog" "$@" 2>&1))"; return
  306. fi
  307. timeout 10 "gen_ssa/$prog" > /dev/null 2>&1; got=$?
  308. if [ "$got" = "$want" ]; then
  309. pass=$((pass+1)); echo "PASS(session): $prog -> $got"
  310. else
  311. fail=$((fail+1)); echo "FAIL(session): $prog got $got want $want"
  312. fi
  313. }
  314. expect_run_files_out() {
  315. # $1 prog, $2 exit code, $3 expected first output line, then files
  316. prog="$1"; want="$2"; wantline="$3"; shift 3
  317. if ! build_session "$prog" "$@"; then
  318. fail=$((fail+1)); echo "FAIL(session-out): $prog build failed"; return
  319. fi
  320. out=$(timeout 10 "gen_ssa/$prog" 2>/dev/null); got=$?
  321. first=$(printf '%s\n' "$out" | head -n 1)
  322. if [ "$got" = "$want" ] && [ "$first" = "$wantline" ]; then
  323. pass=$((pass+1)); echo "PASS(session-out): $prog -> $got [$first]"
  324. else
  325. fail=$((fail+1)); echo "FAIL(session-out): $prog rc=$got line=[$first] want=[$wantline]"
  326. fi
  327. }
  328. expect_run_files DBasicProg 49 d_basic.def d_basic.mod d_basic_prog.mod
  329. expect_run_files CForeignProg 42 c_foreign.def c_foreign.mod c_foreign_prog.mod
  330. expect_run_files EEnumProg 42 e_enum.def e_enum_re.def e_enum_prog.mod
  331. expect_run_files TClassDefProg 8 t_classdef.def t_classdef_prog.mod
  332. expect_run_files DQualProg 46 d_basic.def d_basic.mod d_qual_prog.mod
  333. expect_run_files DTypesProg 36 d_types.def d_types.mod d_types_prog.mod
  334. expect_run_files DOpaqueProg 55 d_opaque.def d_opaque.mod d_opaque_prog.mod
  335. expect_run_files TString 42 d_string.def d_string.mod t_string.mod
  336. expect_run_files FioProg 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod fio_prog.mod
  337. expect_run_files StorageProg 42 ../lib/common/storage.def ../lib/common/storage.mod storage_prog.mod
  338. expect_run_files TSysClock 42 ../lib/iso/sysclock.def ../lib/iso/sysclock.mod t_sysclock.mod
  339. expect_run_files TExceptLib 42 \
  340. ../runtime/syslib/SysExceptions.def \
  341. ../runtime/syslib/SysExceptions.mod \
  342. ../lib/iso/m2exception.def ../lib/iso/m2exception.mod \
  343. ../lib/iso/exceptions.def ../lib/iso/exceptions.mod \
  344. t_except_lib.mod
  345. expect_run_files TExceptTrap 42 \
  346. ../runtime/syslib/SysExceptions.def \
  347. ../runtime/syslib/SysExceptions.mod \
  348. ../lib/iso/m2exception.def ../lib/iso/m2exception.mod \
  349. t_except_trap.mod
  350. expect_run_files TExceptCase 42 \
  351. ../runtime/syslib/SysExceptions.def \
  352. ../runtime/syslib/SysExceptions.mod \
  353. ../lib/iso/m2exception.def ../lib/iso/m2exception.mod \
  354. t_except_case.mod
  355. expect_run_files TExceptFuncret 42 \
  356. ../runtime/syslib/SysExceptions.def \
  357. ../runtime/syslib/SysExceptions.mod \
  358. ../lib/iso/m2exception.def ../lib/iso/m2exception.mod \
  359. t_except_funcret.mod
  360. expect_run_files_out FinallyOrder 0 "P!B!A!" \
  361. f_order_a.def f_order_a.mod f_order_b.def f_order_b.mod \
  362. finally_order.mod
  363. expect_run_files TAst 42 \
  364. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  365. ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
  366. src/AST.def src/AST.mod \
  367. t_ast.mod
  368. expect_run_files GenericProg 42 \
  369. g_ident.def g_ident.mod g_intid.def g_intid.mod g_prog.mod
  370. expect_run_files PairProg 73 \
  371. g_pair.def g_pair.mod g_intchar.def g_intchar.mod g_pair_prog.mod
  372. expect_run_files BufProg 42 \
  373. g_buf.def g_buf.mod g_buf10.def g_buf10.mod g_bufprog.mod
  374. expect_run_files SortProg 3 \
  375. g_cmp.def g_cmp.mod g_sort.def g_sort.mod g_isort.def g_isort.mod g_sortprog.mod
  376. expect_run_files OrdProg 42 \
  377. g_ordbox.def g_ordbox.mod g_intbox.def g_intbox.mod g_ordprog.mod
  378. expect_run_files GWrapProg 42 \
  379. g_ordbox.def g_ordbox.mod g_intbox.def g_intbox.mod \
  380. g_wrap.def g_wrap.mod g_wrapb.def g_wrapb.mod g_wrapprog.mod
  381. expect_run_files GCBoxProg 42 \
  382. g_gcbox.def g_gcbox.mod g_gcint.def g_gcint.mod g_gcprog.mod
  383. expect_run_files GStkProg 42 \
  384. g_gstk.def g_gstk.mod g_gstki.def g_gstki.mod g_gstkp.mod
  385. expect_run_files GTwiceProg 42 \
  386. g_twice.def g_twice.mod g_twice_i.def g_twice_i.mod \
  387. g_twice_c.def g_twice_c.mod g_twice_p.mod
  388. expect_run_files TByteBuf 62 t_bytebuf.mod
  389. expect_run_files TStreamFile 42 \
  390. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  391. ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
  392. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  393. ../lib/iso/chanconsts.def ../lib/iso/chanconsts.mod \
  394. ../lib/iso/streamfile.def ../lib/iso/streamfile.mod \
  395. t_streamfile.mod
  396. expect_run_files TPimIO 42 \
  397. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  398. ../lib/pim/inout.def ../lib/pim/inout.mod \
  399. ../lib/pim/strio.def ../lib/pim/strio.mod \
  400. ../lib/pim/numberio.def ../lib/pim/numberio.mod \
  401. ../lib/iso/realio.def ../lib/iso/realio.mod \
  402. ../lib/pim/realinout.def ../lib/pim/realinout.mod \
  403. ../lib/pim/fpuio.def ../lib/pim/fpuio.mod \
  404. t_pimio.mod
  405. expect_run_files WrapProg 42 \
  406. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  407. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  408. ../lib/iso/stdchans.def ../lib/iso/stdchans.mod \
  409. ../lib/gm2/timestring.def ../lib/gm2/timestring.mod \
  410. ../lib/gm2/wrapclock.def ../lib/gm2/wrapclock.mod \
  411. ../lib/gm2/wraptime.def ../lib/gm2/wraptime.mod \
  412. ../lib/gm2/wrapc.def ../lib/gm2/wrapc.mod \
  413. wrapprog.mod
  414. expect_run_files_out Showcase23 35 "list: 5 10 20" \
  415. ../lib/common/sysio.def ../lib/common/sysio.mod \
  416. showcase23lib.def showcase23lib.mod \
  417. showcase23int.def showcase23int.mod \
  418. showcase23vis.def showcase23vis.mod showcase23.mod
  419. expect_run_files_out Showcase24 42 "showcase24 total=42" \
  420. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  421. ../lib/iso/textio.def ../lib/iso/textio.mod \
  422. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  423. ../lib/common/strings.def ../lib/common/strings.mod \
  424. ../lib/common/math.def ../lib/common/math.mod \
  425. showcase24stack.def showcase24stack.mod \
  426. showcase24int.def showcase24int.mod \
  427. showcase24pair.def showcase24pair.mod \
  428. showcase24pic.def showcase24pic.mod \
  429. showcase24util.def showcase24util.mod \
  430. showcase24.mod
  431. expect_run_files TImportProc 7 pvi.def pvi.mod t_importproc.mod
  432. expect_run_files_out Showcase22 42 "showcase22 total=42" \
  433. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  434. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  435. ../lib/iso/stdchans.def ../lib/iso/stdchans.mod \
  436. ../lib/gm2/timestring.def ../lib/gm2/timestring.mod \
  437. ../lib/gm2/wrapclock.def ../lib/gm2/wrapclock.mod \
  438. ../lib/gm2/wraptime.def ../lib/gm2/wraptime.mod \
  439. ../lib/gm2/wrapc.def ../lib/gm2/wrapc.mod \
  440. showcase22.mod
  441. expect_run_files Library1 42 \
  442. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  443. ../lib/iso/convtypes.def ../lib/iso/convtypes.mod \
  444. ../lib/iso/ioconsts.def ../lib/iso/ioconsts.mod \
  445. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  446. ../lib/common/math.def ../lib/common/math.mod \
  447. ../lib/iso/sioresult.def ../lib/iso/sioresult.mod \
  448. ../lib/iso/TERMINATION.def ../lib/iso/TERMINATION.mod \
  449. ../lib/iso/wholestr.def ../lib/iso/wholestr.mod \
  450. ../lib/iso/realstr.def ../lib/iso/realstr.mod \
  451. ../lib/iso/longstr.def ../lib/iso/longstr.mod \
  452. ../lib/iso/longmath.def ../lib/iso/longmath.mod \
  453. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  454. ../lib/iso/longio.def ../lib/iso/longio.mod \
  455. ../lib/pim/strio.def ../lib/pim/strio.mod \
  456. ../lib/pim/inout.def ../lib/pim/inout.mod \
  457. ../lib/gm2/stdio.def ../lib/gm2/stdio.mod \
  458. ../lib/iso/stextio.def ../lib/iso/stextio.mod \
  459. ../lib/iso/swholeio.def ../lib/iso/swholeio.mod \
  460. ../lib/iso/srealio.def ../lib/iso/srealio.mod \
  461. library1.mod
  462. expect_run_files TDynStr 42 \
  463. ../lib/gm2/dynamicstrings.def ../lib/gm2/dynamicstrings.mod \
  464. ../lib/gm2/sysstorage.def ../lib/gm2/sysstorage.mod \
  465. t_dynstr.mod
  466. expect_run_files ClashProg 60 d_clash_a.def d_clash_a.mod d_clash_b.def d_clash_b.mod d_clash_prog.mod
  467. expect_run_files_out Hello 0 "Hello, Modula-2!" ../lib/common/sysio.def ../lib/common/sysio.mod hello.mod
  468. expect_run_files_out StringsProg 0 "Hello World" ../lib/common/sysio.def ../lib/common/sysio.mod ../lib/common/strings.def ../lib/common/strings.mod strings_prog.mod
  469. expect_run_files StringsSliceProg 255 ../lib/common/strings.def ../lib/common/strings.mod strings_slice_prog.mod
  470. expect_run_files_out Stdlib2Prog 42 "stdlib2 n=42" ../lib/common/sysio.def ../lib/common/sysio.mod ../lib/common/math.def ../lib/common/math.mod ../lib/common/strings.def ../lib/common/strings.mod ../lib/common/charclass.def ../lib/common/charclass.mod stdlib2_prog.mod
  471. expect_run_files MathProg 12 ../lib/common/sysio.def ../lib/common/sysio.mod ../lib/common/math.def ../lib/common/math.mod math_prog.mod
  472. expect_run_files Math2Prog 31 ../lib/common/math.def ../lib/common/math.mod math2_prog.mod
  473. expect_run_files SysClockProg 3 ../lib/iso/sysclock.def ../lib/iso/sysclock.mod sysclock_prog.mod
  474. expect_run_files Utf8Prog 127 ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod utf8_prog.mod
  475. expect_run_files ConvProg 127 ../lib/iso/conversions.def ../lib/iso/conversions.mod conv_prog.mod
  476. expect_run_files ConvResultsProg 127 ../lib/iso/conversions.def ../lib/iso/conversions.mod convresults_prog.mod
  477. expect_run_files TStrEq 15 t_streq.mod
  478. expect_run_files ProgArgsProg 7 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/programargs.def ../lib/iso/programargs.mod progargs_prog.mod
  479. expect_run_files_out UTextProg 42 "héllo" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../lib/iso/textio.def ../lib/iso/textio.mod utext_prog.mod
  480. expect_run_files_in() {
  481. # $1 prog, $2 exit code, $3 expected first line, $4 stdin, then files
  482. prog="$1"; want="$2"; wantline="$3"; input="$4"; shift 4
  483. if ! build_session "$prog" "$@"; then
  484. fail=$((fail+1)); echo "FAIL(session-in): $prog build failed"; return
  485. fi
  486. out=$(printf '%s\n' "$input" | timeout 10 "gen_ssa/$prog" 2>/dev/null); got=$?
  487. first=$(printf '%s\n' "$out" | head -n 1)
  488. if [ "$got" = "$want" ] && [ "$first" = "$wantline" ]; then
  489. pass=$((pass+1)); echo "PASS(session-in): $prog -> $got [$first]"
  490. else
  491. fail=$((fail+1)); echo "FAIL(session-in): $prog rc=$got line=[$first] want=[$wantline]"
  492. fi
  493. }
  494. expect_run_files_in ReadProg 0 "42" "20 22" ../lib/common/sysio.def ../lib/common/sysio.mod read_prog.mod
  495. expect_run_files_in WholeIOProg 0 "42" "6 7" ../lib/common/sysio.def ../lib/common/sysio.mod ../lib/iso/wholeio.def ../lib/iso/wholeio.mod wholeio_prog.mod
  496. expect_run_files_in RealProg 42 "3.500000E+00" "1.25" ../lib/iso/realio.def ../lib/iso/realio.mod ../lib/common/sysio.def ../lib/common/sysio.mod realio_prog.mod
  497. expect_run_files_in IOChanProg 0 "hello 42" "Z" ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod iochan_prog.mod
  498. rm -f gen_ssa/_iochan_tmp.txt
  499. expect_run_files IOChanFileProg 3 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/common/strings.def ../lib/common/strings.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod iochanfile_prog.mod
  500. rm -f gen_ssa/_iochan_tmp.txt
  501. rm -f gen_ssa/_iochanseek.txt
  502. expect_run_files IOChanSeekProg 15 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/common/strings.def ../lib/common/strings.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod iochanseek_prog.mod
  503. rm -f gen_ssa/_iochanseek.txt
  504. expect_run_files FilesProg 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod ../lib/iso/files.def ../lib/iso/files.mod files_prog.mod
  505. expect_run_files TBadFile 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod ../lib/iso/files.def ../lib/iso/files.mod t_badfile.mod
  506. rm -f gen_ssa/_files_tmp.txt
  507. expect_run_files_in Showcase11 80 "Modula-2" "42" \
  508. ../lib/common/sysio.def ../lib/common/sysio.mod \
  509. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  510. ../lib/iso/textio.def ../lib/iso/textio.mod \
  511. ../lib/iso/wholeio.def ../lib/iso/wholeio.mod \
  512. ../lib/common/strings.def ../lib/common/strings.mod \
  513. ../lib/common/math.def ../lib/common/math.mod \
  514. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod ../lib/iso/files.def ../lib/iso/files.mod \
  515. showcase11.mod
  516. rm -f gen_ssa/_showcase11.txt
  517. # step 8.2/8.3: const folding, forward types, trailing ';', empty
  518. # statements, 1-char strings, qualified type names.
  519. expect_run_files Showcase12 42 showcase12lib.def showcase12lib.mod showcase12.mod
  520. expect_run_files_out Showcase13 42 "Even(8)=T Odd(7)=T total=42" ../lib/common/sysio.def ../lib/common/sysio.mod showcase13.mod
  521. expect_run_files_out Showcase19 42 "showcase19 total=42" \
  522. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  523. ../lib/iso/textio.def ../lib/iso/textio.mod \
  524. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  525. showcase19.mod
  526. expect_run_files_out Showcase20 42 "showcase20 total=42" \
  527. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  528. ../lib/iso/textio.def ../lib/iso/textio.mod \
  529. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  530. showcase20.mod
  531. expect_run_files_out Showcase21 42 "showcase21 total=42" \
  532. ../lib/iso/convtypes.def ../lib/iso/convtypes.mod \
  533. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  534. ../lib/common/math.def ../lib/common/math.mod \
  535. ../lib/iso/wholestr.def ../lib/iso/wholestr.mod \
  536. ../lib/iso/realstr.def ../lib/iso/realstr.mod \
  537. ../lib/iso/longmath.def ../lib/iso/longmath.mod \
  538. ../lib/gm2/dynamicstrings.def ../lib/gm2/dynamicstrings.mod \
  539. ../lib/pim/strio.def ../lib/pim/strio.mod \
  540. showcase21.mod
  541. expect_run_files_out Showcase18 42 "showcase18 areas sum=139" \
  542. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  543. ../lib/iso/textio.def ../lib/iso/textio.mod \
  544. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  545. showcase18.mod
  546. expect_run_files_out Showcase17 42 "showcase17 total=42" \
  547. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  548. ../lib/iso/textio.def ../lib/iso/textio.mod \
  549. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  550. showcase17.mod
  551. rm -f gen_ssa/_showcase16.txt
  552. expect_run_files_out Showcase16 42 "showcase16: id=3 total=42" \
  553. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  554. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  555. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  556. ../lib/iso/files.def ../lib/iso/files.mod \
  557. ../lib/iso/textio.def ../lib/iso/textio.mod \
  558. ../lib/common/strings.def ../lib/common/strings.mod \
  559. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  560. showcase16.mod
  561. rm -f gen_ssa/_showcase16.txt
  562. rm -f gen_ssa/_showcase15.txt
  563. expect_run_files_out Showcase15 42 "read back: point 42" \
  564. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  565. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  566. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  567. ../lib/iso/textio.def ../lib/iso/textio.mod \
  568. ../lib/common/strings.def ../lib/common/strings.mod \
  569. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  570. showcase15lib.def showcase15lib.mod showcase15.mod
  571. rm -f gen_ssa/_showcase15.txt
  572. expect_run_files_out Showcase14 42 "showcase14 n=42" \
  573. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  574. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  575. ../lib/common/sysio.def ../lib/common/sysio.mod \
  576. ../lib/iso/textio.def ../lib/iso/textio.mod \
  577. ../lib/iso/conversions.def ../lib/iso/conversions.mod \
  578. ../lib/iso/realio.def ../lib/iso/realio.mod \
  579. ../lib/iso/programargs.def ../lib/iso/programargs.mod \
  580. ../lib/iso/iochan.def ../lib/iso/iochan.mod \
  581. showcase14.mod
  582. expect_run_files_out MixProg 0 "7" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../lib/iso/textio.def ../lib/iso/textio.mod ../lib/common/sysio.def ../lib/common/sysio.mod ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../lib/iso/iochan.def ../lib/iso/iochan.mod ../lib/iso/files.def ../lib/iso/files.mod d_mix_prog.mod
  583. rm -f gen_ssa/_mix.txt
  584. expect_fail_files() {
  585. # $1 = listing basename, $2 = message (may be empty), then files
  586. lst="$1"; want="$2"; shift 2
  587. files=""
  588. for f in "$@"; do files="$files tests/$f"; done
  589. if ./M2 $files 2>&1 | grep -q "Incorrect source"; then :; else
  590. fail=$((fail+1)); echo "FAIL(session-rej): $lst accepted"; return
  591. fi
  592. if [ -z "$want" ]; then
  593. pass=$((pass+1)); echo "PASS(session-rej): $lst"
  594. elif grep -q "$want" "tests/$lst.LST" 2>/dev/null; then
  595. pass=$((pass+1)); echo "PASS(session-rej): $lst [$want]"
  596. else
  597. fail=$((fail+1)); echo "FAIL(session-rej): [$want] not in tests/$lst.LST"
  598. fi
  599. }
  600. expect_fail_files d_badimp_prog "undeclared identifier" d_basic.def d_basic.mod d_badimp_prog.mod
  601. expect_fail_files sig "implementation does not match definition" sig.def sig.mod sig_prog.mod
  602. expect_fail_files g_badbuf "invalid call" g_buf.def g_buf.mod g_badbuf.def
  603. expect_fail_files g_realbox "invalid call" g_ordbox.def g_ordbox.mod g_realbox.def
  604. # --- two-phase parse gate. Deferral is now the DEFAULT (procedure
  605. # bodies are parsed after the unit's declarations); -notwophase
  606. # restores the old inline parse for debugging. Forward-free code
  607. # must be byte-identical either way; forward-reference code must
  608. # still work. ---
  609. twophase_same() {
  610. # $1 = test file (no dir): default (deferral) vs -notwophase inline
  611. name="$1"; mod=$(modof "$name")
  612. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.off.ssa"
  613. ./M2 -notwophase "tests/$name" >/dev/null 2>&1
  614. cp "gen_ssa/$mod.ssa" "gen_ssa/$mod.off.ssa"
  615. if ./M2 "tests/$name" 2>&1 | grep -q "twophase .*mismatch"; then
  616. fail=$((fail+1)); echo "FAIL(twophase): $name probe mismatch"; return
  617. fi
  618. if cmp -s "gen_ssa/$mod.off.ssa" "gen_ssa/$mod.ssa"; then
  619. pass=$((pass+1)); echo "PASS(twophase): $name identical"
  620. else
  621. fail=$((fail+1)); echo "FAIL(twophase): $name .ssa differs"
  622. fi
  623. rm -f "gen_ssa/$mod.off.ssa"
  624. }
  625. twophase_same t_nestedproc.mod
  626. twophase_same t_classmethod.mod
  627. # Forward references compile *differently* with deferral than with the
  628. # legacy FwdVar path (the deferral makes them ordinary, so the codegen is
  629. # the normal one) — that is the point. Gate them functionally: same exit
  630. # code, and the forward diagnostic still fires.
  631. twophase_run() {
  632. # $1 = test file, $2 = expected exit code
  633. name="$1"; want="$2"; mod=$(modof "$name")
  634. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod"
  635. if ./M2 "tests/$name" 2>&1 | grep -q "Parsed correctly"; then :; else
  636. fail=$((fail+1)); echo "FAIL(twophase-run): $name rejected"; return
  637. fi
  638. qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2>/dev/null || { fail=$((fail+1)); echo "FAIL(twophase-run): $name qbe"; return; }
  639. cc "gen_ssa/$mod.s" "$SHIM" -o "gen_ssa/$mod" 2>/dev/null || { fail=$((fail+1)); echo "FAIL(twophase-run): $name cc"; return; }
  640. timeout 10 "gen_ssa/$mod" >/dev/null 2>&1; got=$?
  641. if [ "$got" = "$want" ]; then pass=$((pass+1)); echo "PASS(twophase-run): $name -> $got"
  642. else fail=$((fail+1)); echo "FAIL(twophase-run): $name got $got want $want"; fi
  643. }
  644. twophase_fail() {
  645. # $1 = test file, $2 = message expected in the .LST
  646. name="$1"; want="$2"
  647. if ./M2 "tests/$name" 2>&1 | grep -q "Incorrect source"; then :; else
  648. fail=$((fail+1)); echo "FAIL(twophase-fail): $name accepted"; return
  649. fi
  650. if grep -q "$want" "tests/$(basename "$name" .mod).LST" 2>/dev/null; then
  651. pass=$((pass+1)); echo "PASS(twophase-fail): $name [$want]"
  652. else fail=$((fail+1)); echo "FAIL(twophase-fail): [$want] not found"; fi
  653. }
  654. twophase_fail t_fwdvar.mod "undeclared identifier"
  655. twophase_fail t_fwdsel.mod "undeclared identifier"
  656. twophase_fail t_fwdprop.mod "undeclared identifier"
  657. twophase_fail t_bad_fwd.mod "undeclared identifier"
  658. # --- separate compilation: compile one unit against .def interfaces,
  659. # link objects with cc; library objects must not define main. ---
  660. sep_compile() {
  661. # $1 = module name, $2 = target source, rest = interface files
  662. mod="$1"; target="$2"; shift 2
  663. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod.o"
  664. if ! ./M2 -c "$@" "$target" 2>&1 | grep -q "Parsed correctly"; then
  665. return 1
  666. fi
  667. [ -f "gen_ssa/$mod.ssa" ] || return 1
  668. qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2> "gen_ssa/$mod.qbeerr" || return 1
  669. cc -c "gen_ssa/$mod.s" -o "gen_ssa/$mod.o" 2> "gen_ssa/$mod.ccerr" || return 1
  670. return 0
  671. }
  672. expect_separate() {
  673. # $1 = program module, $2 = expected exit code, $3 = library module,
  674. # $4 = library def, $5 = library mod, $6 = program source
  675. prog="$1"; want="$2"; lib="$3"; ldef="$4"; lmod="$5"; psrc="$6"
  676. if ! sep_compile "$lib" "tests/$lmod" "tests/$ldef"; then
  677. fail=$((fail+1)); echo "FAIL(separate): $lib compile"; return
  678. fi
  679. if grep -q '\$main' "gen_ssa/$lib.ssa"; then
  680. fail=$((fail+1)); echo "FAIL(separate): $lib defines main"; return
  681. fi
  682. if ! sep_compile "$prog" "tests/$psrc" "tests/$ldef"; then
  683. fail=$((fail+1)); echo "FAIL(separate): $prog compile"; return
  684. fi
  685. if ! grep -q '\$main' "gen_ssa/$prog.ssa"; then
  686. fail=$((fail+1)); echo "FAIL(separate): $prog has no main"; return
  687. fi
  688. if ! cc "gen_ssa/$prog.o" "gen_ssa/$lib.o" "$SHIM" -o "gen_ssa/$prog" -lm 2> "gen_ssa/$prog.ccerr"; then
  689. fail=$((fail+1)); echo "FAIL(separate): $prog link"; cat "gen_ssa/$prog.ccerr"; return
  690. fi
  691. timeout 10 "gen_ssa/$prog" >/dev/null 2>&1; got=$?
  692. if [ "$got" = "$want" ]; then
  693. pass=$((pass+1)); echo "PASS(separate): $prog -> $got"
  694. else
  695. fail=$((fail+1)); echo "FAIL(separate): $prog got $got want $want"
  696. fi
  697. }
  698. expect_separate SepProg 42 SepLib sep_lib.def sep_lib.mod sep_prog.mod
  699. expect_separate SepEmptyProg 42 SepEmpty sep_empty.def sep_empty.mod sep_empty_prog.mod
  700. # M2 -c -I: resolve the target's own .def and imports from the include path.
  701. sep_compile_auto() {
  702. # $1 = module, $2 = source
  703. mod="$1"; target="$2"
  704. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod.o"
  705. ./M2 -c -I tests "tests/$target" 2>&1 | grep -q "Parsed correctly" || return 1
  706. [ -f "gen_ssa/$mod.ssa" ] || return 1
  707. qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2>/dev/null || return 1
  708. cc -c "gen_ssa/$mod.s" -o "gen_ssa/$mod.o" 2>/dev/null || return 1
  709. }
  710. expect_separate_auto() {
  711. # $1 = program module, $2 = expected exit code, $3 = library module,
  712. # $4 = library source, $5 = program source
  713. prog="$1"; want="$2"; lib="$3"; lsrc="$4"; psrc="$5"
  714. if ! sep_compile_auto "$lib" "$lsrc"; then
  715. fail=$((fail+1)); echo "FAIL(separate-I): $lib compile"; return
  716. fi
  717. if ! sep_compile_auto "$prog" "$psrc"; then
  718. fail=$((fail+1)); echo "FAIL(separate-I): $prog compile"; return
  719. fi
  720. if ! cc "gen_ssa/$prog.o" "gen_ssa/$lib.o" "$SHIM" -o "gen_ssa/$prog" -lm 2> "gen_ssa/$prog.ccerr"; then
  721. fail=$((fail+1)); echo "FAIL(separate-I): $prog link"; cat "gen_ssa/$prog.ccerr"; return
  722. fi
  723. timeout 10 "gen_ssa/$prog" >/dev/null 2>&1; got=$?
  724. if [ "$got" = "$want" ]; then
  725. pass=$((pass+1)); echo "PASS(separate-I): $prog -> $got"
  726. else
  727. fail=$((fail+1)); echo "FAIL(separate-I): $prog got $got want $want"
  728. fi
  729. }
  730. expect_separate_auto SepResProg 42 SepRes sepres.mod sepres_prog.mod
  731. expect_separate_auto CDefProg 8 CDef cdef.def cdef_prog.mod
  732. # --- M2 process exit codes: 0 = ok, 1 = compile errors, 2 = usage/IO ---
  733. check_exit() {
  734. # $1 = description, $2 = expected rc, rest = args
  735. desc="$1"; want="$2"; shift 2
  736. ./M2 "$@" >/dev/null 2>&1; got=$?
  737. if [ "$got" = "$want" ]; then pass=$((pass+1)); echo "PASS(exit): $desc -> $got"
  738. else fail=$((fail+1)); echo "FAIL(exit): $desc got $got want $want"; fi
  739. }
  740. check_exit "ok" 0 tests/t_minimal.mod
  741. check_exit "errors" 1 tests/t_bad_undecl.mod
  742. check_exit "no input" 2
  743. check_exit "missing file" 2 /tmp/opencode/_m2_no_such_file_.mod
  744. # --- step 7 gate: compiler sources free of gm2-only imports.
  745. # FileIO is the last module to port (see docs/summary_step7.md);
  746. # it is excluded here so the gate guards everything else. ---
  747. if grep -qE "(IMPORT|FROM)[[:space:]]+.*\b(Environment|FileSysOp|TextIO|RawIO|WholeIO|IOChan|ProgramArgs)\b" \
  748. src/SymTab.def src/SymTab.mod src/QbeGen.def src/QbeGen.mod \
  749. src/M2S.mod src/M2P.mod src/M2.mod src/*.frm 2>/dev/null; then
  750. fail=$((fail+1)); echo "FAIL(gate): gm2-only imports present"
  751. else
  752. pass=$((pass+1)); echo "PASS(gate): no gm2-only imports (FileIO port pending)"
  753. fi
  754. echo "--- $pass passed, $fail failed ---"
  755. [ "$fail" -eq 0 ]