intermediate representation#2
Merged
Merged
Conversation
There was a problem hiding this comment.
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.
script to easily compile and run llvm backends
There was a problem hiding this comment.
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.
add auto free on string assignment add free temp variable in expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
lib/ast/ir-nodes.js)ASTBuilderthat parses token streams into the new IR AST, supporting all core Complect language constructs. (lib/ast/ast-builder.js)lib/ast/ast-builder.test.js)Backend and code generation:
BabelTranslatorto 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:
README.mdto 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.