build.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # Build the Pascal-S syntax validator from pascals.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/pascals.atg" "$B/"
  16. cp "$M2LIB/FileIO.def" "$M2LIB/FileIO.mod" "$B/"
  17. cd "$B"
  18. echo "=== CR ==="; CRFRAMES="$FRAMES" "$CR" -m -C pascals.atg
  19. echo "=== check: no degenerate code ==="
  20. if grep -q "IF FALSE\|WHILE FALSE" PascalSP.mod; then echo "DEGENERATE GENERATION (IF/WHILE FALSE)"; exit 1; fi
  21. echo "=== patch: EOF check ==="
  22. python3 - "$B" <<'PYEOF'
  23. import sys
  24. b = sys.argv[1]
  25. s = open(b + '/PascalSP.mod').read()
  26. old = ' PascalSS.Reset; Get;\n PascalS;\n\n END Parse;'
  27. assert old in s, 'EOF patch pattern missing'
  28. s = s.replace(old, ' PascalSS.Reset; Get;\n IF sym # 0 THEN PascalS END;\n IF sym # 0 THEN SynError(0) END;\n\n END Parse;')
  29. open(b + '/PascalSP.mod', 'w').write(s)
  30. print('patched')
  31. PYEOF
  32. echo "=== compile ==="
  33. for m in FileIO PascalSS PascalSP PascalS; do "$GM2" -fiso -I . -c "$m.mod"; done
  34. echo "=== link ==="
  35. # NOTE: the gen step exits 1 on pre-existing errors in gm2's own
  36. # ISO library .defs, but still writes a usable modules.lst.
  37. "$GM2" -fiso -I . -fgen-module-list=modules.lst -o /dev/null FileIO.o PascalSS.o PascalSP.o PascalS.mod || true
  38. "$GM2" -fiso -I . -fuse-list=modules.lst -o PascalS FileIO.o PascalSS.o PascalSP.o PascalS.mod
  39. echo "=== smoke ==="
  40. printf 'program hello (input, output);\nbegin\n writeln('"'"'hi'"'"');\nend.\n' > Hello.pas
  41. ./PascalS Hello.pas
  42. printf 'program t (input, output);\nbegin\nend. GARBAGE\n' > Garbage.pas
  43. if ./PascalS Garbage.pas 2>&1 | grep -q "Incorrect"; then echo "trailing-garbage rejected"; else echo "EOF CHECK FAILED"; exit 1; fi
  44. ./PascalS "$HERE/tests/deep.pas"
  45. rm -f Hello.pas Hello.LST Garbage.pas Garbage.LST "$HERE/tests/deep.LST"