Skip to content

feat: add gang (struct) keyword#161

Merged
leo-aa88 merged 5 commits into
mainfrom
feat/gang-keyword
Apr 3, 2026
Merged

feat: add gang (struct) keyword#161
leo-aa88 merged 5 commits into
mainfrom
feat/gang-keyword

Conversation

@leo-aa88

@leo-aa88 leo-aa88 commented Mar 26, 2026

Copy link
Copy Markdown
Member

Description

Adds struct support to the Brainrot language via the gang keyword.

Syntax

gang Point {
    rizz x;
    rizz y;
    chad magnitude;
};

skibidi main {
    gang Point p;
    p.x = 3;
    p.y = 4;
    p.magnitude = 5.0;
    yapping("Point: %d %d %.1f", p.x, p.y, p.magnitude);

    gang Point q = {10, 20, 0.0};
    yapping("Q: %d %d %.1f", q.x, q.y, q.magnitude);
}

What's included

  • gang keyword and DOT token in the lexer
  • struct_def, struct_field_list, struct_field grammar rules in the parser
  • Struct registry (register_struct_def, get_struct_def, find_struct_field) backed by a hashmap
  • Sequential memory layout via compute_struct_layout with per-field byte offsets
  • VAR_STRUCT variable type and blob allocation via calloc at declaration time
  • Member read/write through evaluate_struct_member_address used by all evaluate_expression_* functions
  • Runtime field type resolution in execute_assignment for correct write dispatch
  • NODE_STRUCT_ACCESS support in is_expression and ast_expr_to_stdrot_value for yapping integration
  • Uninitialised (gang Point p) and initialised (gang Point q = {10, 20, 0.0}) declaration forms
  • Struct blob and struct_name freed in hm_free; StructDef ownership tracked via intrusive next_def list and freed in free_struct_registry
  • Early return in interpreter_visit_declaration for VAR_STRUCT nodes to prevent double-initialisation

Known limitations

  • Nested struct access (p.inner.x) not yet supported
  • Struct function parameters and return values not yet supported

Implements #100.

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

@leo-aa88 leo-aa88 requested a review from SIGMazer as a code owner March 26, 2026 22:03
@leo-aa88 leo-aa88 self-assigned this Mar 26, 2026
@leo-aa88 leo-aa88 added the enhancement New feature or request label Mar 26, 2026
@leo-aa88 leo-aa88 moved this to In Progress in Brainrot 0.0.1 Mar 26, 2026
@leo-aa88 leo-aa88 added the documentation Improvements or additions to documentation label Mar 26, 2026
@leo-aa88

Copy link
Copy Markdown
Member Author

cursed strlen

@leo-aa88 leo-aa88 added the refactor Modify existing working code but keeping the same functionality. label Apr 1, 2026
@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4.2% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@leo-aa88

leo-aa88 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

Quality Gate Failed Quality Gate failed

Failed conditions 4.2% Duplication on New Code (required ≤ 3%) C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

won't fix these

@leo-aa88 leo-aa88 merged commit 59f994f into main Apr 3, 2026
2 of 3 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Brainrot 0.0.1 Apr 3, 2026
@leo-aa88 leo-aa88 deleted the feat/gang-keyword branch April 3, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request refactor Modify existing working code but keeping the same functionality.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant