UNPKG

calcium-lang

Version:
28 lines 850 B
import { Block, Kind, Result } from "../runtime/block"; import { evaluate } from "../util"; import { default as Sym } from "../symbol"; /** * for loop */ export default class For { constructor(variable, iterable) { this.variable = variable; this.iterable = iterable; } execute(env) { const iterator = Reflect.get(evaluate(this.iterable, env), Sym.iter); const block = new Block(Kind.For, env.address, (env) => { const nextValue = Reflect.get(iterator, Sym.next); if (nextValue === null) { return false; } this.variable.assign(nextValue, env); return true; }, (env) => { block.willEnter(env); return Result.Jumpped; }); block.willEnter(env); } } //# sourceMappingURL=for.js.map