Skip to content

Functions#38

Merged
WilliamRagstad merged 62 commits intomainfrom
functions
Dec 4, 2025
Merged

Functions#38
WilliamRagstad merged 62 commits intomainfrom
functions

Conversation

@WilliamRagstad
Copy link
Member

@WilliamRagstad WilliamRagstad commented Jul 25, 2025

This pull request introduces several improvements and refactorings to the interpreter, type checker, and CLI components. The most significant changes include enhanced assignment evaluation with pattern matching, updates to function and lambda handling, improved test coverage and correctness, and minor CLI and error reporting tweaks.

Interpreter and Pattern Matching Improvements

  • Refactored assignment evaluation to support complex patterns (BindPattern), enabling assignments to tuples, records, lists, wildcards, literals, and rest patterns through the new eval_assignment function in core/src/interpreter/eval.rs. This improves language expressiveness and correctness for pattern-based assignments.
  • Enhanced identifier lookup error handling to provide clearer messages when undefined identifiers are encountered.

Function and Lambda Handling

  • Updated function definitions and calls to use Lambda and ret_ty instead of previous function structures, aligning with changes in AST and type representations. This improves consistency and clarity in function handling. [1] [2] [3] [4]
  • Adjusted test helpers and test cases to use the new function/lambda structures and updated parameter handling. [1] [2] [3]

Test Coverage and Correctness

  • Updated interpreter tests to use the standard library (stdlib) for module parsing, ensuring all tests run with the correct environment and type definitions. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Removed an invalid function test and updated tuple and assignment tests to use new pattern matching structures. [1] [2]

Type and Value Representation

  • Added Hash trait derivations to UnsignedInteger, SignedInteger, and RecordKey enums, improving compatibility with hash-based collections and supporting future features. [1] [2] [3]
  • Removed support for numbers as record keys in RecordKey and adjusted formatting accordingly.

CLI and Error Reporting Tweaks

  • Improved REPL prompt display and cleaned up imports for better readability and user experience. [1] [2]
  • Removed redundant error label for EOF in error reporting, simplifying error output.
  • Added debug logging for evaluated expressions in the CLI command handler.

These changes collectively enhance the language's pattern matching capabilities, improve function/lambda consistency, strengthen test reliability, and polish the CLI and error handling experience.This pull request introduces several updates and improvements across multiple components of the codebase, focusing on enhanced debugging, code refactoring, and feature modifications. Key changes include adding debug logging, refactoring assignment evaluation, updating lexer functionality, and removing the Comma token type.

Debugging Enhancements

  • Added detailed debug logging in eval_all to log the number and content of expressions being evaluated.
  • Updated eval_expr to log expressions using print_expr instead of print_sexpr for improved clarity.

Refactoring and Code Simplification

  • Introduced the eval_assignment function to handle assignment expressions more robustly, supporting complex patterns like function definition sugar, destructuring to tuples, records, and lists.
  • Replaced CheckedAst::FunctionDef with CheckedAst::Lambda for consistency in function definitions.
  • Removed redundant code for handling end-of-file error labels in print_error_report.

Lexer Improvements

  • Added factory functions for creating Lexer instances from various sources (e.g., strings, files, stdin).
  • Replaced the Comma token type with an operator token (Op(",".to_string())) for consistency in token handling [1] [2].

Feature Updates

  • Enhanced UnsignedInteger, SignedInteger, and RecordKey enums with the Hash trait to support their use as keys in hash-based collections [1] [2].

Testing Adjustments

  • Updated tests to reflect the removal of the Comma token and the introduction of eval_assignment and CheckedAst::Lambda [1] [2].

These changes collectively enhance the maintainability, functionality, and debugging capabilities of the codebase, aligning with best practices for extensibility and clarity.

@WilliamRagstad WilliamRagstad linked an issue Jul 25, 2025 that may be closed by this pull request
Implemented parsing of the unit type '()' as an empty tuple in the parser and added corresponding handling in the type checker. Refactored CheckedAst and related code to use 'ty' and 'ret_ty' fields for consistency. Added tests for unit parsing and invalid function calls involving unit type.
Refactors the record field parsing logic to use `parse_expr(COMMA_PREC)` instead of `parse_top_expr` for value parsing, ensuring correct precedence handling. Also updates token consumption and tracking of the last token's line info for better error reporting and parsing accuracy.
Removed TokenKind::Newline from the is_terminator check in the lexer. Updated parser tests to unwrap the result earlier and add debugging output for unexpected cases.
The specialize module has been moved from core/src/parser to core/src/type_checker, and related imports and module declarations have been updated accordingly. Intrinsic operator definitions and constants were relocated from op.rs to parser.rs. Type handling logic was removed from the parser, and function signatures were updated to reflect these changes.
Moved parser specialization functions (assignment, member access, binding patterns, etc.) from type_checker/specialize.rs to a new parser/utils.rs module. Updated parser and type checker code to use the new utils module, fixed a typo in the AST enum (MemderAccess -> MemberAccess), and removed unused type registration in stdlib/init.rs. This improves code organization and separation of concerns between parsing and type checking.
Renamed TokenKind to Token and updated all references in lexer, parser, and tests. Simplified AST assignment and type handling, removed LiteralType and annotation from Assignment, and updated related parser logic and tests. Moved parser/utils.rs into parser.rs as a module. These changes improve code clarity and unify token and AST representations.
Introduces a new is_newline method to the Token implementation for easier checking of newline tokens. Also resets VSCode color customizations in settings.json.
Refactored the binding pattern conversion logic from parser.rs to pattern.rs by implementing BindPattern::from_expr and LiteralPattern::from_value. This improves code organization and encapsulation of pattern-related functionality. Also updated references to use the new methods and fixed a typo in a comment.
Commented out handling of Ast::LiteralType in type checker and specialize modules. Assignment type annotations are now ignored, and related code paths for literal type expressions are disabled to simplify type checking logic.
@WilliamRagstad
Copy link
Member Author

This PR has grown into much more than just functions, but also a massive refactoring of the whole compiler. So, this must now be merged into main for new features to be started in parallel.

@WilliamRagstad WilliamRagstad merged commit aff81ac into main Dec 4, 2025
1 check failed
@WilliamRagstad WilliamRagstad deleted the functions branch December 4, 2025 20:46
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.

Function definitions

1 participant