@samitouri / QOS-React-2 / commits / 6930b5f77e

[valueblocks] For.test is a proper value block

Joe Savona committed Jan 31, 2023 at 13:39 UTC 6930b5f77e9da0e68c231ec189bb5e9189265318
8 files changed +14 -16
compiler/forget/src/HIR/BuildHIR.ts
+1
@@ -305,6 +305,7 @@ function lowerStatement(
305 builder.terminateWithContinuation(
306 {
307 kind: "for",
308 + loc: stmtNode.loc ?? GeneratedSource,
309 init: initBlock,
310 test: testBlock.id,
311 update: updateBlock,
compiler/forget/src/HIR/HIR.ts
+2 -1
@@ -172,7 +172,7 @@ export type ReactiveWhileTerminal = {
172 export type ReactiveForTerminal = {
173 kind: "for";
174 init: ReactiveValueBlock;
175 - test: ReactiveValueBlock;
175 + test: ReactiveValue;
176 update: ReactiveValueBlock;
177 loop: ReactiveBlock;
178 id: InstructionId;
@@ -314,6 +314,7 @@ export type WhileTerminal = {
314
315 export type ForTerminal = {
316 kind: "for";
317 + loc: SourceLocation;
318 init: BlockId;
319 test: BlockId;
320 update: BlockId;
compiler/forget/src/HIR/visitors.ts
+1
@@ -337,6 +337,7 @@ export function mapTerminalSuccessors(
337 const fallthrough = fn(terminal.fallthrough);
338 return {
339 kind: "for",
340 + loc: terminal.loc,
341 init,
342 test,
343 update,
compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts
+4 -10
@@ -315,16 +315,10 @@ class Driver {
315 );
316 const initValue = this.visitInitBlock(blockValue, initBlock);
317
318 - const testBlock = this.cx.ir.blocks.get(terminal.test)!;
319 - const testTerminal = testBlock.terminal;
320 - invariant(
321 - testTerminal.kind === "branch",
322 - "Expected for loop test block to end in an if"
323 - );
324 - const testValue = this.visitValueBlock(blockValue, testBlock, {
325 - value: testTerminal.test,
326 - id: testTerminal.id,
327 - });
318 + const testValue = this.visitValueBlockNew(
319 + terminal.test,
320 + terminal.loc
321 + ).value;
322
323 const updateBlock = this.cx.ir.blocks.get(terminal.update)!;
324 const updateTerminal = updateBlock.terminal;
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+1 -1
@@ -265,7 +265,7 @@ function codegenTerminal(
265 case "for": {
266 return t.forStatement(
267 codegenForInit(cx, terminal.init),
268 - codegenValueBlock(cx, terminal.test),
268 + codegenInstructionValue(cx, terminal.test),
269 codegenValueBlock(cx, terminal.update),
270 codegenBlock(cx, terminal.loop)
271 );
compiler/forget/src/ReactiveScopes/PrintReactiveFunction.ts
+1 -1
@@ -233,7 +233,7 @@ function printTerminal(writer: Writer, terminal: ReactiveTerminal): void {
233 writer.writeLine("[${terminal.id}] for (");
234 printValueBlock(writer, terminal.init);
235 writer.writeLine(";");
236 - printValueBlock(writer, terminal.test);
236 + printReactiveValue(writer, terminal.test);
237 writer.writeLine(";");
238 printValueBlock(writer, terminal.update);
239 writer.writeLine(") {");
compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts
+1 -1
@@ -231,7 +231,7 @@ function visit(context: Context, block: ReactiveBlock): void {
231 }
232 case "for": {
233 visitValueBlock(context, terminal.init);
234 - visitValueBlock(context, terminal.test);
234 + visitReactiveValue(context, terminal.test);
235 visitValueBlock(context, terminal.update);
236 visit(context, terminal.loop);
237 break;
compiler/forget/src/ReactiveScopes/visitors.ts
+3 -2
@@ -103,7 +103,7 @@ export class ReactiveFunctionVisitor<TState = void> {
103 }
104 case "for": {
105 this.visitValueBlock(terminal.init, state);
106 - this.visitValueBlock(terminal.test, state);
106 + this.visitValue(terminal.id, terminal.test, state);
107 this.visitValueBlock(terminal.update, state);
108 this.visitBlock(terminal.loop, state);
109 break;
@@ -334,7 +334,8 @@ export function eachTerminalBlock(
334 }
335 case "for": {
336 visitValueBlock(terminal.init);
337 - visitValueBlock(terminal.test);
337 + // TODO
338 + // visitValueBlock(terminal.test);
339 visitValueBlock(terminal.update);
340 visitBlock(terminal.loop);
341 break;