Skip to content

Comments

Add multi-file compilation, imports, visibility modifiers, and test runner#5

Merged
benpayne merged 2 commits intomasterfrom
claude/complete-phase-1-tasks-mptQb
Feb 23, 2026
Merged

Add multi-file compilation, imports, visibility modifiers, and test runner#5
benpayne merged 2 commits intomasterfrom
claude/complete-phase-1-tasks-mptQb

Conversation

@benpayne
Copy link
Owner

Summary

This PR adds support for multi-file module compilation with import statements, visibility modifiers (pub), and a test discovery/runner system. The compiler can now parse multiple input files as separate modules with proper import resolution, and the bcc driver includes a test subcommand for discovering and validating .b files.

Key Changes

Module System & Imports

  • Added ImportStatement class to represent import module_name; declarations
  • Implemented import statement parsing with support for dotted paths (import std.io;)
  • Each input file is now parsed as a separate module with its own scope parented to the global scope
  • Module-level scopes isolate top-level symbols while sharing built-in types

Visibility Modifiers

  • Added pub keyword support for marking functions, structs, enums, and protocols as public
  • Functions and structs now track mIsPublic flag during parsing
  • Default visibility is private; pub is required for cross-module access
  • Updated FunctionDefinition::Parse and StructDefinition::Parse to accept isPublic parameter

Compiler Driver (qcc)

  • Extended to accept multiple input files: qcc file1.b file2.b ...
  • Added command-line options: -S/--emit-ir, -c/--emit-obj, -o/--output, --parse-only, -h/--help
  • Each module generates its own .ll file (or uses -o for the first file)
  • Code generation now processes all modules in sequence

Test Infrastructure (bcc)

  • Added bcc test subcommand for discovering and running test files
  • Discovery strategy: searches tests/ directory if present, otherwise current directory for *.b files
  • Runs each file through qcc for parse-only validation
  • Reports pass/fail summary with exit code indicating test results
  • Added --verbose flag for detailed output

Language Features

  • Added ? (try/propagate) operator for error handling (lexer support)
  • Added TryExpression AST node for postfix ? on expressions
  • Documented flat namespace constraint: no nested modules, no qualified-name expressions in source
  • Documented mandatory explicit type signatures on public functions (already enforced by grammar)

Scope Management

  • Impl blocks now use local scopes to avoid polluting global scope
  • Protocol method signatures use local scopes to prevent conflicts with impl methods
  • Scope::addSymbol now returns bool to detect duplicate symbol definitions

Documentation & Testing

  • Updated language_design.md with import syntax, visibility rules, and flat namespace explanation
  • Added comprehensive test files for new features:
    • import_basic.b, import_dotted.b (pass)
    • import_missing_name.b, import_missing_semi.b (fail)
    • visibility_basic.b, pub_function.b, pub_struct.b, pub_enum.b (pass)
    • protocol_conformance.b, protocol_missing_method.b (pass/fail)
    • try_operator.b, result_option.b, match_enum_variants.b (pass)
    • duplicate_func.b (fail) — now tests actual function name conflicts
  • Moved extern_func_call.b from xfail to pass (now properly supported)
  • Updated implementation_plan.md with current task status (62 pass tests, 21 fail tests)

CI/CD

  • Added GitHub Actions workflow (.github/workflows/ci.yml) with parse-only and with-llvm matrix builds
  • Updated install_deps.sh to support cross-platform dependency installation with optional LLVM

Implementation Details

  • Import statements are stored in Module::mImports vector but not yet enforced during symbol resolution (deferred to Task 63)
  • The flat namespace is enforced by grammar: the parser never produces qualified-name expression nodes
  • Public function type signatures are automatically valid (no inference syntax exists in BLang)
  • Test discovery uses find command

https://claude.ai/code/session_01Qum6HxALUGHyurMWLrH9G4

…ling, and CI

Parser features:
- Protocol conformance checking: impl blocks verify all required methods (Tasks 34-35)
- Parse ? try operator as postfix expression (Task 51)
- Parse import statements with dotted paths (Task 60)
- Parse pub visibility modifier on fn/struct/enum (Task 61)
- Enforce no function overloading via duplicate detection in Scope (Task 65)
- Generic constraint validation: unknown protocols and duplicate params rejected (Task 45)

Module system:
- Multi-file compilation: qcc accepts multiple source files (Task 62)
- Flat namespace enforced by grammar (Task 64)
- Mandatory pub type signatures enforced by fn syntax (Task 66)
- ImportStatement AST node and Module storage (Tasks 60-61)

Tooling and CI:
- qcc CLI flags: --parse-only, -S/--emit-ir, -c/--emit-obj, -o/--output (Tasks 72-74)
- GitHub Actions CI with parse-only and with-llvm matrix (Task 75)
- Cross-platform install_deps.sh (Task 215)
- bcc test subcommand skeleton for test discovery and execution (Task 76)

Tests (83 total, up from 67):
- Moved extern_func_call.b from xfail/ to pass/ with extern declaration (Task 11)
- New pass tests: protocol_conformance, try_operator, result_option,
  match_enum_variants, import_basic, import_dotted, pub_function,
  pub_struct, pub_enum, visibility_basic, extern_func_call
- New fail tests: protocol_missing_method, generic_unknown_constraint,
  generic_duplicate_param, match_missing_brace, import_missing_semi,
  import_missing_name

Documentation:
- Updated implementation_plan.md: 72 done, 7 partial, 139 remaining
- Updated CLAUDE.md with new features and test counts
- Updated language_design.md with error handling and module system docs

https://claude.ai/code/session_01Qum6HxALUGHyurMWLrH9G4
Replace unreachable `return nullptr` inside switch with proper `default`
case in ConstExpression::Parse. Also trigger CI on claude/** branches so
feature branch pushes get tested.

https://claude.ai/code/session_01Qum6HxALUGHyurMWLrH9G4
@benpayne benpayne merged commit 5ed74af into master Feb 23, 2026
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants