7ee6a73ea4
Add standard library modules: - Std::String: strlen, strcmp, concat, copy, starts_with wrappers - Std::Map: linear-probing hash map with String keys, int values Add error handling: - Result and Option algebraic enum examples - ? try operator for automatic error propagation in HIR lowering Compiler bugfixes: - Fix sizeof() for user-defined structs (new hSizeOf HIR node) - Fix HIR type lowering for char8, bool8, int8, uint8, etc. - Fix let statement lowering for pointer types (*char8 → int* bug) - Fix PrintInt ABI mismatch (int64_t → int in io.c) - Fix Makefile test bug (_test_tmp_pkg already exists) Documentation: - Rewrite README.md with features, examples, project structure - Add docs/LanguageRef.md — complete language reference - Add docs/Stdlib.md — standard library documentation - Add docs/BuildAndTest.md — build and test guide New examples: strings, map, result_option, try_operator (13 total)
3.3 KiB
3.3 KiB
Build and Test Guide
This guide covers building the Bux bootstrap compiler, creating projects, and running tests.
Prerequisites
- Nim (1.6+) — for building the bootstrap compiler
- C compiler (
gcc,clang, orcc) — for the C backend - Make
On Debian/Ubuntu:
sudo apt-get install nim gcc make
On macOS:
brew install nim gcc make
Building the Compiler
# Release build
make build
# Development build (no optimizations, faster compile)
make dev
The output is a single binary: buxc.
Creating a Project
# Create a new package in a new directory
./buxc new myproject
cd myproject
This generates:
myproject/
├── bux.toml
└── src/
└── Main.bux
bux.toml
[Package]
Name = "myproject"
Version = "0.1.0"
Type = "bin"
[Build]
Output = "Bin"
Building and Running
# Type-check without building
./buxc check
# Build
./buxc build
# Build and run
./buxc run
# Clean build artifacts
./buxc clean
Build output goes to build/ by default.
Running Tests
Compiler Tests
make test
This runs:
- Lexer unit tests
- Parser unit tests
- Semantic analysis unit tests
- HIR lowering unit tests
- Integration tests (
buxc new,buxc --version)
Example Programs
make test-examples
Compiles and runs all programs in examples/.
Individual Example
mkdir -p examples_pkg/hello/src
cp examples/hello.bux examples_pkg/hello/src/Main.bux
# Create bux.toml manually or use `buxc new`
cd examples_pkg/hello && ../../buxc run
Project Layout
bux/
├── src/ # Bootstrap compiler source (Nim)
│ ├── main.nim # Entry point
│ ├── cli.nim # CLI commands
│ ├── lexer.nim # Tokenizer
│ ├── parser.nim # Parser
│ ├── sema.nim # Semantic analysis
│ ├── hir.nim # High-level IR
│ ├── hir_lower.nim # AST → HIR lowering
│ ├── c_backend.nim # HIR → C code generation
│ └── ...
├── stdlib/ # Standard library
│ ├── Std/
│ │ ├── Io.bux
│ │ ├── Array.bux
│ │ ├── String.bux
│ │ └── Map.bux
│ ├── runtime.c # C runtime shim
│ └── io.c # C I/O functions
├── examples/ # Example programs
├── tests/ # Unit tests (Nim)
├── docs/ # Documentation
└── Makefile
Debugging
Verbose Output
./buxc build -v
Inspecting Generated C
./buxc build
cat build/main.c
Common Errors
| Error | Cause | Fix |
|---|---|---|
stdlib directory not found |
buxc can't find stdlib/ |
Run from project root or set correct path |
duplicate symbol 'bux_alloc' |
Multiple stdlib modules declare same extern | Only declare in one module |
C compilation failed |
Generated C has errors | Check build/main.c for issues |
Adding a New Example
- Create
examples/myexample.bux - Add
myexampletoEXAMPLESinMakefile - Run
make test-examples
Development Workflow
# After making changes to the compiler:
make build
make test
# If tests pass, run examples:
make test-examples