working on it

This commit is contained in:
Dawid Sobczak 2025-04-05 10:55:40 +01:00
parent 56a6e78765
commit 35a88970c2
1094 changed files with 51093 additions and 51 deletions

View file

@ -7,23 +7,30 @@ CFLAGS= -I $(MUSLINST)/include -I $(LUAINST)/include -I deps/lpeglabel
SRCS = $(sort $(wildcard **/*.c))
OBJS = $(SRCS:.c=.o)
all: zsh
all: test.out #zsh
deps/lua-bootstrap/lib/liblua.a:
$(MAKE) -j8 -C deps/lua-5.4.6
$(MAKE) -C deps/lua-5.4.6 install
test.out: test.s.o test.c.o
$(TCC) -static -nostdlib -B ../tcc-boostrap -I ../musl-bootstrap/include ../musl-bootstrap/lib/*.[oa] test.s.o test.c.o -o test.out
test.s.o: $(TCC0) test.s
$(TCC) -static -nostdlib -B ../tcc-boostrap -I ../musl-bootstrap/include ../musl-bootstrap/lib/*.[oa] -c test.s -o test.s.o
test.c.o: $(TCC0) test.c
$(TCC) -static -nostdlib -B ../tcc-boostrap -I ../musl-bootstrap/include ../musl-bootstrap/lib/*.[oa] -c test.c -o test.c.o
deps/lpeglabel/lpeglabel.a: deps/lua-bootstrap/lib/liblua.a
$(MAKE) -C deps/lpeglabel
# deps/lua-bootstrap/lib/liblua.a:
# $(MAKE) -j8 -C deps/lua-5.4.6
# $(MAKE) -C deps/lua-5.4.6 install
%.o: %.c deps/lua-bootstrap/lib/liblua.a
$(CC) $(CFLAGS) -c -o $@ $<
# deps/lpeglabel/lpeglabel.a: deps/lua-bootstrap/lib/liblua.a
# $(MAKE) -C deps/lpeglabel
zsh: $(OBJS) deps/lua-bootstrap/lib/liblua.a deps/lpeglabel/lpeglabel.a
$(CC) -nostdlib -B $(TCCINST) -o zsh $(OBJS) deps/lpeglabel/lpeglabel.a $(LUAINST)/lib/liblua.a $(MUSLINST)/lib/*.[oa]
# %.o: %.c deps/lua-bootstrap/lib/liblua.a
# $(CC) $(CFLAGS) -c -o $@ $<
run: zsh
./zsh
# zsh: $(OBJS) deps/lua-bootstrap/lib/liblua.a deps/lpeglabel/lpeglabel.a
# $(CC) -nostdlib -B $(TCCINST) -o zsh $(OBJS) deps/lpeglabel/lpeglabel.a $(LUAINST)/lib/liblua.a $(MUSLINST)/lib/*.[oa]
# run: zsh
# ./zsh
c:
rm -f zsh

View file

@ -1,32 +1,32 @@
util = require('src.util')
local function parse_tree_to_ast(parsetree)
stack = {{i=1,node=parsetree}};
local stack = {{i=1,node=parsetree}};
while #stack > 0 do
current = table.remove(stack, 1)
while #stack > 0 do
local current = table.remove(stack, 1)
for i = current.i, #current.node, 1 do
inner = current.node[i]
local inner = current.node[i]
if type(inner) == "table" then
current.i = i + 1;
print(current.node.rule)
table.insert(stack, current)
table.insert(stack, {i=1, node=inner})
break;
else
print(inner)
print(string.rep(" ", #stack) .. inner)
end
end
end
end
return {}
end
local function print_ast(ast)
end
return {
parse_tree_to_ast = parse_tree_to_ast,
print = print_ast
}
}

View file

@ -12,13 +12,13 @@ raw = f:read("*all")
f:close()
local errors = 0
local function printerror(desc,line,col,sfail,trec)
local function printerror(desc, line, col, sfail, trec)
errors = errors+1
print("Error #"..errors..": "..desc.." on line "..line.."(col "..col..")")
end
local result, errors = pg.parse(raw, grammar, printerror)
local result, _ = pg.parse(raw, grammar, printerror)
my_ast = ast.parse_tree_to_ast(result)
ast.print(my_ast)
print(util.dump(result))
local my_ast = ast.parse_tree_to_ast(result)

View file

@ -1,4 +1 @@
pub fn main() void {
const x = 0;
if (x) {}
}
const _x = 0;