fix: C backend, parser, sema, HIR lowering for all examples

- C backend: strip c8/c16/c32 string prefixes in emitted C
- C backend: resolve imports to fully-qualified names (Std_Io_PrintLine)
- Parser: fix infinite loop on < in comparisons vs generic calls
- Parser: fix enum patterns without parens (Option::None)
- Parser: fix match expressions inside blocks
- Sema: extract pattern bindings for match arms
- HIR: lower match expressions to if-else chains with enum tag checks
- HIR/C backend: support block expressions as function return values
- Makefile: add integration tests for all 9 examples
- Add pattern_matching.bux example
This commit is contained in:
2026-05-31 01:07:45 +03:00
parent aa3433b5a9
commit 60d4260c93
7 changed files with 272 additions and 14 deletions
+30 -2
View File
@@ -3,7 +3,9 @@ SRC := src/main.nim
OUT := buxc
BUILD_DIR := build
.PHONY: all build test clean
EXAMPLES := hello fibonacci factorial structs enums methods algebraic_enums generics pattern_matching
.PHONY: all build dev test clean test-examples
all: build
@@ -13,14 +15,40 @@ build:
dev:
$(NIM) c -o:$(OUT) $(SRC)
test: build
test: build test-examples
@echo "Running lexer tests..."
$(NIM) c -r tests/lexer_test.nim
@echo "Running parser tests..."
$(NIM) c -r tests/parser_test.nim
@echo "Running sema tests..."
$(NIM) c -r tests/sema_test.nim
@echo "Running HIR tests..."
$(NIM) c -r tests/hir_test.nim
@echo "Running integration tests..."
./$(OUT) new _test_tmp_pkg
./$(OUT) --version
test-examples: build
@for ex in $(EXAMPLES); do \
echo "=== Testing example: $$ex ==="; \
mkdir -p examples_pkg/$$ex/src; \
cp examples/$$ex.bux examples_pkg/$$ex/src/Main.bux; \
if [ ! -f examples_pkg/$$ex/bux.toml ]; then \
echo '[Package]' > examples_pkg/$$ex/bux.toml; \
echo 'Name = "'$$ex'"' >> examples_pkg/$$ex/bux.toml; \
echo 'Version = "0.1.0"' >> examples_pkg/$$ex/bux.toml; \
echo 'Type = "bin"' >> examples_pkg/$$ex/bux.toml; \
echo '' >> examples_pkg/$$ex/bux.toml; \
echo '[Build]' >> examples_pkg/$$ex/bux.toml; \
echo 'Output = "Bin"' >> examples_pkg/$$ex/bux.toml; \
fi; \
(cd examples_pkg/$$ex && timeout 10 ../../$(OUT) run) || exit 1; \
done
@echo "All examples passed!"
clean:
rm -f $(OUT)
rm -rf $(BUILD_DIR)
rm -rf nimcache
rm -rf examples_pkg
rm -rf _test_tmp_pkg