Skip to content

Conversation

@SIGMazer
Copy link
Member

Description

This pull request introduces support for unsized and partially-unsized array initializers, including multi-dimensional arrays, in both the parser and the interpreter. It also adds new test cases to verify these features and refactors array access handling in the codebase. The most important changes are grouped below:

Parser and Language Support for Array Initializers:

  • Added grammar rules to support unsized (arr[] = {...}) and partially-unsized (arr[][N] = {...}) array declarations, inferring the first dimension from the initializer length or from trailing dimensions as needed. (lang.y) [1] [2]
  • Enabled multi-dimensional array initializers using nested braces, allowing for matrix-style initialization in both fixed-size and unsized arrays. (lang.y)

Interpreter/Core Refactoring for Array Access:

  • Updated array access logic to use node->data.array.name instead of node->data.name, ensuring correct handling of array variables in type checks and assignments. (ast.c) [1] [2]
  • Improved type checking for array accesses in is_short_expression, is_float_expression, and is_double_expression functions, with error reporting for undefined variables. (ast.c) [1] [2] [3]

Short-Circuit Logical Evaluation:

  • Refactored logical operation handling in evaluate_expression_int and evaluate_expression_bool to implement proper short-circuit evaluation for AND and OR operations. (ast.c) [1] [2]

Test Cases for Array Initializers and BFS:

  • Added test cases for unsized 1D arrays, complex array operations, matrix initializers (fixed and partially-unsized), and breadth-first search (BFS) using both multi-dimensional and flattened arrays. (test_cases/unsized_array_init.brainrot, test_cases/unsized_array_complex.brainrot, test_cases/matrix_init_simple.brainrot, test_cases/matrix_init_probe.brainrot, test_cases/grid_bfs.brainrot, test_cases/grid_bfs_1d.brainrot) [1] [2] [3] [4] [5] [6]

Test Result Updates:

  • Updated tests/expected_results.json to include expected outputs for the new test cases. (tests/expected_results.json)

Related Issue

this PR fix the limitation we had from #135

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Performance improvement
  • Refactor

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have documented my changes in the code or documentation
  • I have added tests that prove my changes work (if applicable)
  • I have run the unit tests locally
  • I have run the valgrind memory tests locally
  • All new and existing tests pass

@SIGMazer SIGMazer requested a review from leo-aa88 September 29, 2025 11:05
@leo-aa88
Copy link
Member

LGTM

@leo-aa88 leo-aa88 merged commit a4a4105 into main Sep 30, 2025
2 checks passed
@SIGMazer SIGMazer deleted the fix/array branch October 4, 2025 20:28
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