From 3e74914bd8bddc1fe9cf9fbca2a1bc2e842048a5 Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Mon, 5 Apr 2021 14:51:58 +0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + Makefile | 19 +++++++++++++++++++ doc/binfmt.txt | 37 +++++++++++++++++++++++++++++++++++++ doc/bytecode.txt | 3 +++ src/main.c | 5 +++++ 5 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 doc/binfmt.txt create mode 100644 doc/bytecode.txt create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2b4e9f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +O=build +SRCS=$(shell find src -name "*.c" -type f) +OBJS=$(SRCS:src/%.c=$(O)/%.o) +SRC_DIRS=$(shell find src -type d) +DIRS=$(SRC_DIRS:src/%=$(O)/%) $(O) + +all: $(DIRS) $(O)/lisp2 + +clean: + rm -rf $(O) + +$(DIRS): + mkdir -p $@ + +$(O)/lisp2: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(O)/%.o: src/%.c + $(CC) -c $(CFLAGS) -o $@ $< diff --git a/doc/binfmt.txt b/doc/binfmt.txt new file mode 100644 index 0000000..b46beb5 --- /dev/null +++ b/doc/binfmt.txt @@ -0,0 +1,37 @@ +0. File header +... + +1. Library linkage section: +Library entry: +| Offset | Field | Description | +|--------+-------------+-------------------------------------| +| 0x00 | lib_type | 0 - VM library | +| | | 1 - Native library | +| 0x01 | lib_namelen | Library name length | +| 0x02 | lib_name[] | lib_namelen bytes, teminated by NUL | +|--------+-------------+-------------------------------------| + +2. External reference section: +Entry: +| Offset | Field | Description | +|--------+-------------+---------------------------------------------------------| +| 0x00 | ref_type | 0 - Object symbol | +| | | 1 - Bytecode function | +| | | 2 - Native function | +| 0x01 | ref_flags | | +| 0x02 | ref_library | Source library | +| 0x03 | ref_namelen | Length of external symbol name | +| 0x04 | ref_address | For native functions: effective call address | +| | | For VM objects/funcs: entry index in respective section | +| 0x0C | ref_name[] | Native function symbol name | +|--------+-------------+---------------------------------------------------------| + +3. Functions section: +Function entry: +| Offset | Field | Description | +|--------+-----------+-------------------------------------------------------| +| 0x00 | fn_argc | Argument count, 255 means function accepts any number | +| 0x01 | fn_flags | | +| 0x02 | fn_size | Function bytecode size | +| 0x04 | fn_data[] | Binary code chunk of fn_size bytes | +|--------+-----------+-------------------------------------------------------| diff --git a/doc/bytecode.txt b/doc/bytecode.txt new file mode 100644 index 0000000..26b1267 --- /dev/null +++ b/doc/bytecode.txt @@ -0,0 +1,3 @@ +Each instruction is 4 bytes + +... TBD ... diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..e6173ef --- /dev/null +++ b/src/main.c @@ -0,0 +1,5 @@ +#include + +int main(int argc, char **argv) { + return 0; +}