@samitouri / QOS-React-2 / commits / 95642c4421

[valueblocks] Printing for LogicalValue/SequenceValue

Joe Savona committed Jan 31, 2023 at 13:39 UTC 95642c4421304c6fdc5290316a8ebed59779f067
1 file changed +54 -2
compiler/forget/src/ReactiveScopes/PrintReactiveFunction.ts
+54 -2
@@ -12,12 +12,13 @@ import {
12 ReactiveScopeDependency,
13 ReactiveStatement,
14 ReactiveTerminal,
15 + ReactiveValue,
16 ReactiveValueBlock,
17 } from "../HIR/HIR";
18 import {
19 printIdentifier,
19 - printInstruction,
20 printInstructionValue,
21 + printLValue,
22 printPlace,
23 } from "../HIR/PrintHIR";
24 import { assertExhaustive } from "../Utils/utils";
@@ -79,7 +80,18 @@ function printReactiveInstruction(
80 ): void {
81 switch (instr.kind) {
82 case "instruction": {
82 - writer.writeLine(printInstruction(instr.instruction));
83 + const { instruction } = instr;
84 + const id = `[${instruction.id}]`;
85 +
86 + if (instruction.lvalue !== null) {
87 + writer.write(`${id} ${printLValue(instruction.lvalue)} = `);
88 + printReactiveValue(writer, instruction.value);
89 + writer.newline();
90 + } else {
91 + writer.write(`${id} `);
92 + printReactiveValue(writer, instruction.value);
93 + writer.newline();
94 + }
95 break;
96 }
97 case "scope": {
@@ -110,6 +122,38 @@ function printValueBlock(writer: Writer, block: ReactiveValueBlock): void {
122 });
123 }
124
125 +function printReactiveValue(writer: Writer, value: ReactiveValue): void {
126 + switch (value.kind) {
127 + case "LogicalExpression": {
128 + writer.append(`Logical ${value.operator} `);
129 + printReactiveValue(writer, value.left);
130 + writer.newline();
131 + printReactiveValue(writer, value.right);
132 + break;
133 + }
134 + case "SequenceExpression": {
135 + writer.indented(() => {
136 + writer.newline();
137 + writer.writeLine(`Sequence`);
138 + writer.indented(() => {
139 + value.instructions.forEach((instr) =>
140 + printReactiveInstruction(writer, {
141 + kind: "instruction",
142 + instruction: instr,
143 + })
144 + );
145 + writer.write("");
146 + printReactiveValue(writer, value.value);
147 + });
148 + });
149 + break;
150 + }
151 + default: {
152 + writer.append(printInstructionValue(value));
153 + }
154 + }
155 +}
156 +
157 function printTerminal(writer: Writer, terminal: ReactiveTerminal): void {
158 switch (terminal.kind) {
159 case "break": {
@@ -212,6 +256,14 @@ export class Writer {
256 return this.#out.join("");
257 }
258
259 + append(s: string): void {
260 + this.#out.push(s);
261 + }
262 +
263 + newline(): void {
264 + this.#out.push("\n");
265 + }
266 +
267 write(s: string): void {
268 this.#out.push(" ".repeat(this.#depth) + s);
269 }