Compiler.def 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. DEFINITION MODULE Compiler ;
  2. (* TP3 single-pass Pascal -> 8086 compiler, in GNU Modula-2 (-fiso).
  3. Mirrors the original Turbo Pascal 3.0 compiler (TPSRC6 'turbo' entry,
  4. TPSRC7-10): a one-pass parser that reads the shared TextBuf as source
  5. and emits 8086 machine code directly into an internal code buffer, a
  6. patch list resolving forward references, TP3-style error reporting
  7. (error number + relative text position) and code/data size accounting.
  8. The shell (CmdCompile) will call Compile, then jump the editor to
  9. errPos on failure - exactly like the original errexit + editor2 path. *)
  10. FROM SYSTEM IMPORT BYTE ;
  11. PROCEDURE Compile (VAR errNo, errPos : CARDINAL) : BOOLEAN ;
  12. (* Compile the current TextBuf as a Pascal program. Returns TRUE on
  13. success (sizes available via CodeBytes / DataBytes). On failure
  14. returns FALSE, errNo carries the TP3-style error number and errPos
  15. the relative source offset (0-based) for the editor. *)
  16. PROCEDURE SetSource (path : ARRAY OF CHAR) ;
  17. (* Name the file the current TextBuf was loaded from. Only its directory is
  18. used: a {$I file} directive resolves the name against the including file's
  19. directory, so the compiler has to know where that file came from. The
  20. loaders (Shell.LoadWorkFile, CompileTest/ComTest LoadFile) call this; an
  21. unset name means includes resolve against the current directory. *)
  22. PROCEDURE CodeBytes () : CARDINAL ;
  23. (* emitted code size in bytes *)
  24. PROCEDURE DataBytes () : CARDINAL ;
  25. (* emitted data size in bytes - the program's own data, not counting the
  26. runtime or the fixed 4 KiB gap between code and data *)
  27. PROCEDURE ImageBytes () : CARDINAL ;
  28. (* total linked image size = runtime + program. This is what a .COM writer
  29. must emit, padded on to DataBase + DataBytes by the linker. *)
  30. PROCEDURE DataBase () : CARDINAL ;
  31. (* image-absolute offset of the data area, rtSz + 1000H. The linker places
  32. the program's globals here and zero-fills the gap after the code. *)
  33. PROCEDURE ImageByteAt (i : CARDINAL) : BYTE ;
  34. (* i-th byte of the whole image, runtime included, 0 past the end. This is
  35. what a .COM would actually start with. *)
  36. PROCEDURE CodeByteAt (i : CARDINAL) : BYTE ;
  37. (* i-th byte of the emitted image (0 past the end), so tests can check the
  38. generated 8086 code itself and not only its size *)
  39. END Compiler.