Please note: the compiler is currently undergoing a complete rewrite. Earlier versions can be found in the bak* directories.
More details will be added as the new version of the compiler is fleshed out.
Extremely minimal version of a 64bit forth-like compiler that aims to:
- Be completely stand alone (nostdlib)
- Works on byte code (no textual parsing)
- Supports compile time execution of any previously defined code
- Supports multiple os/architectures/executable formats
- Quickly be bootstrapped to higher level languages
version numbers are not exact requirements, just what i am using at time of writing
- linux 6.12.7_1 x86_64
- fasm 1.73.30
- xxd 2024-09-15
- grep 3.11
- cmp 3.10
vm works on byte code, multi-byte values are assumed to be little-endian. op codes are subject to change.
Op Code | Reads | Stack Effect | Description |
---|---|---|---|
00 | byte | ( -- b ) | read byte from input, push on the data stack |
01 | word | ( -- w ) | read word from input, push on the data stack |
02 | dword | ( -- d ) | read dword from input, push on the data stack |
03 | qword | ( -- q ) | read qword from input, push on the data stack |
04 | ( -- a ) | push addr of code buffer's here on the data stack | |
05 | ( a -- ) | set addr of code buffer's here | |
06 | ( a b -- a' ) | write byte to addr, push new addr on the data stack | |
07 | ( a w -- a' ) | write word to addr, push new addr on the data stack | |
08 | ( a d -- a' ) | write dword to addr, push new addr on the data stack | |
09 | ( a q -- a' ) | write qword to addr, push new addr on the data stack | |
0A | ( -- a ) | push addr of code buffer start on the data stack | |
0B | ( n1 n2 -- n ) | n1 - n2, push result on the data stack | |
0C | ( n1 n2 -- n ) | n1 + n2, push result on the data stack | |
0D | ( x -- ) | drop top of the data stack | |
0E | ( a b -- b a ) | swap the top two items of the data stack |
Stage 0
A binary file ending in bs0
is a stage 0 file that contains a run of bytes that are executed by the blue
compiler.
Stage 1
A textual file ending in bs1
that allows minimal formatting/commenting. Line comments start with #
. A stage 1
file is lowered to a stage 0 file by stripping comments and running it through xxd
.
- mmap stdin into input buffer like s120.asm
- provide syscalls in x86_64/linux/syscall.bs1
- instead of dumping the whole code buffer, have app write output giving start/end
- calculate string location/length in hello world example
- add code_buffer_start that can be different from code_buffer
- elf pre/post needs to be combined and moved to compiled words that can be called by the app
- add = op
- add over op
- add op to enter compile mode
- add op to enter interpret mode
- add op to call bytecode at location
- add assert op (in block)
- add tuck (swap over in block)
- add stack over/underflow error checks
- add code buffer over/underflow error checks
- add opcode overflow error check
- need a bs1/bs0 test case file to test blue
This will be a program written in bs1 that converts bs1 files to bs0 files. It will replace the current use of grep/xxd in build.sh. It will still be built initially with grep/xxd, then it will rebuild itself.
The program will be minimalist and require valid input else invalid output. Simplicity of this implementation is more important than performance. Likely once a higher level language is implemented it will re-implement s120 with more nice things.
Needs:
- Port s120.asm to bs1