Skip to content

Language: while, do-while, and for loops (CFG → VM → JIT) #192

@PurHur

Description

@PurHur

Problem

lib/Compiler.php::compileStmt() only lowers Jump, JumpIf, and Switch_. Any while, do-while, or for statement hits:

LogicException: Unknown Stmt Type: Stmt\While

Web apps use loops for pagination, template rows, retry logic, and route tables. #115 (break/continue) depends on this.

Goal

Support standard PHP loop forms in VM and JIT:

for ($i = 0; $i < count($items); $i++) { /* ... */ }
while ($row = next($rows)) { /* ... */ }
do { /* ... */ } while ($cond);

Tasks

Acceptance criteria

$s = 0;
for ($i = 0; $i < 5; $i++) { $s += $i; }
echo $s; // 10

Runs identically in bin/vm.php and bin/jit.php.

Dependencies

Files

  • lib/Compiler.php, lib/OpCode.php, lib/VM.php, lib/JIT.php
  • test/compliance/cases/language/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions