Skip to content

Commit

Permalink
Add compiler written in Déjà Vu
Browse files Browse the repository at this point in the history
This will in time be used to load every module (including the main
file), making dvc obsolete for anything but compiling the compiler.
  • Loading branch information
gvx committed Oct 7, 2013
1 parent 3e81e9e commit c044f57
Show file tree
Hide file tree
Showing 6 changed files with 780 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
*.o
vm/std.c
vm/std.vu
vm/compiler.c
vm/compiler.vu
vm/vu
vm/vu-dbg
22 changes: 22 additions & 0 deletions gencompilerc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with open('compiler.c', 'w') as f:
f.write('''#include "compiler.h"
/* This file is generated by gencompilerc.py.
* Do not edit by hand.
* Also, this file is automatically updated
* by make when the project is built.
*/
V load_compiler(V global)
{
char compiler[] = {''')
with open('compiler.vu', 'rb') as std:
for n, char in enumerate(std.read()):
if n % 8 == 0:
f.write("\n ")
f.write(r"'\x%02x', " % ord(char))
f.write('''
};
return load_memfile(compiler, sizeof compiler, a_to_string("(compiler)"), global);
}
''')
8 changes: 7 additions & 1 deletion vm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ debug: vu-dbg
clean:
rm *.o

CFILES := $(wildcard *.c) $(shell if [ ! -e "std.c" ]; then echo "std.c"; fi)
CFILES := $(wildcard *.c) $(shell if [ ! -e "std.c" ]; then echo "std.c"; fi) $(shell if [ ! -e "compiler.c" ]; then echo "compiler.c"; fi)
OFILES = $(patsubst %.c, %.o, $(CFILES))
ODBGFILES = $(patsubst %.c, %.dbg.o, $(CFILES))
CFLAGS = -Wall -falign-functions=4
Expand Down Expand Up @@ -47,3 +47,9 @@ std.vu: std.dva

std.c: std.vu
python ../genstdc.py

compiler.vu: compiler.deja
python ../dvc.py $^ > $@

compiler.c: compiler.vu
python ../gencompilerc.py
Loading

0 comments on commit c044f57

Please sign in to comment.