aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md13
1 files changed, 7 insertions, 6 deletions
diff --git a/README.md b/README.md
index bf46a01..4537188 100644
--- a/README.md
+++ b/README.md
@@ -2,11 +2,11 @@
a small stack cpu began as a C89 code golf entry and became a self-hosting runtime. a native core runs vm code with an arm64 or x86-64 jit, through llvm on supported builds, or in the interpreter. the genome contains a compiler for zc, a C-like language with forth influences. the compiler resides in vm memory alongside the program; code can call its functions, modify its tables, add syntax, and compile new code at runtime. heap objects carry an ownership tag (u, m or d) checked by a static analyzer, with deterministic frees at scope ends and a mark-sweep collector underneath. types are a compiler primitive, with structs, generics, reflection and an optional typechecker. programs can install up to 512 custom opcodes (virtual enhancements), which the jits inline as native code. code marked `o3` bypasses the stack machine: the core compiles the region as a unit and keeps its variables in registers.
-this folder has the latest code. `docs/LEARN.md` is a tour of the language. `docs/history/` is the scrapbook: notes for every stage, plus frozen code from the stages that still have it, archived as `docs/history/code-snapshots.tar.gz`.
+this folder has the latest code. `docs/SPEC.md` is the language reference, and `docs/LEARN.md` is a tour of the language. `docs/history/` is the scrapbook: notes for every stage, plus frozen code from the stages that still have it, archived as `docs/history/code-snapshots.tar.gz`.
## files
-`src/core/core.c` is the native core. it contains the arm64 jit, the x86-64 jit, the llvm backend (behind `-DZYLLVM`), the portable interpreter, the enhancement unit (recipe parser, vm-code lifter, optimizer and lowering), and the o3 region compiler. `src/runtime/rt.zc` provides i/o, native division enhancements, the heap, and the collector; `src/compiler/compiler.zc` is the compiler. both are written in zc and begin with an overview. together they make up the genome. `src/tools/zc0.c` is stage 0 of the bootstrap, a c compiler for the subset of zc used by `src/compiler/compiler.zc`. `src/tools/build.zc` has the resident compiler compile its own source into a fresh image, and `src/tools/mkgenome.c` checks that image against the memory map before it becomes `build/core/genome.bin`. an image is a file of little-endian 64-bit words, and every core takes its genome in at compile time with c23 `#embed` (`src/core/genome.h`). `examples/` contains small programs (hello, factorial, echo, self-patching code, an owning list, a repl, a typed program, and an enhancement demo) and larger proofs of concept:
+`src/core/core.c` is the native core. it contains the arm64 jit, the x86-64 jit, the llvm backend (behind `-DZYLLVM`), the portable interpreter, the enhancement unit (recipe parser, vm-code lifter, optimizer and lowering), and the o3 region compiler. `src/runtime/rt.zc` provides i/o, native division enhancements, the heap, and the collector; the compiler is the files of `src/compiler/`, named in order by `src/compiler/parts` (the lexer, types, expressions, statements, analyzer, declarations, check mode and image building each have a file; `base.zc` begins with the overview). all are written in zc. together they make up the genome. `src/tools/zc0.c` is stage 0 of the bootstrap, a c compiler for the subset of zc used by the compiler. `src/tools/build.zc` has the resident compiler compile its own source into a fresh image, and `src/tools/mkgenome.c` checks that image against the memory map before it becomes `build/core/genome.bin`. an image is a file of little-endian 64-bit words, and every core takes its genome in at compile time with c23 `#embed` (`src/core/genome.h`). `examples/` contains small programs (hello, factorial, echo, self-patching code, an owning list, a repl, a typed program, and an enhancement demo) and larger proofs of concept:
- `mandel.zc`: the mandelbrot set in 16.16 fixed point, with the fixed-point multiply wired in as a custom opcode.
- `bf.zc`: a brainfuck compiler. it turns brainfuck into zc source, has the resident compiler compile it, and runs it (native code on the jit). it takes a program after a backtick, or runs hello world.
@@ -31,13 +31,14 @@ run these commands from the repository root. everything built or generated goes
make
build/bin/zy < examples/hello.zc
make test JOBS=4
+make parity
make genome
make web
make js
make run PROG=examples/hello.zc
```
-the cores embed their genome with c23 `#embed`, so the c compiler has to be clang 19 or gcc 15 or later. `src/tools/findcc.sh` finds one (`CC` set on the command line or in the environment is used as given, and must support it too). `make genome` bootstraps the compiler, compares two self-compiled images, and writes `build/core/genome.bin` only after they agree; `make` reruns it whenever a source of the genome changes, and the cores that embed it are rebuilt after it. `make check` runs the smaller suite while iterating. `ONBOARD.md` is a reading and verification order for getting to know the code.
+the cores embed their genome with c23 `#embed`, so the c compiler has to be clang 19 or gcc 15 or later. `src/tools/findcc.sh` finds one (`CC` set on the command line or in the environment is used as given, and must support it too). `make genome` bootstraps the compiler, compares two self-compiled images, and writes `build/core/genome.bin` only after they agree; `make` reruns it whenever a source of the genome changes, and the cores that embed it are rebuilt after it. `make check` runs the smaller suite while iterating. `make parity` (`src/tools/parity.sh`, `--help` for options) compiles the test and example programs with zc0 and with the self-hosted compiler and compares what they print, which the fixpoint check cannot see; programs zc0 rejects are skipped and counted, intended differences are listed in `tests/parity.known`, and work files go to `build/parity/`. `ONBOARD.md` is a reading and verification order for getting to know the code.
### command-line help
@@ -88,9 +89,9 @@ clang -O2 -fwrapv -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c s
### language server
-`src/lsp/server.zc` is a language server written in zc. it runs the compiler (`src/compiler/compiler.zc`) in check mode and provides a json-rpc protocol. diagnostics use the compiler's messages. parse words such as `immediate fn`, `run.add_binop` and `quote` execute during checks, so editor parsing and highlighting reflect syntax added by the program.
+`src/lsp/server.zc` is a language server written in zc. it runs the compiler (`src/compiler/`) in check mode and provides a json-rpc protocol. diagnostics use the compiler's messages. parse words such as `immediate fn`, `run.add_binop` and `quote` execute during checks, so editor parsing and highlighting reflect syntax added by the program.
-hover shows declaration signatures and documentation. a top-level function, global or struct shows its declaration line; a method or static function shows its indented declaration. comments directly above a declaration provide its documentation, and a declaration without comments still shows its signature. parameters show their declarations, while `let` locals show the compiler-assigned type. untyped locals, parameters and function returns show inferred types; the server obtains these by checking the document again with unresolved names open. it caches the result until the document changes, so the first hover after an edit may take longer. hovering an imported module name shows its module overview and include form; source libraries can provide the same overview in a comment after their namespace and include headers. embedded `core.zc` is provided alongside runtime, compiler and standard-library sources, so `core.syscall` and `rt.syscall` navigate to and reference their distinct declarations. keywords such as `static`, `micro` and `unchecked` show their form and meaning from one table in `src/lsp/server.zc`.
+hover shows declaration signatures and documentation. a top-level function, global or struct shows its declaration line; a method or static function shows its indented declaration. comments directly above a declaration provide its documentation, and a declaration without comments still shows its signature. parameters show their declarations, while `let` locals show the compiler-assigned type. untyped locals, parameters and function returns show inferred types; the server obtains these by checking the document again with unresolved names open. it caches the result until the document changes, so the first hover after an edit may take longer. hovering an imported module name shows its module overview and include form; source libraries can provide the same overview in a comment after their namespace and include headers. embedded `core.zc` is provided alongside runtime, compiler (its parts joined into the one document `tinyvm:/compiler.zc`) and standard-library sources, so `core.syscall` and `rt.syscall` navigate to and reference their distinct declarations. keywords such as `static`, `micro` and `unchecked` show their form and meaning from one table in `src/lsp/server.zc`.
check mode records errors instead of printing them and continues after an error, up to 20 diagnostics per document. each record contains a line and token offset; the server maps these to utf-16 ranges. check mode also reports non-error findings as hints.
@@ -515,7 +516,7 @@ tables: `run.add_binop("**", 11, "ipow c")` adds or replaces a binary operator w
## the bootstrap
-`src/tools/zc0.c` compiles the subset of zc used by `src/compiler/compiler.zc` (without the analyzer, types, quote, parse words, or block expressions, but with `enhance` and top-level `embed` declarations) into the first genome, `build/s0/genome.bin`. a core built around that image compiles `src/compiler/compiler.zc` again in the VM using the full compiler, analyzer, and native division code, and `mkgenome` accepts the result only if it is an image (a compiler that rejects its own source prints diagnostics instead, which `mkgenome` shows). a core built around the second image compiles the source a third time; the two self-compiled images must be identical, and the first becomes `build/core/genome.bin`. the test suite checks this fixpoint on the interpreter, microcore, jit and llvm backends when available. in the zc0 subset `u`, `m` and `d` are recast tags, not names. an image build (`build_image(org, dst)`) compiles with only the image's names, keywords, and built-in types visible, writes code for the requested address, and appends a symbol table containing its names and enhancements. an image build (`build_image(org, dst)`) compiles with only the image's names, keywords, and built-in types visible, writes code for the requested address, and appends a symbol table containing its names and enhancements.
+`src/tools/zc0.c` compiles the subset of zc used by the compiler, the files of `src/compiler/parts` read as one stream (without the analyzer, types, quote, parse words, or block expressions, but with `enhance` and top-level `embed` declarations) into the first genome, `build/s0/genome.bin`. a core built around that image compiles the compiler again in the VM using the full compiler, analyzer, and native division code, and `mkgenome` accepts the result only if it is an image (a compiler that rejects its own source prints diagnostics instead, which `mkgenome` shows). a core built around the second image compiles the source a third time; the two self-compiled images must be identical, and the first becomes `build/core/genome.bin`. the test suite checks this fixpoint on the interpreter, microcore, jit and llvm backends when available. zc0 reads `u`, `m` and `d` as ordinary names too: `u*x` with the star touching the letter is a recast (no code), `u * x` is a product, and `.u`, `.m` and `.d` tags are read and ignored. it packs `b"..."` byte strings like the compiler and tracks `bstr` locals, globals, parameters and returns, and `embed` declarations (arrays only at the top level). an image build (`build_image(org, dst)`) compiles with only the image's names, keywords, and built-in types visible, writes code for the requested address, and appends a symbol table containing its names and enhancements.
## the instruction set