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