Skip to content

Conversation

@rbonifacio
Copy link
Contributor

Redesign of the function call evaluation and interpreter environment.

In this commit, we rename the parser functions, changed the
order of the declarations (to simplify program comprehension), and
also improve the parser test organization. To this end, we moved
the test suite to the 'tests/parser_tests.rs' file. New features
in the parse:

- parse for statement
- parse while statement
…er_expr, parser_stmt)

Also, since we aim to make the code more correct, we decided to
remove the code related to the statement 'match-case'.
…variables

- Update Environment to differentiate mutable and non-mutable variables:
  - Add mutable flag to variable storage in Scope
  - Update lookup to return (bool, Type) tuple indicating mutability
  - Modify map_variable to require mutability parameter

- Add type checking for new statements:
  - val declaration (non-mutable)
  - var declaration (mutable)
  - if-then-else with proper type checking
  - for loops with type checking
  - while loops with type checking

- Update test suite:
  - Add tests for mutable/non-mutable variable behavior
  - Add tests for new statement type checking
  - Fix existing tests to declare variables before assignment

- Clean up source code:
  - Remove old type checker files (tc/*)
  - Reorganize type checking logic
  - Improve error messages
- Split interpreter.rs into expression_eval.rs and statement_execute.rs
- Moved expression evaluation logic into expression_eval.rs
- Moved statement execution logic into statement_execute.rs
- Created mod.rs to expose the main functions (eval, run, execute)
- Removed the old interpreter.rs file
- Fixed unused import warning in statement_execute.rs
- All tests pass successfully
… expression tests

- Add missing NEQ (!=) operator implementation in expression evaluator
- Create relational_expression_tests module with 40 comprehensive tests
- Cover all relational operators: EQ, NEQ, GT, LT, GTE, LTE
- Test integer, real, and mixed type comparisons
- Include edge cases: negatives, zero, decimals, large numbers
- Add error handling tests for invalid types and undefined variables
- Test complex expressions with variables and arithmetic operations
- Maintain proper test organization in expression_eval.rs
…t cases

- Create boolean_expression_tests module in expression_eval.rs
- Cover all boolean operators: AND, OR, NOT with truth table tests
- Test basic operations: all combinations of True/False for AND/OR
- Test NOT operator with both True and False inputs
- Add variable integration tests with boolean values
- Test nested boolean expressions and operator precedence
- Include complex expressions combining boolean, relational, and arithmetic
- Test De Morgan's law equivalence verification
- Add edge cases: double negation, chained operators
- Test integration with relational operators (>, <, ==, etc.)
- Include error handling for invalid types (integers, strings, reals)
- Test undefined variable handling in boolean contexts
- Verify proper evaluation order in mixed expressions
- Add comprehensive operator chaining tests
- Maintain consistent test organization alongside existing modules
- Rename all eval function calls to use consistent 'eval_' prefix:
  * add → eval_add, sub → eval_sub, mul → eval_mul, div → eval_div
  * and → eval_and, or → eval_or, not → eval_not
  * eq → eval_eq, neq → eval_neq, gt → eval_gt, lt → eval_lt
  * gte → eval_gte, lte → eval_lte
  * lookup → eval_lookup, call → eval_call
- Reorganize function definitions to match eval() function call order
- Move helper functions (eval_binary_arith_op, eval_binary_boolean_op,
  eval_binary_rel_op) before their usage
- Group functions by operation type: arithmetic, boolean, relational
- Maintain all existing functionality and test coverage
- Improve code organization and naming consistency
@rbonifacio rbonifacio merged commit e5d952d into main Jun 19, 2025
@helpmehelpus
Copy link
Collaborator

hard to follow this rhythm. plz teach me how to

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.

3 participants