Skip to content

Commit 503d52c

Browse files
committed
feat(codegen): use indent of tabs
1 parent b504cf2 commit 503d52c

File tree

12 files changed

+64
-48
lines changed

12 files changed

+64
-48
lines changed

Makefile

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ LEX_OUT = lex.yy.c
1616
YACC_OUT = parser.tab.c
1717
YACC_HEADER = parser.tab.h
1818

19-
SMOKE_DIR = tests/smoke
20-
SMOKE_SOURCES := $(wildcard $(SMOKE_DIR)/*.c)
21-
SMOKE_CASES := $(basename $(notdir $(SMOKE_SOURCES)))
22-
SEMANTIC_SCRIPT = scripts/run_semantic_tests.sh
19+
PASS_DIR = tests/pass
20+
PASS_SOURCES := $(wildcard $(PASS_DIR)/*.c)
21+
PASS_CASES := $(basename $(notdir $(PASS_SOURCES)))
22+
FAIL_DIR = tests/fail
23+
FAIL_SOURCES := $(wildcard $(FAIL_DIR)/*.c)
24+
FAIL_CASES := $(basename $(notdir $(FAIL_SOURCES)))
2325

2426
all: $(TARGET)
2527

@@ -35,14 +37,16 @@ $(YACC_OUT) $(YACC_HEADER): $(YACC_SRC) src/ast.h src/ast.c
3537
clean:
3638
rm -f $(TARGET) $(LEX_OUT) $(YACC_OUT) $(YACC_HEADER)
3739

38-
test: all
39-
@echo "== Running smoke tests =="
40-
@if [ -z "$(SMOKE_CASES)" ]; then \
41-
echo "No smoke tests found under $(SMOKE_DIR)"; \
40+
test: test-pass test-fail
41+
42+
test-pass: all
43+
@echo "== Running pass tests =="
44+
@if [ -z "$(PASS_CASES)" ]; then \
45+
echo "No pass tests found under $(PASS_DIR)"; \
4246
else \
43-
for case in $(SMOKE_CASES); do \
44-
input="$(SMOKE_DIR)/$$case.c"; \
45-
expected_file="$(SMOKE_DIR)/$$case.lua"; \
47+
for case in $(PASS_CASES); do \
48+
input="$(PASS_DIR)/$$case.c"; \
49+
expected_file="$(PASS_DIR)/$$case.lua"; \
4650
if [ ! -f "$$expected_file" ]; then \
4751
echo "Missing expected Lua file for $$case"; \
4852
exit 1; \
@@ -58,9 +62,41 @@ test: all
5862
exit 1; \
5963
fi; \
6064
done; \
61-
echo "All smoke tests passed."; \
65+
echo "All pass tests passed."; \
6266
fi
6367

64-
semantic-test: all
65-
@echo "== Running semantic tests =="
66-
@COMPILER_CMD=./c2lua bash $(SEMANTIC_SCRIPT)
68+
test-fail: all
69+
@echo "== Running fail tests =="
70+
@if [ -z "$(FAIL_CASES)" ]; then \
71+
echo "No fail tests found under $(FAIL_DIR)"; \
72+
else \
73+
for case in $(FAIL_CASES); do \
74+
input="$(FAIL_DIR)/$$case.c"; \
75+
expected_err="$(FAIL_DIR)/$$case.err"; \
76+
if [ ! -f "$$expected_err" ]; then \
77+
echo "Missing expected .err file for $$case"; \
78+
exit 1; \
79+
fi; \
80+
tmp_err=$$(mktemp); \
81+
if ./c2lua "$$input" > /dev/null 2> "$$tmp_err"; then \
82+
echo "-- $$case... fail"; \
83+
echo "Expected compilation error but succeeded."; \
84+
rm -f "$$tmp_err"; \
85+
exit 1; \
86+
fi; \
87+
if diff -u "$$expected_err" "$$tmp_err" > /dev/null; then \
88+
echo "-- $$case... ok"; \
89+
else \
90+
echo "-- $$case... fail"; \
91+
echo "Expected:"; \
92+
cat "$$expected_err"; \
93+
echo; \
94+
echo "Got:"; \
95+
cat "$$tmp_err"; \
96+
rm -f "$$tmp_err"; \
97+
exit 1; \
98+
fi; \
99+
rm -f "$$tmp_err"; \
100+
done; \
101+
echo "All fail tests passed."; \
102+
fi

src/codegen_lua.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,6 @@ static void emit_indent(FILE *out, int indent)
326326
{
327327
for (int i = 0; i < indent; ++i)
328328
{
329-
fputs(" ", out);
329+
fputs("\t", out);
330330
}
331331
}

tests/pass/expressions.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
local function add(k, y)
2-
return (k + y)
2+
return (k + y)
33
end
44

55
local function sum(a, b)
6-
local r = ((a + b) / 10)
7-
return r
6+
local r = ((a + b) / 10)
7+
return r
88
end
99

1010
os.exit((function(args)
11-
local args_table = args
12-
local K = args_table and tonumber(args_table[1]) or 0
13-
local a = 10
14-
local b = 20
15-
local r = (sum(a, b) + add(a, b))
16-
return 0
11+
local args_table = args
12+
local K = args_table and tonumber(args_table[1]) or 0
13+
local a = 10
14+
local b = 20
15+
local r = (sum(a, b) + add(a, b))
16+
return 0
1717
end)(arg))

tests/pass/testes.c

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/pass/testes.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/pass/variable.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os.exit((function(args)
2-
local a = 10
3-
a = (a + 5)
4-
return a
2+
local a = 10
3+
a = (a + 5)
4+
return a
55
end)(arg))
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)