@samitouri / QOS-React-2 / commits / de3952352b

Use new codegen in playground

Switches to the new codegen with memoization applied, and puts the JS tab first to make it easier to look at the input/output side by side.

Joe Savona committed Dec 14, 2022 at 16:23 UTC de3952352bf664ba63edd7211a1f732f791d9441
2 files changed +28 -19
compiler/forget/packages/playground/components/Editor/Output.tsx
+13 -10
@@ -21,19 +21,21 @@ import TabbedWindow, { TabTypes } from "../TabbedWindow";
21 import { monacoOptions } from "./monacoOptions";
22 const {
23 buildReactiveFunction,
24 - printReactiveFunction,
25 - parseFunctions,
26 - Environment,
27 - enterSSA,
24 + codegenReactiveFunction,
25 eliminateRedundantPhi,
29 - inferReferenceEffects,
26 + enterSSA,
27 + Environment,
28 + flattenReactiveLoops,
29 inferMutableRanges,
31 - inferReactiveScopeVariables,
30 inferReactiveScopes,
31 + inferReactiveScopeVariables,
32 + inferReferenceEffects,
33 leaveSSA,
34 lower,
35 + parseFunctions,
36 printHIR,
36 - codegen,
37 + printReactiveFunction,
38 + propagateScopeDependencies,
39 } = HIR;
40 const MemoizedOutput = memo(Output);
41
@@ -98,10 +100,11 @@ function compile(source: string): CompilerOutput | CompilerError {
100 const inferReactiveScopesOutput = printHIR(ir.body);
101
102 const reactiveFunction = buildReactiveFunction(ir);
103 + flattenReactiveLoops(reactiveFunction);
104 + propagateScopeDependencies(reactiveFunction);
105 const reactiveFunctionOutput = printReactiveFunction(reactiveFunction);
106
103 - codegen(ir);
104 - const ast = codegen(ir);
107 + const ast = codegenReactiveFunction(reactiveFunction);
108 const generated = generate(
109 ast,
110 {
@@ -163,6 +166,7 @@ function Output({ store, setTabsOpen, tabsOpen }: Props) {
166 setTabsOpen={setTabsOpen}
167 tabsOpen={tabsOpen}
168 tabs={{
169 + JS: <TextTabContent output={compilerOutput.codegenOutput} />,
170 HIR: (
171 <TextTabContent output={compilerOutput.hirOutput}></TextTabContent>
172 ),
@@ -204,7 +208,6 @@ function Output({ store, setTabsOpen, tabsOpen }: Props) {
208 output={compilerOutput.reactiveFunctionOutput}
209 ></TextTabContent>
210 ),
207 - JS: <TextTabContent output={compilerOutput.codegenOutput} />,
211 SourceMap: (
212 <>
213 {compilerOutput.sourceMapUrl && (
compiler/forget/src/index.ts
+15 -9
@@ -27,8 +27,10 @@ import * as t from "@babel/types";
27 import { lower } from "./HIR/BuildHIR";
28 import { buildReactiveFunction } from "./HIR/BuildReactiveFunction";
29 import codegen from "./HIR/Codegen";
30 +import { codegenReactiveFunction } from "./HIR/CodegenReactiveFunction";
31 import { eliminateRedundantPhi } from "./HIR/EliminateRedundantPhi";
32 import enterSSA from "./HIR/EnterSSA";
33 +import { flattenReactiveLoops } from "./HIR/FlattenReactiveLoops";
34 import { Environment } from "./HIR/HIRBuilder";
35 import { inferMutableRanges } from "./HIR/InferMutableRanges";
36 import { inferReactiveScopes } from "./HIR/InferReactiveScopes";
@@ -37,6 +39,7 @@ import inferReferenceEffects from "./HIR/InferReferenceEffects";
39 import { leaveSSA } from "./HIR/LeaveSSA";
40 import printHIR, { printFunction } from "./HIR/PrintHIR";
41 import { printReactiveFunction } from "./HIR/PrintReactiveFunction";
42 +import { propagateScopeDependencies } from "./HIR/PropagateScopeDependencies";
43
44 function parseFunctions(
45 source: string
@@ -60,21 +63,24 @@ function parseFunctions(
63 }
64
65 export const HIR = {
63 - parseFunctions,
64 - lower,
66 + codegenReactiveFunction,
67 + flattenReactiveLoops,
68 + propagateScopeDependencies,
69 + buildReactiveFunction,
70 + codegen,
71 eliminateRedundantPhi,
72 enterSSA,
73 + Environment,
74 inferMutableRanges,
68 - inferReferenceEffects,
69 - inferReactiveScopeVariables,
75 inferReactiveScopes,
71 - buildReactiveFunction,
72 - printReactiveFunction,
76 + inferReactiveScopeVariables,
77 + inferReferenceEffects,
78 + leaveSSA,
79 + lower,
80 + parseFunctions,
81 printFunction,
82 printHIR,
75 - Environment,
76 - leaveSSA,
77 - codegen,
83 + printReactiveFunction,
84 };
85
86 export default BabelPlugin;