Asama 6.1 — Implement Constant Folding optimization #55

Open
opened 2026-05-26 19:52:48 +03:00 by saqut · 0 comments
Owner

Goal: Evaluate constant expressions at compile time.

Files to create:

  • src/opt/constant_folding.hpp (new)

Requirements:

  • Walk AST, find BinaryExpression where both operands are Literals.
  • Compute result, replace subtree with single Literal node.
  • Handles +, -, *, /, % for integers and floats.
  • Guard against division by zero (emit warning).

Success criteria:

  • 4 + 5 becomes 9 in optimized AST.
  • x + 0 is NOT folded (x is not constant).
**Goal:** Evaluate constant expressions at compile time. **Files to create:** - src/opt/constant_folding.hpp (new) **Requirements:** - Walk AST, find BinaryExpression where both operands are Literals. - Compute result, replace subtree with single Literal node. - Handles +, -, *, /, % for integers and floats. - Guard against division by zero (emit warning). **Success criteria:** - 4 + 5 becomes 9 in optimized AST. - x + 0 is NOT folded (x is not constant).
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: saqut/saqut-compiler#55
No description provided.