From 44405d9a7dc9a98a4a9e41b88194d51870b2dd7c Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 10 Oct 2026 04:29:15 +0000 Subject: [PATCH] Stage 1 done: tick the plan, record the lines The report's library table gains Sys, and three long lines wrap. --- diff --git a/PLAN.md b/PLAN.md index abdbe87..6c82268 100644 --- a/PLAN.md +++ b/PLAN.md @@ -3,7 +3,7 @@ jed (Polish *jeden*, one) is a small systems language in Wirth's tradition: full control of memory, volatile access, atomics, calls into C, generic modules. Its compiler is meant to be read in a long weekend: -about 4,550 lines of Free Pascal, one pass, no IR, no optimizer, writing +under 5,000 lines of Free Pascal, one pass, no IR, no optimizer, writing x86-64 machine code and the ELF file itself. The language is defined by `doc/jed.md`. Where this plan and the report @@ -53,17 +53,20 @@ is a library. ## The compiler, in reading order + +Lines after stage 1, all of them and those of code (neither blank nor +only comment), as `make loc` counts them: -| File | Lines | What | -|---|---|---| -| `src/scan.pas` | ~430 | Symbols, literals, comments, error messages | -| `src/sym.pas` | ~450 | Types, objects, scopes, layout | -| `src/x64.pas` | ~400 | Code buffer, chunks, fixups, instruction encoder | -| `src/gen.pas` | ~660 | Items: loading, storing, copying, frames, calls | -| `src/parse.pas` | ~1,900 | Declarations, statements, expressions, built-ins | -| `src/link.pas` | ~200 | Tree shaking, layout, patching | -| `src/elf.pas` | ~450 | Static and dynamic ELF, symbol table | -| `src/jed.pas` | ~115 | The command line | +| File | Lines | Code | What | +|---|---|---|---| +| `src/scan.pas` | 548 | 471 | Symbols, literals, comments, error messages | +| `src/sym.pas` | 452 | 380 | Types, objects, scopes, layout | +| `src/x64.pas` | 613 | 491 | Code buffer, chunks, fixups, instruction encoder | +| `src/gen.pas` | 1,177 | 1,035 | Items: loading, storing, copying, frames, calls | +| `src/parse.pas` | 1,370 | 1,265 | Declarations, statements, expressions, built-ins | +| `src/link.pas` | 123 | 92 | Tree shaking, layout, patching | +| `src/elf.pas` | 185 | 147 | Static ELF, symbol table | +| `src/jed.pas` | 113 | 85 | The command line, the entry point | ## Steps @@ -71,17 +74,17 @@ - [x] 1. Language report, `doc/jed.md`. Reviewed and approved before any more code. -- [ ] 2. Scanner and symbol table, `scan.pas` and `sym.pas`, written +- [x] 2. Scanner and symbol table, `scan.pas` and `sym.pas`, written against the report; they compile. -- [ ] 3. Machine code, `x64.pas`. -- [ ] 4. Linking and output, `link.pas` and `elf.pas`: tree shaking, +- [x] 3. Machine code, `x64.pas`. +- [x] 4. Linking and output, `link.pas` and `elf.pas`: tree shaking, static ELF, symbol table. A hand built chunk runs. -- [ ] 5. Parser and code generator, `gen.pas` and `parse.pas`: +- [x] 5. Parser and code generator, `gen.pas` and `parse.pas`: everything in the report except multiple results, errors, enumerations and sets, record literals, `defer`, `NEW`, generic modules and `extern`. Module bodies, per-target modules and their interface check, and code procedures are in. -- [ ] 6. `lib/Rt.jed`, `lib/Sys.linux-x86_64.jed`, `lib/Out.jed`; +- [x] 6. `lib/Rt.jed`, `lib/Sys.linux-x86_64.jed`, `lib/Out.jed`; examples (hello, args, variants and slices, volatile, a code procedure); `make check` runs them against expected output; `make bench` times the compiler on generated jed. diff --git a/doc/jed.md b/doc/jed.md index 12580ba..c68b0d9 100644 --- a/doc/jed.md +++ b/doc/jed.md @@ -37,8 +37,8 @@ comments is ASCII. Spaces, tabs and line breaks separate symbols and are otherwise ignored. -**Identifiers** are an ASCII letter or `_` followed by letters, digits and `_`, -up to 63 characters. Case matters: `count` and `Count` are different +**Identifiers** are an ASCII letter or `_` followed by letters, digits +and `_`, up to 63 characters. Case matters: `count` and `Count` are different names. **Reserved words** are lowercase, except `VOLATILE`: @@ -590,8 +590,8 @@ field or element of it. Each read or write of a volatile variable of a basic, enumeration, set or pointer type is exactly one memory access, of exactly its size, and volatile accesses happen in the order the -program writes them. Copying a whole record or array through a volatile pointer is -not allowed, since it can't be one access. +program writes them. Copying a whole record or array through a +volatile pointer is not allowed, since it can't be one access. A `^VOLATILE T` doesn't convert to `^T` without a written conversion. @@ -723,8 +723,8 @@ and indexing arrays and slices is checked, so a program's behaviour is defined by this report, with one exception: memory reached through a pointer. Dereferencing a stale or made-up pointer, indexing through a -pointer, a code procedure that breaks its rules, and C code can read or write any -memory, and what follows isn't defined. Dereferencing `nil`, dividing +pointer, a code procedure that breaks its rules, and C code can read or +write any memory, and what follows isn't defined. Dereferencing `nil`, dividing by zero and calling a `nil` procedure stop the program with a signal. ## 11. The library @@ -734,6 +734,7 @@ | Module | What | |---|---| | `Rt` | what the compiler's checks call when they fail, and string comparison | +| `Sys` | system calls: `write`, `exit`; one file per target | | `Out` | writing text and numbers to standard output | | `Mem` | `mmap`, and `Allocator`, the interface of every allocator | | `Heap` | a general allocator |