Skip to content

add pointers support#159

Merged
leo-aa88 merged 4 commits into
mainfrom
feat/pointers
Mar 20, 2026
Merged

add pointers support#159
leo-aa88 merged 4 commits into
mainfrom
feat/pointers

Conversation

@SIGMazer

Copy link
Copy Markdown
Member

Description

This pull request adds comprehensive support for C-style pointers to the Brainrot language, including arbitrary pointer indirection, address-of and dereference operators, pointer assignment, pointer arithmetic, and pointer-based call-by-reference. The changes span the core AST data structures, interpreter logic, and user documentation, ensuring pointers are first-class citizens throughout the system.

Pointer support in AST and interpreter:

  • Added pointer_level fields to Variable, Parameter, Function, ReturnValue, Value, and ASTNode structs to track pointer indirection levels, and introduced the Declarator struct for pointer-aware declarations. [1] [2] [3] [4] [5] [6] [7]
  • Added support for pointer values (pvalue) to relevant union types and assignment logic, including correct handling of pointer assignment in declarations and assignments. [1] [2] [3] [4] [5] [6]
  • Introduced new operator types for address-of and dereference (OP_ADDRESS_OF, OP_DEREFERENCE) and corresponding interpreter logic. [1] [2]
  • Added pointer-aware function and parameter creation routines (create_function_ex, create_parameter_ex, etc.) and updated function definition handling to support pointer return types. [1] [2]
  • Implemented utility functions for pointer evaluation and address calculation (get_expression_pointer_level, evaluate_expression_pointer, evaluate_lvalue_address, etc.).

Documentation updates:

  • Expanded the user guide and language reference to document pointer syntax, semantics, and usage, including pointer declarations, address-of, dereference, pointer assignment, pointer arithmetic, and pointer-based call-by-reference. [1] [2] [3] [4] [5]

Interpreter refactoring:

  • Refactored interpreter logic for assignment, declaration, and function definition to handle pointer types and levels, and streamlined loop handling for clarity. [1] [2] [3] [4] [5] [6] [7]

These changes collectively enable robust pointer functionality in Brainrot, closely mirroring C's pointer model for both variable and function handling.

Related Issue

Fixes #95

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 as a code owner March 17, 2026 11:04
@leo-aa88

Copy link
Copy Markdown
Member

@leo-aa88 leo-aa88 merged commit 1f02d3c into main Mar 20, 2026
2 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.

Add support for pointers

2 participants