Functions#3
Merged
Merged
Conversation
functions working on llvm
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for user-defined functions to the Complect programming language, including function declarations with parameters, return statements, and function calls with optional result assignment. The implementation spans parsing, IR representation, and code generation for both Babel (JavaScript) and LLVM backends.
Key Changes:
- Added
func,return,call,into, andendkeywords to support function syntax - Implemented
FunctionDeclaration,ReturnStatement, andCallStatementIR nodes with full parsing support - Extended Babel and LLVM translators to generate proper function definitions, returns, and calls
- Added comprehensive test coverage for all new functionality
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| todo.md | Marked functions feature as completed and updated todo list |
| lib/tokenizer/keywords.js | Added function-related keywords (func, return, call, into, end) |
| lib/ast/ir-nodes.js | Defined three new IR node classes for functions, returns, and calls |
| lib/ast/ast-builder.js | Implemented parsing logic for function declarations, return statements, and call statements |
| lib/ast/ast-builder.test.js | Added comprehensive tests for parsing all function-related syntax |
| lib/babel-ast/babel-translator.js | Added translation logic to generate JavaScript function declarations, returns, and calls |
| lib/babel-ast/babel-translator.test.js | Added tests verifying correct Babel AST generation for functions |
| lib/llvm/llvm-translator.js | Implemented LLVM IR generation including type inference, function scope management, and call translation |
| lib/llvm/llvm-translator.test.js | Added tests for LLVM function and call statement translation |
| fixtures/function-test | Created example demonstrating function usage with multiple test cases |
| exec-babel.sh | Added shell script for executing Babel-compiled programs |
| exec-llvm.sh | Added shell script for LLVM compilation and execution with memory checking |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 adds support for user-defined functions to the language, including parsing, IR representation, translation to Babel/JavaScript and LLVM IR, and comprehensive tests. The changes introduce function declarations, return statements, and call statements, enabling users to define and call their own functions with parameters and return values.
Parser and IR enhancements:
FunctionDeclaration,ReturnStatement, andCallStatementnode types to the IR inir-nodes.js, and extended the AST builder to parsefunc,return, andcallsyntax, supporting parameters and result assignments. [1] [2] [3] [4]Code generation improvements:
Testing:
Fixtures and scripts:
function-testdemonstrating function usage, and added anexec-babel.shscript for running tests through the Babel pipeline. [1] [2]