Skip to content

Functions#3

Merged
jarrodconnolly merged 6 commits into
mainfrom
functions
Dec 27, 2025
Merged

Functions#3
jarrodconnolly merged 6 commits into
mainfrom
functions

Conversation

@jarrodconnolly

Copy link
Copy Markdown
Owner

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:

  • Added FunctionDeclaration, ReturnStatement, and CallStatement node types to the IR in ir-nodes.js, and extended the AST builder to parse func, return, and call syntax, supporting parameters and result assignments. [1] [2] [3] [4]

Code generation improvements:

  • Updated the Babel translator to generate JavaScript function declarations, return statements, and function calls (with or without result assignment) from the new IR nodes. [1] [2]
  • Extended the LLVM translator to handle function declarations, returns, and calls, including type inference for function signatures and proper result assignment. Added recursive signature collection and variable handling for function calls. [1] [2] [3] [4] [5]

Testing:

  • Added comprehensive tests for function declarations, return statements, and call statements in both the AST builder and Babel translator test suites, ensuring correct parsing and code generation. [1] [2] [3] [4]

Fixtures and scripts:

  • Introduced a new fixture file function-test demonstrating function usage, and added an exec-babel.sh script for running tests through the Babel pipeline. [1] [2]

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 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, and end keywords to support function syntax
  • Implemented FunctionDeclaration, ReturnStatement, and CallStatement IR 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.

Comment thread todo.md
Comment thread lib/llvm/llvm-translator.js Outdated
Comment thread lib/llvm/llvm-translator.js Outdated
Comment thread lib/llvm/llvm-translator.js Outdated
Comment thread exec-babel.sh
@jarrodconnolly jarrodconnolly merged commit f4c91b7 into main Dec 27, 2025
1 check passed
@jarrodconnolly jarrodconnolly deleted the functions branch December 27, 2025 06:34
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