Skip to content

Brainrot standard library#158

Merged
leo-aa88 merged 8 commits intomainfrom
feat/stdrot
Mar 9, 2026
Merged

Brainrot standard library#158
leo-aa88 merged 8 commits intomainfrom
feat/stdrot

Conversation

@SIGMazer
Copy link
Copy Markdown
Member

@SIGMazer SIGMazer commented Mar 8, 2026

Description

This pull request refactors the Brainrot interpreter and build system to modularize built-in functions by moving their implementations into a shared library (libstdrot.so). It introduces a dynamic loading mechanism for the standard library, updates function call dispatching, and adds a new built-in assertion function bet. Documentation is updated accordingly, and the build system is enhanced to support shared library compilation and cleanup.

Build system and shared library integration:

  • The Makefile is updated to build the libstdrot.so shared library, link it with the main executable, and clean up its artifacts. This enables modular loading of built-in functions at runtime. [1] [2]
  • Loader functions stdrot_load and stdrot_unload are added to manage the lifecycle of the standard library, which is now loaded at interpreter startup and unloaded at shutdown. [1] [2] [3]

Interpreter refactoring and function dispatch:

  • Built-in function implementations (such as yapping, baka, ragequit, etc.) are removed from the main binary and replaced with stub declarations that forward calls to the shared library via a standardized dispatch mechanism (execute_func_call). [1] [2] [3] [4]
  • The interpreter now uses execute_func_call for built-in function calls, and function call execution context (line number, function name) is set for improved error reporting. [1] [2]

New built-in function:

  • The bet function is introduced as a runtime assertion, terminating execution with an error message if a condition is false. Documentation is updated to describe its usage and behavior. [1] [2] [3]

Documentation and cleanup improvements:

  • User guides and language reference documentation are updated to reflect the new bet function and the modular built-in function system. [1] [2]
  • Cleanup routines are improved to prevent double freeing and ensure proper resource management, including freeing the scope and interpreter only once.

Code organization and removal of obsolete code:

  • Obsolete built-in function implementations and declarations are removed from lang.y and ast.c, and replaced with modular stubs and loader interfaces. [1] [2]
  • The new stdrot/baka.c file provides the error output function implementation for the shared library.

Related Issue

Fixes #151

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 8, 2026 03:41
@SIGMazer SIGMazer added refactor Modify existing working code but keeping the same functionality. bugfix Fix for something that wasn't working labels Mar 8, 2026
@leo-aa88
Copy link
Copy Markdown
Member

leo-aa88 commented Mar 8, 2026

wow nice PR, will check this one later bit by bit!

@leo-aa88
Copy link
Copy Markdown
Member

leo-aa88 commented Mar 9, 2026

LGTM

@leo-aa88 leo-aa88 merged commit 2c4fc9f into main Mar 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix for something that wasn't working refactor Modify existing working code but keeping the same functionality.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Returned value is ignored

2 participants