Skip to content

intermediate representation#2

Merged
jarrodconnolly merged 8 commits into
mainfrom
ir
Dec 27, 2025
Merged

intermediate representation#2
jarrodconnolly merged 8 commits into
mainfrom
ir

Conversation

@jarrodconnolly

Copy link
Copy Markdown
Owner

This pull request introduces a new intermediate representation (IR) for the Complect compiler, refactors the compiler pipeline to use this IR, and adds a pluggable backend architecture supporting both JavaScript (via Babel AST) and LLVM IR output. It also updates the documentation to reflect these architectural changes and adds comprehensive tests for the new IR AST builder.

Major architectural improvements:

  • Introduced a new IR AST structure with dedicated node classes for statements and expressions, enabling a backend-agnostic compilation pipeline. (lib/ast/ir-nodes.js)
  • Implemented an ASTBuilder that parses token streams into the new IR AST, supporting all core Complect language constructs. (lib/ast/ast-builder.js)
  • Added a comprehensive test suite for the IR AST builder, ensuring correct parsing of variable declarations, assignments, conditionals, loops, and expressions. (lib/ast/ast-builder.test.js)

Backend and code generation:

  • Added a BabelTranslator to convert the IR AST into Babel AST for JavaScript code generation, supporting all major statement and expression types. (lib/babel-ast/babel-translator.js)

Documentation and usage updates:

  • Updated README.md to describe the new IR-based architecture, pluggable backend system, LLVM IR support, and improved CLI usage instructions. (README.md) [1] [2] [3]

These changes lay the groundwork for future extensibility (such as WebAssembly and custom interpreters), improve maintainability, and provide a solid foundation for further language and backend enhancements.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a major architectural refactoring that decouples the compiler from Babel-specific AST generation by introducing an intermediate representation (IR), enabling a pluggable backend system supporting both JavaScript (Babel) and LLVM IR compilation.

Key changes:

  • New IR AST structure with dedicated node classes for backend-agnostic compilation
  • Pluggable backend architecture with BabelTranslator and LLVMTranslator implementations
  • Enhanced CLI with backend selection, file I/O, and help options
  • Comprehensive test suites for IR AST builder and Babel translator

Reviewed changes

Copilot reviewed 12 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
plan.md Added implementation plan document outlining the multi-backend architecture strategy
package.json Added llvm-bindings dependency; removed "stream" keyword
package-lock.json Large dependency tree for llvm-bindings and related build tools (cmake-js, etc.)
llvm-test/llvm.js Updated target triple from macOS to Linux
lib/tokenizer/token.js Removed commented-out code
lib/llvm/llvm-translator.js New LLVM backend translator converting IR to LLVM IR with support for all language features
lib/compiler.js Refactored to build IR first, then translate to selected backend (babel or llvm)
lib/babel-ast/babel-translator.test.js Comprehensive test suite for Babel translator
lib/babel-ast/babel-translator.js New Babel backend translator converting IR to Babel AST
lib/ast/ir-nodes.js New IR node class definitions (Program, Statement, Expression, and concrete types)
lib/ast/ast-builder.test.js Comprehensive test suite for IR AST builder
lib/ast/ast-builder.js New AST builder parsing tokens into IR using state machine
bin/cli.js Enhanced CLI with backend selection, file I/O, and help options
README.md Updated documentation describing IR architecture, LLVM support, and CLI usage; fixed license reference
.gitignore Added LLVM output files (*.ll, *.s)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/llvm/llvm-translator.js
Comment thread lib/llvm/llvm-translator.js
Comment thread package.json
Comment thread README.md
Comment thread lib/babel-ast/babel-translator.js Outdated
Comment thread lib/llvm/llvm-translator.js Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 18 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ast/ast-builder.js
Comment thread lib/ast/ast-builder.js
Comment thread lib/llvm/llvm-translator.js
Comment thread lib/llvm/llvm-translator.js Outdated
Comment thread lib/llvm/llvm-translator.js
Comment thread lib/ast/ast-builder.js
add auto free on string assignment
add free temp variable in expressions
@jarrodconnolly jarrodconnolly merged commit 7792ef5 into main Dec 27, 2025
1 check failed
@jarrodconnolly jarrodconnolly deleted the ir branch December 27, 2025 00:40
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