Asama 6.1 — Implement Constant Folding optimization #55

Closed
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).
saqut closed this issue 2026-06-14 21:53:17 +03:00
Sign in to join this conversation.
No description provided.