build.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Build the P6 Pascal syntax validator from p6_pascal.atg.
  3. # Needs: CR (Coco/R V1.53), gm2 -fiso, parser/scanner frames, FileIO.
  4. # Note: link via the two-step module list; a single-step link trips
  5. # over pre-existing errors in this gm2 build's own ISO library .defs.
  6. set -e
  7. CR="${CR:-/home/eric/Projets/Projets-Modula2/MyWork/CocoGm2/CR}"
  8. GM2="${GM2:-/home/eric/bin/Modula2/Gm2/bin/gm2}"
  9. FRAMES="${CRFRAMES:-/home/eric/Projets/Projets-Modula2/MyWork/Theia/GNU-grammar/build}"
  10. M2LIB="${M2LIB:-/home/eric/Projets/Projets-Modula2/MyWork/Theia/GNU-grammar/build}"
  11. HERE="$(cd "$(dirname "$0")" && pwd)"
  12. B="$HERE/build"
  13. rm -rf "$B"
  14. mkdir -p "$B"
  15. cp "$HERE/p6_pascal.atg" "$B/"
  16. cp "$M2LIB/FileIO.def" "$M2LIB/FileIO.mod" "$B/"
  17. cd "$B"
  18. echo "=== CR ==="; CRFRAMES="$FRAMES" "$CR" -m -C p6_pascal.atg
  19. echo "=== patch: EOF check ==="
  20. python3 - <<'EOF'
  21. s = open('P6P.mod').read()
  22. old = ''' P6S.Reset; Get;
  23. P6;
  24. END Parse;'''
  25. assert old in s, 'EOF patch pattern missing'
  26. s = s.replace(old, ''' P6S.Reset; Get;
  27. P6;
  28. IF sym # 0 THEN SynError(0) END;
  29. END Parse;''')
  30. open('P6P.mod', 'w').write(s)
  31. print('patched')
  32. EOF
  33. echo "=== check: no degenerate code ==="
  34. if grep -q "IF FALSE\|WHILE FALSE" P6P.mod; then echo "DEGENERATE GENERATION (IF/WHILE FALSE)"; exit 1; fi
  35. echo "=== compile ==="
  36. for m in FileIO P6S P6P P6; do "$GM2" -fiso -I . -c "$m.mod"; done
  37. echo "=== link ==="
  38. # NOTE: the gen step exits 1 on pre-existing errors in gm2's own
  39. # ISO library .defs, but still writes a usable modules.lst.
  40. "$GM2" -fiso -I . -fgen-module-list=modules.lst -o /dev/null FileIO.o P6S.o P6P.o P6.mod || true
  41. "$GM2" -fiso -I . -fuse-list=modules.lst -o P6 FileIO.o P6S.o P6P.o P6.mod
  42. echo "=== smoke ==="
  43. printf 'PROGRAM Hello;\nBEGIN\n WriteLn('"'"'hi'"'"');\nEND.\n' > Hello.pas
  44. ./P6 Hello.pas
  45. printf 'PROGRAM T;\nBEGIN\nEND. GARBAGE\n' > Garbage.pas
  46. if ./P6 Garbage.pas 2>&1 | grep -q "Incorrect"; then echo "trailing-garbage rejected"; else echo "EOF CHECK FAILED"; exit 1; fi
  47. ./P6 "$HERE/tests/deep.pas"
  48. rm -f Hello.pas Hello.LST Garbage.pas Garbage.LST "$HERE/tests/deep.LST"