Skip to content

Add variables#2

Open
hand-burger wants to merge 2 commits into
AdamHameed:mainfrom
hand-burger:feature/variables
Open

Add variables#2
hand-burger wants to merge 2 commits into
AdamHameed:mainfrom
hand-burger:feature/variables

Conversation

@hand-burger

Copy link
Copy Markdown

Summary of Changes

This PR introduces support for local variable declarations, read references, and assignment statements.

  1. AST Improvements: Extended the AST with Statement::Declare, Statement::Assign, and Expr::Variable nodes to model variables.
  2. Parser Upgrades:
    • The parser can now loop and parse multiple statements in a function body instead of requiring exactly one return statement.
    • Parses int x = <expr>; (declarations) and x = <expr>; (assignments).
    • Resolves identifier lookups (x) as expressions.
  3. LLVM Codegen:
    • Dynamically allocates stack variables using alloca and stores values using store inside generate_ir.
    • Resolves variable reads by generating load instructions referencing their allocated stack space.
  4. Testing: Added unit and end-to-end integration tests verifying local variable compilation and multi-statement function executions.

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.

1 participant