|
@@ -0,0 +1,67 @@
|
|
|
|
|
+# Compiler module (`COMPILER.DEF/MOD`, `compiler.txt` 1350 lines)
|
|
|
|
|
+
|
|
|
|
|
+Core idea: `Compiler` owns the **symbol descriptor** and the
|
|
|
|
|
+predefined environment. Everything else (`Scanner/SymTab/Express/...`)
|
|
|
|
|
+allocates and links these nodes.
|
|
|
|
|
+
|
|
|
|
|
+## `Record / RecordPtr / ArrayPtr`
|
|
|
|
|
+
|
|
|
|
|
+```modula2
|
|
|
|
|
+RecordPtr = POINTER TO Record;
|
|
|
|
|
+Record = RECORD
|
|
|
|
|
+ word0: RecordPtr; (* scope chain link / backlink *)
|
|
|
|
|
+ word1: RecordPtr; (* name string *)
|
|
|
|
|
+ word2: RecordPtr; (* type / return type *)
|
|
|
|
|
+ word3: BITSET; (* kind: 64 const/type, 192 proc, 256 indexed var, 1089 module *)
|
|
|
|
|
+ word4: CARDINAL; (* node class 0..11, module class 6 *)
|
|
|
|
|
+ word5: WORD; (* const value / stdproc no. / elem type *)
|
|
|
|
|
+ high: WORD; (* max / param list / scope list *)
|
|
|
|
|
+END;
|
|
|
|
|
+ArrayPtr = POINTER TO ARRAY [0..5] OF WORD; (* param lists *)
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`PROC15(cnt,ret,first)` builds `p^[0]=cnt, p^[1]=ret, p^[2]=first`
|
|
|
|
|
+into `global35` (last list); caller patches `global35^[3..5]`.
|
|
|
|
|
+
|
|
|
|
|
+## Globals (proposed names)
|
|
|
|
|
+
|
|
|
|
|
+| old | proposed | role |
|
|
|
|
|
+|---|---|---|
|
|
|
|
|
+| global2 | `rangeCheckOpt` | `2 IN Scanner.global2` |
|
|
|
|
|
+| global3/4 | `curScopeAnchor/outerScope` | scope list heads |
|
|
|
|
|
+| global5 | `keywordHashTab` | `PROC13` table (730,731,1245,...) |
|
|
|
|
|
+| IntType/CardType/AddressType/RealType | same | `PROC9/PROC14` |
|
|
|
|
|
+| LongintType/LongrealType/CharType/BooleanType/BitsetType/ProcType | same | — |
|
|
|
|
|
+| WordType/ByteType/global17 | same / `addrAlias` | `BYTE^.word2:=WORD` |
|
|
|
|
|
+| global20/21 | `systemMod/storageMod` | module descriptors (`word4=6,word3=1089`) |
|
|
|
|
|
+| global22 | `allocSig` | `PROC15(2,2,CARD)+ADDRESS` |
|
|
|
|
|
+| global23/24 | `systemScope/storageScope` | `word0=global4,word1=list` |
|
|
|
|
|
+| global25/26 | `genZ80Requested/inCompile` | `FALSE/TRUE` init in `PROC1` |
|
|
|
|
|
+| global27-30 | (reserved Pass1/Stmt/Expr temps) | — |
|
|
|
|
|
+| global31/32/33 | `curScope/saveScope/baseScope` | insertion head |
|
|
|
|
|
+| global34 | `bitsetRange` | `PROC8(1,1),word2=CARD,high=15` |
|
|
|
|
|
+| global35 | `lastParamList` | see `PROC15` |
|
|
|
|
|
+| global12 | `charElemDesc` | `PROC8(0,11),word5=CHAR` |
|
|
|
|
|
+
|
|
|
|
|
+## Procedures (proposed names)
|
|
|
|
|
+
|
|
|
|
|
+| old | proposed | behaviour |
|
|
|
|
|
+|---|---|---|
|
|
|
|
|
+| PROC3 | `InsertIdent` | `Scanner.proc15+proc16`, chain on `global31` |
|
|
|
|
|
+| PROC4 | `DeclConst` | `TRUE/FALSE/NIL, IORESULT/HLRESULT, ...` |
|
|
|
|
|
+| PROC5 | `DeclStdProc` | `CAP/HALT/TRUNC/BREAK/TRANSFER/...` |
|
|
|
|
|
+| PROC6 | `DeclProc` | `READ/WRITE/NEW/DISPOSE/INC/DEC/INCL/EXCL/CODE`, `word3:=192` |
|
|
|
|
|
+| PROC7 | `DeclFunc` | `CARD/INT/LONG/FLOAT/ABS/.../ADR/TSIZE` + return type |
|
|
|
|
|
+| PROC8 | `NewTypeDesc` | `Scanner.proc14` + `word3:=size` |
|
|
|
|
|
+| PROC9 | `DeclType` | `INTEGER/CHAR/BOOLEAN/CARD/REAL/LONGREAL/BITSET/PROC/...`, double-linked |
|
|
|
|
|
+| PROC10/11 | `InitOperators` | fills `ERRORS.global3` (`:=`, `..`, `<=`, `>=`, `<>`, `(.`, `.)`, `(:`, `:)` ) |
|
|
|
|
|
+| PROC12 | `InitCharClass` | `A-Z->10, 0-9->11, ...` into `Scanner.global24` |
|
|
|
|
|
+| PROC13 | `InitKeywords` | 30 hash codes into `global5` |
|
|
|
|
|
+| PROC14 | `DeclarePredefTypes` | all base types + `PROCESS`, saves `global32/33` |
|
|
|
|
|
+| PROC15 | `MakeParamList` | see above |
|
|
|
|
|
+| PROC16 | `DeclareStdNames` | `TRUE/FALSE/NIL` + std procs/funcs + `global4` scope |
|
|
|
|
|
+| PROC17 | `DeclareSYSTEM` | `IORESULT/HLRESULT`, `CODE/ADR/TSIZE/.../BDOS/BIOS/MOVE/FILL/INP/OUT`, builds `global20/23` |
|
|
|
|
|
+| PROC18 | `DeclareSTORAGE` | `ALLOCATE/DEALLOCATE/MARK/RELEASE/FREEMEM`, builds `global21/24` |
|
|
|
|
|
+| PROC1 | `InitCompiler` | `PROC10/12/13/14/16/17/18`, `%L` option, `FREEMEM` print, `SymTab` allocs |
|
|
|
|
|
+| GETINP | `OpenSourceOutput` | `Files.Open(inName)`, `RedirectOutput`, `@@@` output, `BDOS 29`, `UseError` handler |
|
|
|
|
|
+| proc19-28 | imported | actually `Scanner.proc7/14/15/16/17/25/28`, `SymTab`, `Texts` — not real `Compiler` procs; the `COMPILER.DEF` `proc1..28` list is an obfuscated stub |
|