Skip to content

Add runtime, REPL, and language features (conditionals, assignment, keywords)#6

Merged
aisrael merged 15 commits intomainfrom
feat/runtime
Mar 19, 2026
Merged

Add runtime, REPL, and language features (conditionals, assignment, keywords)#6
aisrael merged 15 commits intomainfrom
feat/runtime

Conversation

@aisrael
Copy link
Owner

@aisrael aisrael commented Mar 19, 2026

Summary

This PR introduces a runtime layer, an interactive REPL, and several language features so the interpreter can evaluate expressions and run small programs.

Key changes

  • Runtime: New runtime module with core types (Value, SimpleRuntime) and function definitions; eval logic refactored to use it.
  • REPL: New repl module and integration in flt binary for interactive evaluation.
  • Language features:
    • Statements: Expression statements, let bindings, and assignment.
    • Functions: FunctionCall AST, keyword arguments, and enhanced FunctionDefinition / Argument structures.
    • Operators: Comparison (<, >, <=, >=) and equality/inequality (==, !=).
    • Conditionals: if expressions.
  • Parser: Statement parsing, keyword parsing, and extended expression parsing to support the above.
  • Docs & tests: Updated syntax and operator docs; new/updated feature and REPL tests.

Commits (main..HEAD)

  • Add support for if expressions in the language
  • Add REPL module and integrate into main application
  • REPL now uses SimpleRuntime
  • Add expression statement support in AST and parser
  • Add comparison / equality / inequality operators
  • Add assignment and let keyword support
  • Add keyword support in AST and parser
  • Add FunctionCall AST and enhance function definition structures
  • Add runtime module with core types and function definitions
  • Display and formatting improvements for AST

Made with Cursor

aisrael added 15 commits March 15, 2026 14:44
Added a Display implementation for the KeyValue struct to format key-value pairs in map literals, handling both quoted and unquoted keys. Refactored the Display implementation for the Expr enum to utilize the new KeyValue formatting, improving overall expression output consistency. Updated function call and map literal formatting for better readability.
Introduced a new `runtime` module to support the `flt` language, including core types such as `Value` and `Type`, as well as function definitions and signatures. This update lays the groundwork for runtime evaluation and function handling, enhancing the language's capabilities. Updated `lib.rs` to include the new module.
Refactored the FunctionDefinition struct to accept a string name using a generic type for improved flexibility. Introduced an `accepts` method to check if the function definition matches given arguments. Added convenience methods for creating Argument instances with built-in types (number, string, boolean). Updated tests to validate the new functionality.
Introduced a new FunctionCall struct to represent function calls in the AST, including positional and keyword arguments. Updated the expression parser to handle function calls, ensuring that positional arguments are processed before any keyword arguments. Refactored related parsing functions to accommodate the new structure and updated tests to validate the changes.
Introduced a new `Keyword` enum to represent reserved keywords in the language, including `if`, `else`, and `return`. Updated the `Expr` enum to include a `Keyword` variant and refactored the expression parser to handle keyword parsing. Implemented a new `parse_keyword` function to ensure proper recognition of keywords, including word-boundary checks. Added tests to validate keyword parsing functionality and updated the evaluator to handle keyword expressions appropriately.
Introduced the 'let' keyword to the Keyword enum and updated the expression and keyword parsers to recognize it. Added corresponding tests to ensure proper parsing functionality for the 'let' keyword in expressions and keywords, enhancing the language's capabilities.
Updated the `functions-and-pipe.md` documentation to explain the use of keyword arguments in function calls. Modified the `README.md` and `syntax.md` files to reflect these changes, ensuring clarity on the syntax and semantics of function calls with keyword arguments. Updated `runtime-and-limitations.md` to specify the current limitations regarding function calls with keyword arguments.
Introduced a new feature file for assignment scenarios, including tests for both 'let' and direct variable assignments. Updated the parser to handle assignments without the 'let' keyword, allowing for more flexible syntax. Enhanced the runtime trait to support evaluation of assignment statements, and modified related structures to accommodate these changes, ensuring comprehensive parsing and evaluation capabilities for variable assignments.
Enhanced the language by introducing `==` and `!=` as binary operators. Updated the parser to recognize these operators and modified the AST to include corresponding variants. Added tests to validate the functionality of equality and inequality expressions, ensuring proper evaluation and parsing behavior.
Introduced `<`, `>`, `<=`, and `>=` as binary operators in the language. Updated the parser and AST to recognize these operators, enhancing the expression evaluation capabilities. Added corresponding tests to validate the functionality of comparison expressions, ensuring accurate parsing and evaluation behavior.
Introduced a new `Expr` variant in the `Statement` enum to represent bare expressions as statements. Updated the parser to handle expression statements, allowing for direct parsing of expressions without the `let` keyword. Added feature tests to validate the parsing of number expressions and binary expressions with semicolons, ensuring correct output and behavior in the language.
…nce REPL functionality

- Added `dirs-next` and `dirs-sys-next` packages for improved directory handling.
- Updated `thiserror` dependency to version 2.0.9.
- Introduced REPL history management in `flt.rs`, allowing users to save and load command history.
- Modified feature tests to reflect changes in REPL command execution and output validation.
- Introduced a new `repl` module to handle Read-Eval-Print Loop functionality, including history management for user inputs.
- Updated `lib.rs` to include the new `repl` module.
- Refactored `flt.rs` to utilize the new REPL implementation, removing redundant code related to REPL history and execution.
- Enhanced the `SimpleRuntime` to return evaluated values instead of a unit type for better usability in REPL context.
- Introduced a new `IfExpr` variant in the `Expr` enum to represent conditional expressions with optional else branches.
- Updated the parser to handle the syntax for if expressions, allowing for both block and inline branches.
- Enhanced the runtime to evaluate if expressions, returning the appropriate branch based on the condition.
- Added tests to validate the parsing and evaluation of if expressions, ensuring correct behavior for various scenarios including conditions, branches, and error handling for non-boolean conditions.
@aisrael aisrael merged commit 222b9d1 into main Mar 19, 2026
4 checks passed
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.

1 participant