cb256397bd
buxc (Nim bootstrap) successfully compiles buxc2 (Bux self-hosted compiler)
into a working 88KB ELF x86-64 binary.
Compiler fixes (Nim):
- duplicate symbol: user funcs shadow stdlib funcs via mergeDecls()
- forward declarations: func without body + definition (both orderings)
- extern func dedup: same extern in multiple files
- discard keyword: new language keyword, lowered to expr stmt or no-op
- parser: keywords as field names + advance-on-error safeguard
- parser: var without initializer (zero-init)
- parser: multi-line || && continuation expressions
- parser: else-if chain newline handling
- C backend: const declarations emitted as #define
- C backend: load(field_ptr) → base.field optimization (fixes lvalue errors)
Source fixes (src_bux/*.bux):
- types.bux: tk* → ty* prefix for type kind constants (avoid token conflict)
- sema.bux: remaining tk* → ty* references, StringMap → *void workaround
- hir_lower.bux: ekReturn removed, Lcx_LowerParam helper, *f dereference
- c_backend.bux: &mod.funcs[i] for pointer passing
- cli.bux: ReadFile/WriteFile → bux_read_file/bux_write_file wrappers
- parser.bux: pathStr.len → String_Len(pathStr)
- types.bux: "*" + x → String_Concat("*", x)
Build system:
- Makefile: added 4 missing examples + selfhost target
- PLAN.md: updated with actual project state, Phase 7.9 marked complete
All 18 examples pass, all unit tests pass.
65 lines
1.9 KiB
Makefile
65 lines
1.9 KiB
Makefile
NIM := nim
|
|
SRC := src/main.nim
|
|
OUT := buxc
|
|
BUILD_DIR := build
|
|
|
|
EXAMPLES := hello fibonacci factorial structs enums methods algebraic_enums generics generics_struct generic_infer generic_infer2 extend_generic pattern_matching strings strings2 map result_option try_operator
|
|
|
|
.PHONY: all build dev test clean test-examples
|
|
|
|
all: build
|
|
|
|
build:
|
|
$(NIM) c -o:$(OUT) -d:release $(SRC)
|
|
|
|
dev:
|
|
$(NIM) c -o:$(OUT) $(SRC)
|
|
|
|
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..."
|
|
rm -rf _test_tmp_pkg
|
|
./$(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
|
|
|
|
selfhost: build
|
|
@echo "=== Phase 7.9: Building self-hosted compiler ==="
|
|
@rm -rf _selfhost/src
|
|
@mkdir -p _selfhost/src
|
|
@cp src_bux/*.bux _selfhost/src/
|
|
@cp _selfhost/src/main.bux _selfhost/src/Main.bux 2>/dev/null || true
|
|
@cd _selfhost && ../$(OUT) build
|
|
@echo "=== Self-hosted compiler built successfully ==="
|