diff --git a/package.json b/package.json index 8c001ce8d..4e5ed2fc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-slang", - "version": "0.3.1", + "version": "0.3.2", "description": "Javascript-based interpreter for slang, written in Typescript", "author": { "name": "Source Academy", diff --git a/src/__tests__/__snapshots__/allowed-syntax.ts.snap b/src/__tests__/__snapshots__/allowed-syntax.ts.snap index c114df96f..f200106b9 100644 --- a/src/__tests__/__snapshots__/allowed-syntax.ts.snap +++ b/src/__tests__/__snapshots__/allowed-syntax.ts.snap @@ -25,6 +25,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -697,6 +698,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -745,6 +747,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -779,9 +782,11 @@ let lastStatementResult = undefined; } }, \\"function name(a, b) {\\\\n const sum = a + b;\\\\n if (sum > 1) {\\\\n return sum;\\\\n } else {\\\\n if (a % 2 === 0) {\\\\n return -1;\\\\n } else if (b % 2 === 0) {\\\\n return 1;\\\\n } else {\\\\n return a > b ? 0 : -2;\\\\n }\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(name, 15, 0, 1, 2);\\"); - native.globals.variables.set(\\"name\\", { + globals.variables.set(\\"name\\", { kind: \\"const\\", - value: name + getValue: () => { + return name; + } }); } } @@ -857,6 +862,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -891,6 +897,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1027,6 +1034,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1061,6 +1069,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1095,6 +1104,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1129,6 +1139,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1163,6 +1174,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1197,6 +1209,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1231,6 +1244,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1265,6 +1279,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1545,6 +1560,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1579,6 +1595,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2114,6 +2131,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2148,6 +2166,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2194,6 +2213,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2228,6 +2248,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2297,6 +2318,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2331,6 +2353,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2421,6 +2444,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2458,6 +2482,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2539,6 +2564,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2576,6 +2602,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3130,6 +3157,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3168,6 +3196,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3179,16 +3208,20 @@ let lastStatementResult = undefined; i = binaryOp(\\"+\\", i, 1, 3, 6); } lastStatementResult = eval(\\"i;\\"); - native.globals.variables.set(\\"i\\", { + globals.variables.set(\\"i\\", { kind: \\"let\\", - value: i, + getValue: () => { + return i; + }, assignNewValue: function (unique) { - return i = this.value = unique; + return i = unique; } }); - native.globals.variables.set(\\"startTime\\", { + globals.variables.set(\\"startTime\\", { kind: \\"const\\", - value: startTime + getValue: () => { + return startTime; + } }); } } @@ -3853,6 +3886,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3890,6 +3924,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3900,16 +3935,20 @@ let lastStatementResult = undefined; throwIfTimeout(startTime, runtime(), 2, 0); } lastStatementResult = eval(\\"i;\\"); - native.globals.variables.set(\\"i\\", { + globals.variables.set(\\"i\\", { kind: \\"let\\", - value: i, + getValue: () => { + return i; + }, assignNewValue: function (unique) { - return i = this.value = unique; + return i = unique; } }); - native.globals.variables.set(\\"startTime\\", { + globals.variables.set(\\"startTime\\", { kind: \\"const\\", - value: startTime + getValue: () => { + return startTime; + } }); } } @@ -5296,6 +5335,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5342,6 +5382,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5360,16 +5401,20 @@ let lastStatementResult = undefined; } } lastStatementResult = eval(\\"i;\\"); - native.globals.variables.set(\\"i\\", { + globals.variables.set(\\"i\\", { kind: \\"let\\", - value: i, + getValue: () => { + return i; + }, assignNewValue: function (unique) { - return i = this.value = unique; + return i = unique; } }); - native.globals.variables.set(\\"startTime\\", { + globals.variables.set(\\"startTime\\", { kind: \\"const\\", - value: startTime + getValue: () => { + return startTime; + } }); } } @@ -5441,6 +5486,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5475,6 +5521,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5611,6 +5658,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5649,6 +5697,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5901,6 +5950,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -5935,6 +5985,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -6291,6 +6342,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -6326,17 +6378,20 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { { let x = [1, 2, 3]; lastStatementResult = eval(\\"getProp(x, 1, 2, 0);\\"); - native.globals.variables.set(\\"x\\", { + globals.variables.set(\\"x\\", { kind: \\"let\\", - value: x, + getValue: () => { + return x; + }, assignNewValue: function (unique) { - return x = this.value = unique; + return x = unique; } }); } @@ -6787,6 +6842,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -6822,17 +6878,20 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { { let x = [1, 2, 3]; lastStatementResult = eval(\\"setProp(x, 1, 4, 2, 0);\\"); - native.globals.variables.set(\\"x\\", { + globals.variables.set(\\"x\\", { kind: \\"let\\", - value: x, + getValue: () => { + return x; + }, assignNewValue: function (unique) { - return x = this.value = unique; + return x = unique; } }); } @@ -6905,6 +6964,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -7110,6 +7170,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -7327,6 +7388,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -7705,6 +7767,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -8087,6 +8150,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -8303,6 +8367,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -8551,6 +8616,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -8868,6 +8934,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -9126,6 +9193,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -9409,6 +9477,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/block-scoping.ts.snap b/src/__tests__/__snapshots__/block-scoping.ts.snap index 9c481b44c..7e25733c5 100644 --- a/src/__tests__/__snapshots__/block-scoping.ts.snap +++ b/src/__tests__/__snapshots__/block-scoping.ts.snap @@ -199,6 +199,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -216,9 +217,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n const x = true;\\\\n if (true) {\\\\n const x = false;\\\\n } else {\\\\n const x = false;\\\\n }\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 10, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -256,6 +259,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -280,9 +284,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n let z = [];\\\\n for (let x = 0; x < 10; x = x + 1) {\\\\n z[x] = () => x;\\\\n }\\\\n return z[1]();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 8, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -319,6 +325,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -335,9 +342,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n let x = true;\\\\n for (let x = 1; x > 0; x = x - 1) {}\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 7, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -377,6 +386,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -394,9 +404,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n let x = true;\\\\n if (true) {\\\\n let x = false;\\\\n } else {\\\\n let x = false;\\\\n }\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 10, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -434,6 +446,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -449,9 +462,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n const x = true;\\\\n {\\\\n const x = false;\\\\n }\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 8, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -490,6 +505,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -508,9 +524,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n let x = true;\\\\n while (true) {\\\\n let x = false;\\\\n break;\\\\n }\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 9, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } diff --git a/src/__tests__/__snapshots__/display.ts.snap b/src/__tests__/__snapshots__/display.ts.snap index f658fbf8c..384175cfc 100644 --- a/src/__tests__/__snapshots__/display.ts.snap +++ b/src/__tests__/__snapshots__/display.ts.snap @@ -21,6 +21,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -64,6 +65,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -118,6 +120,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -162,6 +165,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -198,6 +202,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -255,6 +260,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/index.ts.snap b/src/__tests__/__snapshots__/index.ts.snap index 87b8e4fbb..ce51dd5f9 100644 --- a/src/__tests__/__snapshots__/index.ts.snap +++ b/src/__tests__/__snapshots__/index.ts.snap @@ -20,15 +20,18 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { { const a = []; lastStatementResult = eval(\\"getProp(a, 1, 2, 0);\\"); - native.globals.variables.set(\\"a\\", { + globals.variables.set(\\"a\\", { kind: \\"const\\", - value: a + getValue: () => { + return a; + } }); } } @@ -60,15 +63,18 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { { const o = {}; lastStatementResult = eval(\\"getProp(o, \\\\\\"nonexistent\\\\\\", 2, 0);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -114,6 +120,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -178,6 +185,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -214,6 +222,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -253,6 +262,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -266,9 +276,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n let variable = false;\\\\n variable = true;\\\\n return variable;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 6, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -320,6 +332,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -333,9 +346,11 @@ let lastStatementResult = undefined; }; }, \\"function test() {\\\\n const constant = 3;\\\\n constant = 4;\\\\n return constant;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(test, 6, 0);\\"); - native.globals.variables.set(\\"test\\", { + globals.variables.set(\\"test\\", { kind: \\"const\\", - value: test + getValue: () => { + return test; + } }); } } @@ -370,6 +385,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -379,9 +395,11 @@ let lastStatementResult = undefined; setProp(getProp(o, \\"a\\", 3, 0), \\"b\\", {}, 3, 0); setProp(getProp(getProp(o, \\"a\\", 4, 0), \\"b\\", 4, 0), \\"c\\", \\"string\\", 4, 0); lastStatementResult = eval(\\"getProp(getProp(getProp(o, \\\\\\"a\\\\\\", 5, 0), \\\\\\"b\\\\\\", 5, 0), \\\\\\"c\\\\\\", 5, 0);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -426,6 +444,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -438,9 +457,11 @@ let lastStatementResult = undefined; value: binaryOp(\\"*\\", i, callIfFuncAndRightArgs(fac, 1, 37, binaryOp(\\"-\\", i, 1, 1, 41)), 1, 33) }, \\"i => i === 1 ? 1 : i * fac(i - 1)\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(fac, 2, 0, 5);\\"); - native.globals.variables.set(\\"fac\\", { + globals.variables.set(\\"fac\\", { kind: \\"const\\", - value: fac + getValue: () => { + return fac; + } }); } } @@ -489,6 +510,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -500,9 +522,11 @@ let lastStatementResult = undefined; }; }, \\"function t(x, y, z) {\\\\n return x + y + z;\\\\n}\\"); lastStatementResult = eval(\\"boolOrErr(binaryOp(\\\\\\"===\\\\\\", callIfFuncAndRightArgs(identity, 4, 0, t), t, 4, 0), 4, 0) && binaryOp(\\\\\\"===\\\\\\", callIfFuncAndRightArgs(t, 4, 21, 1, 2, 3), 6, 4, 21);\\"); - native.globals.variables.set(\\"t\\", { + globals.variables.set(\\"t\\", { kind: \\"const\\", - value: t + getValue: () => { + return t; + } }); } } @@ -533,6 +557,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -603,6 +628,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -610,9 +636,11 @@ let lastStatementResult = undefined; const o = {}; setProp(o, \\"a\\", 1, 2, 0); lastStatementResult = eval(\\"getProp(o, \\\\\\"a\\\\\\", 3, 0);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -682,6 +710,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -697,6 +726,206 @@ let lastStatementResult = undefined; } `; +exports[`Test context reuse: expectResult 1`] = ` +Object { + "alertResult": Array [], + "code": "let i = 0; +function f() { + i = i + 1; + return i; +} +i;", + "displayResult": Array [], + "errors": Array [], + "parsedErrors": "", + "result": 0, + "resultStatus": "finished", + "transpiled": "const native = $$NATIVE_STORAGE; +const callIfFuncAndRightArgs = native.operators.get(\\"callIfFuncAndRightArgs\\"); +const boolOrErr = native.operators.get(\\"boolOrErr\\"); +const wrap = native.operators.get(\\"wrap\\"); +const unaryOp = native.operators.get(\\"unaryOp\\"); +const binaryOp = native.operators.get(\\"binaryOp\\"); +const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); +const setProp = native.operators.get(\\"setProp\\"); +const getProp = native.operators.get(\\"getProp\\"); +let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; +(( ) => { + return (() => { + { + { + let i = 0; + const f = wrap(() => { + i = binaryOp(\\"+\\", i, 1, 3, 6); + return { + isTail: false, + value: i + }; + }, \\"function f() {\\\\n i = i + 1;\\\\n return i;\\\\n}\\"); + lastStatementResult = eval(\\"i;\\"); + globals.variables.set(\\"i\\", { + kind: \\"let\\", + getValue: () => { + return i; + }, + assignNewValue: function (unique) { + return i = unique; + } + }); + globals.variables.set(\\"f\\", { + kind: \\"const\\", + getValue: () => { + return f; + } + }); + } + } + return lastStatementResult; + })(); +})(); +", + "visualiseListResult": Array [], +} +`; + +exports[`Test context reuse: expectResult 2`] = ` +Object { + "alertResult": Array [], + "code": "i = 100; f();", + "displayResult": Array [], + "errors": Array [], + "parsedErrors": "", + "result": 101, + "resultStatus": "finished", + "transpiled": "const native = $$NATIVE_STORAGE; +const callIfFuncAndRightArgs = native.operators.get(\\"callIfFuncAndRightArgs\\"); +const boolOrErr = native.operators.get(\\"boolOrErr\\"); +const wrap = native.operators.get(\\"wrap\\"); +const unaryOp = native.operators.get(\\"unaryOp\\"); +const binaryOp = native.operators.get(\\"binaryOp\\"); +const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); +const setProp = native.operators.get(\\"setProp\\"); +const getProp = native.operators.get(\\"getProp\\"); +let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; +(( ) => { + return (() => { + { + { + { + let i = globals.previousScope.variables.get(\\"i\\").getValue(); + const f = globals.previousScope.variables.get(\\"f\\").getValue(); + { + i = globals.previousScope.variables.get(\\"i\\").assignNewValue(100); + lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 1, 9);\\"); + } + } + } + } + return lastStatementResult; + })(); +})(); +", + "visualiseListResult": Array [], +} +`; + +exports[`Test context reuse: expectResult 3`] = ` +Object { + "alertResult": Array [], + "code": "f(); i;", + "displayResult": Array [], + "errors": Array [], + "parsedErrors": "", + "result": 102, + "resultStatus": "finished", + "transpiled": "const native = $$NATIVE_STORAGE; +const callIfFuncAndRightArgs = native.operators.get(\\"callIfFuncAndRightArgs\\"); +const boolOrErr = native.operators.get(\\"boolOrErr\\"); +const wrap = native.operators.get(\\"wrap\\"); +const unaryOp = native.operators.get(\\"unaryOp\\"); +const binaryOp = native.operators.get(\\"binaryOp\\"); +const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); +const setProp = native.operators.get(\\"setProp\\"); +const getProp = native.operators.get(\\"getProp\\"); +let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; +(( ) => { + return (() => { + { + { + { + let i = globals.previousScope.previousScope.previousScope.variables.get(\\"i\\").getValue(); + const f = globals.previousScope.previousScope.previousScope.variables.get(\\"f\\").getValue(); + { + { + { + callIfFuncAndRightArgs(f, 1, 0); + lastStatementResult = eval(\\"i = globals.previousScope.previousScope.previousScope.variables.get(\\\\\\"i\\\\\\").getValue();\\"); + } + } + } + } + } + } + return lastStatementResult; + })(); +})(); +", + "visualiseListResult": Array [], +} +`; + +exports[`Test context reuse: expectResult 4`] = ` +Object { + "alertResult": Array [], + "code": "i;", + "displayResult": Array [], + "errors": Array [], + "parsedErrors": "", + "result": 102, + "resultStatus": "finished", + "transpiled": "const native = $$NATIVE_STORAGE; +const callIfFuncAndRightArgs = native.operators.get(\\"callIfFuncAndRightArgs\\"); +const boolOrErr = native.operators.get(\\"boolOrErr\\"); +const wrap = native.operators.get(\\"wrap\\"); +const unaryOp = native.operators.get(\\"unaryOp\\"); +const binaryOp = native.operators.get(\\"binaryOp\\"); +const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); +const setProp = native.operators.get(\\"setProp\\"); +const getProp = native.operators.get(\\"getProp\\"); +let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; +(( ) => { + return (() => { + { + { + { + let i = globals.previousScope.previousScope.previousScope.previousScope.previousScope.variables.get(\\"i\\").getValue(); + const f = globals.previousScope.previousScope.previousScope.previousScope.previousScope.variables.get(\\"f\\").getValue(); + { + { + { + { + { + lastStatementResult = eval(\\"i = globals.previousScope.previousScope.previousScope.previousScope.previousScope.variables.get(\\\\\\"i\\\\\\").getValue();\\"); + } + } + } + } + } + } + } + } + return lastStatementResult; + })(); +})(); +", + "visualiseListResult": Array [], +} +`; + exports[`Test equal for different lists: expectResult 1`] = ` Object { "alertResult": Array [], @@ -716,6 +945,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -750,6 +980,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -784,6 +1015,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -820,6 +1052,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -857,6 +1090,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -896,6 +1130,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -907,9 +1142,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x) {\\\\n return 5;\\\\n}\\"); lastStatementResult = eval(\\"binaryOp(\\\\\\"+\\\\\\", callIfFuncAndRightArgs(toString, 4, 0, wrap(a => ({ isTail: false, value: a }), \\\\\\"a => a\\\\\\")), callIfFuncAndRightArgs(toString, 4, 17, f), 4, 0);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -974,6 +1211,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1008,6 +1246,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1042,6 +1281,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1076,6 +1316,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1110,6 +1351,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1144,6 +1386,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1178,6 +1421,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1212,6 +1456,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1246,6 +1491,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1280,6 +1526,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1314,6 +1561,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1348,6 +1596,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1382,6 +1631,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1418,6 +1668,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1455,6 +1706,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/interpreter-errors.ts.snap b/src/__tests__/__snapshots__/interpreter-errors.ts.snap index f7ac7e3fb..9c1539fbe 100644 --- a/src/__tests__/__snapshots__/interpreter-errors.ts.snap +++ b/src/__tests__/__snapshots__/interpreter-errors.ts.snap @@ -19,6 +19,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -102,6 +103,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -314,6 +316,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -331,13 +334,17 @@ let lastStatementResult = undefined; column: 15 }), \\"x => g(x)\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 3, 0, 1);\\"); - native.globals.variables.set(\\"g\\", { + globals.variables.set(\\"g\\", { kind: \\"const\\", - value: g + getValue: () => { + return g; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -422,6 +429,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -431,9 +439,11 @@ let lastStatementResult = undefined; value: x }), \\"x => x\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 2, 0);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -518,6 +528,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -527,9 +538,11 @@ let lastStatementResult = undefined; value: x }), \\"x => x\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 2, 0, 1, 2);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -614,6 +627,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -623,9 +637,11 @@ let lastStatementResult = undefined; value: x }), \\"x => x\\")]; lastStatementResult = eval(\\"callIfFuncAndRightArgs(getProp(f, 0, 2, 0), 2, 0, 1, 2);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -714,6 +730,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -725,9 +742,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x) {\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 4, 0);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -816,6 +835,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -827,9 +847,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x) {\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 4, 0, 1, 2);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -974,6 +996,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1122,6 +1145,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1308,6 +1332,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1883,6 +1908,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2224,6 +2250,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2786,6 +2813,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2797,9 +2825,11 @@ let lastStatementResult = undefined; }; }, \\"function f() {\\\\n return 1;\\\\n}\\"); lastStatementResult = eval(\\"getProp(f, \\\\\\"prototype\\\\\\", 4, 0);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -2848,6 +2878,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2900,6 +2931,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2955,6 +2987,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2966,9 +2999,11 @@ let lastStatementResult = undefined; }; }, \\"function f() {\\\\n return 1;\\\\n}\\"); lastStatementResult = eval(\\"setProp(f, \\\\\\"prop\\\\\\", 5, 4, 0);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -3017,6 +3052,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -3106,6 +3142,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/return-regressions.ts.snap b/src/__tests__/__snapshots__/return-regressions.ts.snap index 837ac5726..f282f6e8b 100644 --- a/src/__tests__/__snapshots__/return-regressions.ts.snap +++ b/src/__tests__/__snapshots__/return-regressions.ts.snap @@ -33,6 +33,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -61,13 +62,17 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 12, 6); }, \\"function f() {\\\\n for (let i = 0; i < 100; i = i + 1) {\\\\n return i + 1;\\\\n unreachable();\\\\n }\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -112,6 +117,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -138,13 +144,17 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 12, 6); }, \\"function f() {\\\\n if (true) {\\\\n return 1;\\\\n unreachable();\\\\n } else {}\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -189,6 +199,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -217,13 +228,17 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 12, 6); }, \\"function f() {\\\\n while (true) {\\\\n return 1;\\\\n unreachable();\\\\n }\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -265,6 +280,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -288,13 +304,17 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 9, 6); }, \\"function f() {\\\\n return 1;\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 11, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -379,6 +399,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -410,17 +431,23 @@ let lastStatementResult = undefined; }; }, \\"function f() {\\\\n for (let i = 0; i < 100; i = i + 1) {\\\\n return id(i + 1) + id(i + 2);\\\\n }\\\\n return 0;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -468,6 +495,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -500,17 +528,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 15, 6); }, \\"function f() {\\\\n if (true) {\\\\n return id(1) + id(2);\\\\n unreachable();\\\\n } else {}\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 17, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -558,6 +592,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -592,17 +627,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 15, 6); }, \\"function f() {\\\\n while (true) {\\\\n return id(1) + id(2);\\\\n unreachable();\\\\n }\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 17, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -647,6 +688,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -676,17 +718,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 12, 6); }, \\"function f() {\\\\n return id(1) + id(2);\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -734,6 +782,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -772,17 +821,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 15, 6); }, \\"function f() {\\\\n for (let i = 0; i < 100; i = i + 1) {\\\\n return id(i + 1);\\\\n unreachable();\\\\n }\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 17, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -830,6 +885,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -866,17 +922,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 15, 6); }, \\"function f() {\\\\n if (true) {\\\\n return id(1);\\\\n unreachable();\\\\n } else {}\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 17, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -924,6 +986,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -962,17 +1025,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 15, 6); }, \\"function f() {\\\\n while (true) {\\\\n return id(1);\\\\n unreachable();\\\\n }\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 17, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -1017,6 +1086,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1050,17 +1120,23 @@ let lastStatementResult = undefined; callIfFuncAndRightArgs(unreachable, 12, 6); }, \\"function f() {\\\\n return id(1);\\\\n unreachable();\\\\n return 0;\\\\n unreachable();\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 14, 4);\\"); - native.globals.variables.set(\\"unreachable\\", { + globals.variables.set(\\"unreachable\\", { kind: \\"const\\", - value: unreachable + getValue: () => { + return unreachable; + } }); - native.globals.variables.set(\\"id\\", { + globals.variables.set(\\"id\\", { kind: \\"const\\", - value: id + getValue: () => { + return id; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } diff --git a/src/__tests__/__snapshots__/stdlib.ts.snap b/src/__tests__/__snapshots__/stdlib.ts.snap index 82edcc101..30e801559 100644 --- a/src/__tests__/__snapshots__/stdlib.ts.snap +++ b/src/__tests__/__snapshots__/stdlib.ts.snap @@ -21,6 +21,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -84,6 +85,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -118,6 +120,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -152,6 +155,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -186,6 +190,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -220,6 +225,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -254,6 +260,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -288,6 +295,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -322,6 +330,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -356,6 +365,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -390,6 +400,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -424,6 +435,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -458,6 +470,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -492,6 +505,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -526,6 +540,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -560,6 +575,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -594,6 +610,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -628,6 +645,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -662,6 +680,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -696,6 +715,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -730,6 +750,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -764,6 +785,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -801,6 +823,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -812,9 +835,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x) {\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(is_function, 4, 0, f);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -845,6 +870,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -879,6 +905,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -913,6 +940,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -947,6 +975,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1189,6 +1218,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1223,6 +1253,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1257,6 +1288,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1291,6 +1323,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1333,6 +1366,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1356,13 +1390,17 @@ let lastStatementResult = undefined; } }, \\"function repeatUntilDifferentTime() {\\\\n if (start === runtime()) {\\\\n return repeatUntilDifferentTime();\\\\n } else {\\\\n return true;\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(repeatUntilDifferentTime, 9, 0);\\"); - native.globals.variables.set(\\"start\\", { + globals.variables.set(\\"start\\", { kind: \\"const\\", - value: start + getValue: () => { + return start; + } }); - native.globals.variables.set(\\"repeatUntilDifferentTime\\", { + globals.variables.set(\\"repeatUntilDifferentTime\\", { kind: \\"const\\", - value: repeatUntilDifferentTime + getValue: () => { + return repeatUntilDifferentTime; + } }); } } @@ -1396,6 +1434,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1436,6 +1475,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1470,6 +1510,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1504,6 +1545,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1538,6 +1580,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1572,6 +1615,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1606,6 +1650,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1756,6 +1801,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/stringify.ts.snap b/src/__tests__/__snapshots__/stringify.ts.snap index 1c53fc02b..65a24d6ca 100644 --- a/src/__tests__/__snapshots__/stringify.ts.snap +++ b/src/__tests__/__snapshots__/stringify.ts.snap @@ -20,6 +20,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -29,9 +30,11 @@ let lastStatementResult = undefined; value: 1 }), \\"() => 1\\")]; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, xs);\\"); - native.globals.variables.set(\\"xs\\", { + globals.variables.set(\\"xs\\", { kind: \\"const\\", - value: xs + getValue: () => { + return xs; + } }); } } @@ -63,6 +66,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -72,9 +76,11 @@ let lastStatementResult = undefined; value: x }), \\"(x, y) => x\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, f);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -117,6 +123,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -142,9 +149,11 @@ let lastStatementResult = undefined; n: 0 }; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, o);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -175,6 +184,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -211,6 +221,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -246,15 +257,18 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { { const xs = []; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, xs);\\"); - native.globals.variables.set(\\"xs\\", { + globals.variables.set(\\"xs\\", { kind: \\"const\\", - value: xs + getValue: () => { + return xs; + } }); } } @@ -290,6 +304,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -301,9 +316,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x, y) {\\\\n return x;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 4, 0, f);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -437,6 +454,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -448,13 +466,17 @@ let lastStatementResult = undefined; setProp(arr, i, i, 3, 2); } lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 5, 0, arr);\\"); - native.globals.variables.set(\\"arr\\", { + globals.variables.set(\\"arr\\", { kind: \\"const\\", - value: arr + getValue: () => { + return arr; + } }); - native.globals.variables.set(\\"startTime\\", { + globals.variables.set(\\"startTime\\", { kind: \\"const\\", - value: startTime + getValue: () => { + return startTime; + } }); } } @@ -573,6 +595,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -607,6 +630,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -642,6 +666,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -651,9 +676,11 @@ let lastStatementResult = undefined; value: 1 }), \\"() => 1\\"), [[]]]]; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, xs);\\"); - native.globals.variables.set(\\"xs\\", { + globals.variables.set(\\"xs\\", { kind: \\"const\\", - value: xs + getValue: () => { + return xs; + } }); } } @@ -685,6 +712,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -702,9 +730,11 @@ let lastStatementResult = undefined; } }; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, o);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -737,6 +767,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -744,11 +775,13 @@ let lastStatementResult = undefined; let o = {}; setProp(o, \\"o\\", o, 2, 0); lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 3, 0, o);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"let\\", - value: o, + getValue: () => { + return o; + }, assignNewValue: function (unique) { - return o = this.value = unique; + return o = unique; } }); } @@ -780,6 +813,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -814,6 +848,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -849,6 +884,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -862,9 +898,11 @@ let lastStatementResult = undefined; }), \\"() => 1\\") }; lastStatementResult = eval(\\"callIfFuncAndRightArgs(stringify, 2, 0, o);\\"); - native.globals.variables.set(\\"o\\", { + globals.variables.set(\\"o\\", { kind: \\"const\\", - value: o + getValue: () => { + return o; + } }); } } @@ -895,6 +933,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -929,6 +968,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -967,6 +1007,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1005,6 +1046,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1043,6 +1085,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1081,6 +1124,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1119,6 +1163,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1153,6 +1198,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/__tests__/__snapshots__/tailcall-return.ts.snap b/src/__tests__/__snapshots__/tailcall-return.ts.snap index 39abbd4e5..087100e35 100644 --- a/src/__tests__/__snapshots__/tailcall-return.ts.snap +++ b/src/__tests__/__snapshots__/tailcall-return.ts.snap @@ -26,6 +26,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -48,9 +49,11 @@ let lastStatementResult = undefined; } }, \\"function f(x, y) {\\\\n if (x <= 0) {\\\\n return y;\\\\n } else {\\\\n return f(x - 1, y + 1);\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 8, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -88,6 +91,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -110,9 +114,11 @@ let lastStatementResult = undefined; } }, \\"function f(x, y) {\\\\n if (x <= 0) {\\\\n return y;\\\\n } else {\\\\n return false || f(x - 1, y + 1);\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 8, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -146,6 +152,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -164,9 +171,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x, y) {\\\\n return x <= 0 ? y : f(x - 1, y + 1);\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 4, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -200,6 +209,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -221,9 +231,11 @@ let lastStatementResult = undefined; }; }, \\"function f(x, y) {\\\\n return x <= 0 ? y : false || x > 0 ? f(x - 1, y + 1) : 'unreachable';\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 4, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -261,6 +273,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -283,9 +296,11 @@ let lastStatementResult = undefined; } }, \\"(x, y) => {\\\\n if (x <= 0) {\\\\n return y;\\\\n } else {\\\\n return f(x - 1, y + 1);\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 8, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -317,6 +332,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -333,9 +349,11 @@ let lastStatementResult = undefined; column: 33 }, \\"(x, y) => x <= 0 ? y : f(x - 1, y + 1)\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 2, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -373,6 +391,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -395,9 +414,11 @@ let lastStatementResult = undefined; } }, \\"function f(x, y, z) {\\\\n if (x <= 0) {\\\\n return y;\\\\n } else {\\\\n return f(x - 1, y + f(0, z, 0), z);\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 8, 0, 5000, 5000, 2);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -430,6 +451,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -457,13 +479,17 @@ let lastStatementResult = undefined; column: 33 }, \\"(x, y) => x <= 0 ? y : f(x - 1, y + 1)\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 3, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); - native.globals.variables.set(\\"g\\", { + globals.variables.set(\\"g\\", { kind: \\"const\\", - value: g + getValue: () => { + return g; + } }); } } @@ -508,6 +534,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -547,13 +574,17 @@ let lastStatementResult = undefined; } }, \\"function g(x, y) {\\\\n if (x <= 0) {\\\\n return y;\\\\n } else {\\\\n return f(x - 1, y + 1);\\\\n }\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(f, 15, 0, 5000, 5000);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); - native.globals.variables.set(\\"g\\", { + globals.variables.set(\\"g\\", { kind: \\"const\\", - value: g + getValue: () => { + return g; + } }); } } diff --git a/src/__tests__/__snapshots__/transpiled-code.ts.snap b/src/__tests__/__snapshots__/transpiled-code.ts.snap index 152af6f1a..983f2c450 100644 --- a/src/__tests__/__snapshots__/transpiled-code.ts.snap +++ b/src/__tests__/__snapshots__/transpiled-code.ts.snap @@ -11,83 +11,84 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $$NATIVE_STORAGE[1].globals; (( ) => { return (() => { { - const runtime = native.globals.previousScope.variables.get(\\"runtime\\").value; - const display = native.globals.previousScope.variables.get(\\"display\\").value; - const raw_display = native.globals.previousScope.variables.get(\\"raw_display\\").value; - const stringify = native.globals.previousScope.variables.get(\\"stringify\\").value; - const error = native.globals.previousScope.variables.get(\\"error\\").value; - const prompt = native.globals.previousScope.variables.get(\\"prompt\\").value; - const is_number = native.globals.previousScope.variables.get(\\"is_number\\").value; - const is_string = native.globals.previousScope.variables.get(\\"is_string\\").value; - const is_function = native.globals.previousScope.variables.get(\\"is_function\\").value; - const is_boolean = native.globals.previousScope.variables.get(\\"is_boolean\\").value; - const is_undefined = native.globals.previousScope.variables.get(\\"is_undefined\\").value; - const parse_int = native.globals.previousScope.variables.get(\\"parse_int\\").value; - const undefined = native.globals.previousScope.variables.get(\\"undefined\\").value; - const NaN = native.globals.previousScope.variables.get(\\"NaN\\").value; - const Infinity = native.globals.previousScope.variables.get(\\"Infinity\\").value; - const math_abs = native.globals.previousScope.variables.get(\\"math_abs\\").value; - const math_acos = native.globals.previousScope.variables.get(\\"math_acos\\").value; - const math_acosh = native.globals.previousScope.variables.get(\\"math_acosh\\").value; - const math_asin = native.globals.previousScope.variables.get(\\"math_asin\\").value; - const math_asinh = native.globals.previousScope.variables.get(\\"math_asinh\\").value; - const math_atan = native.globals.previousScope.variables.get(\\"math_atan\\").value; - const math_atanh = native.globals.previousScope.variables.get(\\"math_atanh\\").value; - const math_atan2 = native.globals.previousScope.variables.get(\\"math_atan2\\").value; - const math_ceil = native.globals.previousScope.variables.get(\\"math_ceil\\").value; - const math_cbrt = native.globals.previousScope.variables.get(\\"math_cbrt\\").value; - const math_expm1 = native.globals.previousScope.variables.get(\\"math_expm1\\").value; - const math_clz32 = native.globals.previousScope.variables.get(\\"math_clz32\\").value; - const math_cos = native.globals.previousScope.variables.get(\\"math_cos\\").value; - const math_cosh = native.globals.previousScope.variables.get(\\"math_cosh\\").value; - const math_exp = native.globals.previousScope.variables.get(\\"math_exp\\").value; - const math_floor = native.globals.previousScope.variables.get(\\"math_floor\\").value; - const math_fround = native.globals.previousScope.variables.get(\\"math_fround\\").value; - const math_hypot = native.globals.previousScope.variables.get(\\"math_hypot\\").value; - const math_imul = native.globals.previousScope.variables.get(\\"math_imul\\").value; - const math_log = native.globals.previousScope.variables.get(\\"math_log\\").value; - const math_log1p = native.globals.previousScope.variables.get(\\"math_log1p\\").value; - const math_log2 = native.globals.previousScope.variables.get(\\"math_log2\\").value; - const math_log10 = native.globals.previousScope.variables.get(\\"math_log10\\").value; - const math_max = native.globals.previousScope.variables.get(\\"math_max\\").value; - const math_min = native.globals.previousScope.variables.get(\\"math_min\\").value; - const math_pow = native.globals.previousScope.variables.get(\\"math_pow\\").value; - const math_random = native.globals.previousScope.variables.get(\\"math_random\\").value; - const math_round = native.globals.previousScope.variables.get(\\"math_round\\").value; - const math_sign = native.globals.previousScope.variables.get(\\"math_sign\\").value; - const math_sin = native.globals.previousScope.variables.get(\\"math_sin\\").value; - const math_sinh = native.globals.previousScope.variables.get(\\"math_sinh\\").value; - const math_sqrt = native.globals.previousScope.variables.get(\\"math_sqrt\\").value; - const math_tan = native.globals.previousScope.variables.get(\\"math_tan\\").value; - const math_tanh = native.globals.previousScope.variables.get(\\"math_tanh\\").value; - const math_trunc = native.globals.previousScope.variables.get(\\"math_trunc\\").value; - const math_E = native.globals.previousScope.variables.get(\\"math_E\\").value; - const math_LN10 = native.globals.previousScope.variables.get(\\"math_LN10\\").value; - const math_LN2 = native.globals.previousScope.variables.get(\\"math_LN2\\").value; - const math_LOG10E = native.globals.previousScope.variables.get(\\"math_LOG10E\\").value; - const math_LOG2E = native.globals.previousScope.variables.get(\\"math_LOG2E\\").value; - const math_PI = native.globals.previousScope.variables.get(\\"math_PI\\").value; - const math_SQRT1_2 = native.globals.previousScope.variables.get(\\"math_SQRT1_2\\").value; - const math_SQRT2 = native.globals.previousScope.variables.get(\\"math_SQRT2\\").value; - const pair = native.globals.previousScope.variables.get(\\"pair\\").value; - const is_pair = native.globals.previousScope.variables.get(\\"is_pair\\").value; - const head = native.globals.previousScope.variables.get(\\"head\\").value; - const tail = native.globals.previousScope.variables.get(\\"tail\\").value; - const is_null = native.globals.previousScope.variables.get(\\"is_null\\").value; - const list = native.globals.previousScope.variables.get(\\"list\\").value; - const draw_data = native.globals.previousScope.variables.get(\\"draw_data\\").value; - const set_head = native.globals.previousScope.variables.get(\\"set_head\\").value; - const set_tail = native.globals.previousScope.variables.get(\\"set_tail\\").value; - const array_length = native.globals.previousScope.variables.get(\\"array_length\\").value; - const is_array = native.globals.previousScope.variables.get(\\"is_array\\").value; - const stream_tail = native.globals.previousScope.variables.get(\\"stream_tail\\").value; - const stream = native.globals.previousScope.variables.get(\\"stream\\").value; - const list_to_stream = native.globals.previousScope.variables.get(\\"list_to_stream\\").value; - const parse = native.globals.previousScope.variables.get(\\"parse\\").value; - const apply_in_underlying_javascript = native.globals.previousScope.variables.get(\\"apply_in_underlying_javascript\\").value; + const runtime = globals.previousScope.variables.get(\\"runtime\\").getValue(); + const display = globals.previousScope.variables.get(\\"display\\").getValue(); + const raw_display = globals.previousScope.variables.get(\\"raw_display\\").getValue(); + const stringify = globals.previousScope.variables.get(\\"stringify\\").getValue(); + const error = globals.previousScope.variables.get(\\"error\\").getValue(); + const prompt = globals.previousScope.variables.get(\\"prompt\\").getValue(); + const is_number = globals.previousScope.variables.get(\\"is_number\\").getValue(); + const is_string = globals.previousScope.variables.get(\\"is_string\\").getValue(); + const is_function = globals.previousScope.variables.get(\\"is_function\\").getValue(); + const is_boolean = globals.previousScope.variables.get(\\"is_boolean\\").getValue(); + const is_undefined = globals.previousScope.variables.get(\\"is_undefined\\").getValue(); + const parse_int = globals.previousScope.variables.get(\\"parse_int\\").getValue(); + const undefined = globals.previousScope.variables.get(\\"undefined\\").getValue(); + const NaN = globals.previousScope.variables.get(\\"NaN\\").getValue(); + const Infinity = globals.previousScope.variables.get(\\"Infinity\\").getValue(); + const math_abs = globals.previousScope.variables.get(\\"math_abs\\").getValue(); + const math_acos = globals.previousScope.variables.get(\\"math_acos\\").getValue(); + const math_acosh = globals.previousScope.variables.get(\\"math_acosh\\").getValue(); + const math_asin = globals.previousScope.variables.get(\\"math_asin\\").getValue(); + const math_asinh = globals.previousScope.variables.get(\\"math_asinh\\").getValue(); + const math_atan = globals.previousScope.variables.get(\\"math_atan\\").getValue(); + const math_atanh = globals.previousScope.variables.get(\\"math_atanh\\").getValue(); + const math_atan2 = globals.previousScope.variables.get(\\"math_atan2\\").getValue(); + const math_ceil = globals.previousScope.variables.get(\\"math_ceil\\").getValue(); + const math_cbrt = globals.previousScope.variables.get(\\"math_cbrt\\").getValue(); + const math_expm1 = globals.previousScope.variables.get(\\"math_expm1\\").getValue(); + const math_clz32 = globals.previousScope.variables.get(\\"math_clz32\\").getValue(); + const math_cos = globals.previousScope.variables.get(\\"math_cos\\").getValue(); + const math_cosh = globals.previousScope.variables.get(\\"math_cosh\\").getValue(); + const math_exp = globals.previousScope.variables.get(\\"math_exp\\").getValue(); + const math_floor = globals.previousScope.variables.get(\\"math_floor\\").getValue(); + const math_fround = globals.previousScope.variables.get(\\"math_fround\\").getValue(); + const math_hypot = globals.previousScope.variables.get(\\"math_hypot\\").getValue(); + const math_imul = globals.previousScope.variables.get(\\"math_imul\\").getValue(); + const math_log = globals.previousScope.variables.get(\\"math_log\\").getValue(); + const math_log1p = globals.previousScope.variables.get(\\"math_log1p\\").getValue(); + const math_log2 = globals.previousScope.variables.get(\\"math_log2\\").getValue(); + const math_log10 = globals.previousScope.variables.get(\\"math_log10\\").getValue(); + const math_max = globals.previousScope.variables.get(\\"math_max\\").getValue(); + const math_min = globals.previousScope.variables.get(\\"math_min\\").getValue(); + const math_pow = globals.previousScope.variables.get(\\"math_pow\\").getValue(); + const math_random = globals.previousScope.variables.get(\\"math_random\\").getValue(); + const math_round = globals.previousScope.variables.get(\\"math_round\\").getValue(); + const math_sign = globals.previousScope.variables.get(\\"math_sign\\").getValue(); + const math_sin = globals.previousScope.variables.get(\\"math_sin\\").getValue(); + const math_sinh = globals.previousScope.variables.get(\\"math_sinh\\").getValue(); + const math_sqrt = globals.previousScope.variables.get(\\"math_sqrt\\").getValue(); + const math_tan = globals.previousScope.variables.get(\\"math_tan\\").getValue(); + const math_tanh = globals.previousScope.variables.get(\\"math_tanh\\").getValue(); + const math_trunc = globals.previousScope.variables.get(\\"math_trunc\\").getValue(); + const math_E = globals.previousScope.variables.get(\\"math_E\\").getValue(); + const math_LN10 = globals.previousScope.variables.get(\\"math_LN10\\").getValue(); + const math_LN2 = globals.previousScope.variables.get(\\"math_LN2\\").getValue(); + const math_LOG10E = globals.previousScope.variables.get(\\"math_LOG10E\\").getValue(); + const math_LOG2E = globals.previousScope.variables.get(\\"math_LOG2E\\").getValue(); + const math_PI = globals.previousScope.variables.get(\\"math_PI\\").getValue(); + const math_SQRT1_2 = globals.previousScope.variables.get(\\"math_SQRT1_2\\").getValue(); + const math_SQRT2 = globals.previousScope.variables.get(\\"math_SQRT2\\").getValue(); + const pair = globals.previousScope.variables.get(\\"pair\\").getValue(); + const is_pair = globals.previousScope.variables.get(\\"is_pair\\").getValue(); + const head = globals.previousScope.variables.get(\\"head\\").getValue(); + const tail = globals.previousScope.variables.get(\\"tail\\").getValue(); + const is_null = globals.previousScope.variables.get(\\"is_null\\").getValue(); + const list = globals.previousScope.variables.get(\\"list\\").getValue(); + const draw_data = globals.previousScope.variables.get(\\"draw_data\\").getValue(); + const set_head = globals.previousScope.variables.get(\\"set_head\\").getValue(); + const set_tail = globals.previousScope.variables.get(\\"set_tail\\").getValue(); + const array_length = globals.previousScope.variables.get(\\"array_length\\").getValue(); + const is_array = globals.previousScope.variables.get(\\"is_array\\").getValue(); + const stream_tail = globals.previousScope.variables.get(\\"stream_tail\\").getValue(); + const stream = globals.previousScope.variables.get(\\"stream\\").getValue(); + const list_to_stream = globals.previousScope.variables.get(\\"list_to_stream\\").getValue(); + const parse = globals.previousScope.variables.get(\\"parse\\").getValue(); + const apply_in_underlying_javascript = globals.previousScope.variables.get(\\"apply_in_underlying_javascript\\").getValue(); { const boolOrErr = 1; setProp(boolOrErr, 123, 1, 2, 0); @@ -105,17 +106,23 @@ let lastStatementResult = undefined; wrap9; }, \\"function f(callIfFuncAndRightArgs, wrap0, wrap1, wrap2, wrap3, wrap4, wrap5, wrap6, wrap7, wrap8, wrap9) {\\\\n let wrap = 2;\\\\n wrap0;\\\\n wrap1;\\\\n wrap2;\\\\n wrap3;\\\\n wrap4;\\\\n wrap5;\\\\n wrap6;\\\\n wrap7;\\\\n wrap8;\\\\n wrap9;\\\\n}\\"); const native = 123; - native.globals.variables.set(\\"boolOrErr\\", { + globals.variables.set(\\"boolOrErr\\", { kind: \\"const\\", - value: boolOrErr + getValue: () => { + return boolOrErr; + } }); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); - native.globals.variables.set(\\"native\\", { + globals.variables.set(\\"native\\", { kind: \\"const\\", - value: native + getValue: () => { + return native; + } }); } } @@ -138,83 +145,84 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $$NATIVE_STORAGE[0].globals; (( ) => { return (() => { { - const runtime = native.globals.previousScope.variables.get(\\"runtime\\").value; - const display = native.globals.previousScope.variables.get(\\"display\\").value; - const raw_display = native.globals.previousScope.variables.get(\\"raw_display\\").value; - const stringify = native.globals.previousScope.variables.get(\\"stringify\\").value; - const error = native.globals.previousScope.variables.get(\\"error\\").value; - const prompt = native.globals.previousScope.variables.get(\\"prompt\\").value; - const is_number = native.globals.previousScope.variables.get(\\"is_number\\").value; - const is_string = native.globals.previousScope.variables.get(\\"is_string\\").value; - const is_function = native.globals.previousScope.variables.get(\\"is_function\\").value; - const is_boolean = native.globals.previousScope.variables.get(\\"is_boolean\\").value; - const is_undefined = native.globals.previousScope.variables.get(\\"is_undefined\\").value; - const parse_int = native.globals.previousScope.variables.get(\\"parse_int\\").value; - const undefined = native.globals.previousScope.variables.get(\\"undefined\\").value; - const NaN = native.globals.previousScope.variables.get(\\"NaN\\").value; - const Infinity = native.globals.previousScope.variables.get(\\"Infinity\\").value; - const math_abs = native.globals.previousScope.variables.get(\\"math_abs\\").value; - const math_acos = native.globals.previousScope.variables.get(\\"math_acos\\").value; - const math_acosh = native.globals.previousScope.variables.get(\\"math_acosh\\").value; - const math_asin = native.globals.previousScope.variables.get(\\"math_asin\\").value; - const math_asinh = native.globals.previousScope.variables.get(\\"math_asinh\\").value; - const math_atan = native.globals.previousScope.variables.get(\\"math_atan\\").value; - const math_atanh = native.globals.previousScope.variables.get(\\"math_atanh\\").value; - const math_atan2 = native.globals.previousScope.variables.get(\\"math_atan2\\").value; - const math_ceil = native.globals.previousScope.variables.get(\\"math_ceil\\").value; - const math_cbrt = native.globals.previousScope.variables.get(\\"math_cbrt\\").value; - const math_expm1 = native.globals.previousScope.variables.get(\\"math_expm1\\").value; - const math_clz32 = native.globals.previousScope.variables.get(\\"math_clz32\\").value; - const math_cos = native.globals.previousScope.variables.get(\\"math_cos\\").value; - const math_cosh = native.globals.previousScope.variables.get(\\"math_cosh\\").value; - const math_exp = native.globals.previousScope.variables.get(\\"math_exp\\").value; - const math_floor = native.globals.previousScope.variables.get(\\"math_floor\\").value; - const math_fround = native.globals.previousScope.variables.get(\\"math_fround\\").value; - const math_hypot = native.globals.previousScope.variables.get(\\"math_hypot\\").value; - const math_imul = native.globals.previousScope.variables.get(\\"math_imul\\").value; - const math_log = native.globals.previousScope.variables.get(\\"math_log\\").value; - const math_log1p = native.globals.previousScope.variables.get(\\"math_log1p\\").value; - const math_log2 = native.globals.previousScope.variables.get(\\"math_log2\\").value; - const math_log10 = native.globals.previousScope.variables.get(\\"math_log10\\").value; - const math_max = native.globals.previousScope.variables.get(\\"math_max\\").value; - const math_min = native.globals.previousScope.variables.get(\\"math_min\\").value; - const math_pow = native.globals.previousScope.variables.get(\\"math_pow\\").value; - const math_random = native.globals.previousScope.variables.get(\\"math_random\\").value; - const math_round = native.globals.previousScope.variables.get(\\"math_round\\").value; - const math_sign = native.globals.previousScope.variables.get(\\"math_sign\\").value; - const math_sin = native.globals.previousScope.variables.get(\\"math_sin\\").value; - const math_sinh = native.globals.previousScope.variables.get(\\"math_sinh\\").value; - const math_sqrt = native.globals.previousScope.variables.get(\\"math_sqrt\\").value; - const math_tan = native.globals.previousScope.variables.get(\\"math_tan\\").value; - const math_tanh = native.globals.previousScope.variables.get(\\"math_tanh\\").value; - const math_trunc = native.globals.previousScope.variables.get(\\"math_trunc\\").value; - const math_E = native.globals.previousScope.variables.get(\\"math_E\\").value; - const math_LN10 = native.globals.previousScope.variables.get(\\"math_LN10\\").value; - const math_LN2 = native.globals.previousScope.variables.get(\\"math_LN2\\").value; - const math_LOG10E = native.globals.previousScope.variables.get(\\"math_LOG10E\\").value; - const math_LOG2E = native.globals.previousScope.variables.get(\\"math_LOG2E\\").value; - const math_PI = native.globals.previousScope.variables.get(\\"math_PI\\").value; - const math_SQRT1_2 = native.globals.previousScope.variables.get(\\"math_SQRT1_2\\").value; - const math_SQRT2 = native.globals.previousScope.variables.get(\\"math_SQRT2\\").value; - const pair = native.globals.previousScope.variables.get(\\"pair\\").value; - const is_pair = native.globals.previousScope.variables.get(\\"is_pair\\").value; - const head = native.globals.previousScope.variables.get(\\"head\\").value; - const tail = native.globals.previousScope.variables.get(\\"tail\\").value; - const is_null = native.globals.previousScope.variables.get(\\"is_null\\").value; - const list = native.globals.previousScope.variables.get(\\"list\\").value; - const draw_data = native.globals.previousScope.variables.get(\\"draw_data\\").value; - const set_head = native.globals.previousScope.variables.get(\\"set_head\\").value; - const set_tail = native.globals.previousScope.variables.get(\\"set_tail\\").value; - const array_length = native.globals.previousScope.variables.get(\\"array_length\\").value; - const is_array = native.globals.previousScope.variables.get(\\"is_array\\").value; - const stream_tail = native.globals.previousScope.variables.get(\\"stream_tail\\").value; - const stream = native.globals.previousScope.variables.get(\\"stream\\").value; - const list_to_stream = native.globals.previousScope.variables.get(\\"list_to_stream\\").value; - const parse = native.globals.previousScope.variables.get(\\"parse\\").value; - const apply_in_underlying_javascript = native.globals.previousScope.variables.get(\\"apply_in_underlying_javascript\\").value; + const runtime = globals.previousScope.variables.get(\\"runtime\\").getValue(); + const display = globals.previousScope.variables.get(\\"display\\").getValue(); + const raw_display = globals.previousScope.variables.get(\\"raw_display\\").getValue(); + const stringify = globals.previousScope.variables.get(\\"stringify\\").getValue(); + const error = globals.previousScope.variables.get(\\"error\\").getValue(); + const prompt = globals.previousScope.variables.get(\\"prompt\\").getValue(); + const is_number = globals.previousScope.variables.get(\\"is_number\\").getValue(); + const is_string = globals.previousScope.variables.get(\\"is_string\\").getValue(); + const is_function = globals.previousScope.variables.get(\\"is_function\\").getValue(); + const is_boolean = globals.previousScope.variables.get(\\"is_boolean\\").getValue(); + const is_undefined = globals.previousScope.variables.get(\\"is_undefined\\").getValue(); + const parse_int = globals.previousScope.variables.get(\\"parse_int\\").getValue(); + const undefined = globals.previousScope.variables.get(\\"undefined\\").getValue(); + const NaN = globals.previousScope.variables.get(\\"NaN\\").getValue(); + const Infinity = globals.previousScope.variables.get(\\"Infinity\\").getValue(); + const math_abs = globals.previousScope.variables.get(\\"math_abs\\").getValue(); + const math_acos = globals.previousScope.variables.get(\\"math_acos\\").getValue(); + const math_acosh = globals.previousScope.variables.get(\\"math_acosh\\").getValue(); + const math_asin = globals.previousScope.variables.get(\\"math_asin\\").getValue(); + const math_asinh = globals.previousScope.variables.get(\\"math_asinh\\").getValue(); + const math_atan = globals.previousScope.variables.get(\\"math_atan\\").getValue(); + const math_atanh = globals.previousScope.variables.get(\\"math_atanh\\").getValue(); + const math_atan2 = globals.previousScope.variables.get(\\"math_atan2\\").getValue(); + const math_ceil = globals.previousScope.variables.get(\\"math_ceil\\").getValue(); + const math_cbrt = globals.previousScope.variables.get(\\"math_cbrt\\").getValue(); + const math_expm1 = globals.previousScope.variables.get(\\"math_expm1\\").getValue(); + const math_clz32 = globals.previousScope.variables.get(\\"math_clz32\\").getValue(); + const math_cos = globals.previousScope.variables.get(\\"math_cos\\").getValue(); + const math_cosh = globals.previousScope.variables.get(\\"math_cosh\\").getValue(); + const math_exp = globals.previousScope.variables.get(\\"math_exp\\").getValue(); + const math_floor = globals.previousScope.variables.get(\\"math_floor\\").getValue(); + const math_fround = globals.previousScope.variables.get(\\"math_fround\\").getValue(); + const math_hypot = globals.previousScope.variables.get(\\"math_hypot\\").getValue(); + const math_imul = globals.previousScope.variables.get(\\"math_imul\\").getValue(); + const math_log = globals.previousScope.variables.get(\\"math_log\\").getValue(); + const math_log1p = globals.previousScope.variables.get(\\"math_log1p\\").getValue(); + const math_log2 = globals.previousScope.variables.get(\\"math_log2\\").getValue(); + const math_log10 = globals.previousScope.variables.get(\\"math_log10\\").getValue(); + const math_max = globals.previousScope.variables.get(\\"math_max\\").getValue(); + const math_min = globals.previousScope.variables.get(\\"math_min\\").getValue(); + const math_pow = globals.previousScope.variables.get(\\"math_pow\\").getValue(); + const math_random = globals.previousScope.variables.get(\\"math_random\\").getValue(); + const math_round = globals.previousScope.variables.get(\\"math_round\\").getValue(); + const math_sign = globals.previousScope.variables.get(\\"math_sign\\").getValue(); + const math_sin = globals.previousScope.variables.get(\\"math_sin\\").getValue(); + const math_sinh = globals.previousScope.variables.get(\\"math_sinh\\").getValue(); + const math_sqrt = globals.previousScope.variables.get(\\"math_sqrt\\").getValue(); + const math_tan = globals.previousScope.variables.get(\\"math_tan\\").getValue(); + const math_tanh = globals.previousScope.variables.get(\\"math_tanh\\").getValue(); + const math_trunc = globals.previousScope.variables.get(\\"math_trunc\\").getValue(); + const math_E = globals.previousScope.variables.get(\\"math_E\\").getValue(); + const math_LN10 = globals.previousScope.variables.get(\\"math_LN10\\").getValue(); + const math_LN2 = globals.previousScope.variables.get(\\"math_LN2\\").getValue(); + const math_LOG10E = globals.previousScope.variables.get(\\"math_LOG10E\\").getValue(); + const math_LOG2E = globals.previousScope.variables.get(\\"math_LOG2E\\").getValue(); + const math_PI = globals.previousScope.variables.get(\\"math_PI\\").getValue(); + const math_SQRT1_2 = globals.previousScope.variables.get(\\"math_SQRT1_2\\").getValue(); + const math_SQRT2 = globals.previousScope.variables.get(\\"math_SQRT2\\").getValue(); + const pair = globals.previousScope.variables.get(\\"pair\\").getValue(); + const is_pair = globals.previousScope.variables.get(\\"is_pair\\").getValue(); + const head = globals.previousScope.variables.get(\\"head\\").getValue(); + const tail = globals.previousScope.variables.get(\\"tail\\").getValue(); + const is_null = globals.previousScope.variables.get(\\"is_null\\").getValue(); + const list = globals.previousScope.variables.get(\\"list\\").getValue(); + const draw_data = globals.previousScope.variables.get(\\"draw_data\\").getValue(); + const set_head = globals.previousScope.variables.get(\\"set_head\\").getValue(); + const set_tail = globals.previousScope.variables.get(\\"set_tail\\").getValue(); + const array_length = globals.previousScope.variables.get(\\"array_length\\").getValue(); + const is_array = globals.previousScope.variables.get(\\"is_array\\").getValue(); + const stream_tail = globals.previousScope.variables.get(\\"stream_tail\\").getValue(); + const stream = globals.previousScope.variables.get(\\"stream\\").getValue(); + const list_to_stream = globals.previousScope.variables.get(\\"list_to_stream\\").getValue(); + const parse = globals.previousScope.variables.get(\\"parse\\").getValue(); + const apply_in_underlying_javascript = globals.previousScope.variables.get(\\"apply_in_underlying_javascript\\").getValue(); { lastStatementResult = eval(\\"\\\\\\"ensure_builtins\\\\\\";\\"); } diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts index 061b10348..b98c8abec 100644 --- a/src/__tests__/index.ts +++ b/src/__tests__/index.ts @@ -1,6 +1,7 @@ import { Value } from '../types' import { stripIndent } from '../utils/formatters' import { + createTestContext, expectParsedError, expectParsedErrorNoErrorSnapshot, expectParsedErrorNoSnapshot, @@ -389,3 +390,19 @@ test('test true || true', () => { test('test || shortcircuiting', () => { return expectToMatchJS('true || 1();', { native: true }) }) + +test('Test context reuse', async () => { + const context = createTestContext({ chapter: 4 }) + const init = stripIndent` + let i = 0; + function f() { + i = i + 1; + return i; + } + i; + ` + await expectResult(init, { context, native: true }).toBe(0) + await expectResult('i = 100; f();', { context, native: true }).toBe(101) + await expectResult('f(); i;', { context, native: true }).toBe(102) + return expectResult('i;', { context, native: true }).toBe(102) +}) diff --git a/src/createContext.ts b/src/createContext.ts index 51670d0a7..50a012478 100644 --- a/src/createContext.ts +++ b/src/createContext.ts @@ -86,7 +86,7 @@ const defineSymbol = (context: Context, name: string, value: Value) => { }) GLOBAL[GLOBAL_KEY_TO_ACCESS_NATIVE_STORAGE][context.contextId].globals.variables.set(name, { kind: 'const', - value + getValue: () => value }) } diff --git a/src/stdlib/__tests__/__snapshots__/list.ts.snap b/src/stdlib/__tests__/__snapshots__/list.ts.snap index d8af49fb7..8c0a6dde3 100644 --- a/src/stdlib/__tests__/__snapshots__/list.ts.snap +++ b/src/stdlib/__tests__/__snapshots__/list.ts.snap @@ -36,6 +36,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -86,6 +87,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -136,6 +138,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -188,6 +191,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -240,6 +244,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -292,6 +297,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -344,6 +350,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -396,6 +403,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -448,6 +456,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -500,6 +509,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -550,6 +560,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -629,6 +640,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -679,6 +691,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -729,6 +742,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -779,6 +793,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -829,6 +844,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -879,6 +895,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -929,6 +946,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -979,6 +997,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1029,6 +1048,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1079,6 +1099,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1113,6 +1134,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1147,6 +1169,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1181,6 +1204,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1215,6 +1239,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1249,6 +1274,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1283,6 +1309,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1317,6 +1344,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1355,6 +1383,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1364,11 +1393,13 @@ let lastStatementResult = undefined; sum = binaryOp(\\"+\\", sum, x, 3, 8); }, \\"x => {\\\\n sum = sum + x;\\\\n}\\"), callIfFuncAndRightArgs(list, 4, 3, 1, 2, 3)); lastStatementResult = eval(\\"sum;\\"); - native.globals.variables.set(\\"sum\\", { + globals.variables.set(\\"sum\\", { kind: \\"let\\", - value: sum, + getValue: () => { + return sum; + }, assignNewValue: function (unique) { - return sum = this.value = unique; + return sum = unique; } }); } @@ -1400,6 +1431,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1453,6 +1485,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1464,9 +1497,11 @@ let lastStatementResult = undefined; }; }, \\"function f() {\\\\n return 1;\\\\n}\\"); lastStatementResult = eval(\\"callIfFuncAndRightArgs(list, 2, 0, 1, 'a string \\\\\\"\\\\\\"', wrap(() => ({ isTail: false, value: f }), \\\\\\"() => f\\\\\\"), f, true, 3.14);\\"); - native.globals.variables.set(\\"f\\", { + globals.variables.set(\\"f\\", { kind: \\"const\\", - value: f + getValue: () => { + return f; + } }); } } @@ -1497,6 +1532,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1531,6 +1567,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1565,6 +1602,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1601,6 +1639,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1651,6 +1690,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1701,6 +1741,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1738,6 +1779,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1775,6 +1817,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1809,6 +1852,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1843,6 +1887,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1877,6 +1922,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1911,6 +1957,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1948,6 +1995,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1956,16 +2004,20 @@ let lastStatementResult = undefined; const q = p; callIfFuncAndRightArgs(set_head, 3, 0, p, 3); lastStatementResult = eval(\\"boolOrErr(binaryOp(\\\\\\"===\\\\\\", p, q, 4, 0), 4, 0) && callIfFuncAndRightArgs(equal, 4, 11, p, callIfFuncAndRightArgs(pair, 4, 20, 3, 2));\\"); - native.globals.variables.set(\\"p\\", { + globals.variables.set(\\"p\\", { kind: \\"let\\", - value: p, + getValue: () => { + return p; + }, assignNewValue: function (unique) { - return p = this.value = unique; + return p = unique; } }); - native.globals.variables.set(\\"q\\", { + globals.variables.set(\\"q\\", { kind: \\"const\\", - value: q + getValue: () => { + return q; + } }); } } @@ -1999,6 +2051,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2007,16 +2060,20 @@ let lastStatementResult = undefined; const q = p; callIfFuncAndRightArgs(set_tail, 3, 0, p, 3); lastStatementResult = eval(\\"boolOrErr(binaryOp(\\\\\\"===\\\\\\", p, q, 4, 0), 4, 0) && callIfFuncAndRightArgs(equal, 4, 11, p, callIfFuncAndRightArgs(pair, 4, 20, 1, 3));\\"); - native.globals.variables.set(\\"p\\", { + globals.variables.set(\\"p\\", { kind: \\"let\\", - value: p, + getValue: () => { + return p; + }, assignNewValue: function (unique) { - return p = this.value = unique; + return p = unique; } }); - native.globals.variables.set(\\"q\\", { + globals.variables.set(\\"q\\", { kind: \\"const\\", - value: q + getValue: () => { + return q; + } }); } } @@ -2047,6 +2104,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -2081,6 +2139,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/stdlib/__tests__/__snapshots__/misc.ts.snap b/src/stdlib/__tests__/__snapshots__/misc.ts.snap index 6a54a45af..6f6c5c756 100644 --- a/src/stdlib/__tests__/__snapshots__/misc.ts.snap +++ b/src/stdlib/__tests__/__snapshots__/misc.ts.snap @@ -164,6 +164,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -198,6 +199,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -232,6 +234,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/stdlib/__tests__/__snapshots__/parser.ts.snap b/src/stdlib/__tests__/__snapshots__/parser.ts.snap index 7c9550069..c76976547 100644 --- a/src/stdlib/__tests__/__snapshots__/parser.ts.snap +++ b/src/stdlib/__tests__/__snapshots__/parser.ts.snap @@ -55,6 +55,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -120,6 +121,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -186,6 +188,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -236,6 +239,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -272,6 +276,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -409,6 +414,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -473,6 +479,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -535,6 +542,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -638,6 +646,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -682,6 +691,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -842,6 +852,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -915,6 +926,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -983,6 +995,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1051,6 +1064,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1087,6 +1101,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -1132,6 +1147,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/stdlib/__tests__/__snapshots__/stream.ts.snap b/src/stdlib/__tests__/__snapshots__/stream.ts.snap index c3534fbc8..e500bc8ad 100644 --- a/src/stdlib/__tests__/__snapshots__/stream.ts.snap +++ b/src/stdlib/__tests__/__snapshots__/stream.ts.snap @@ -20,6 +20,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -54,6 +55,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -88,6 +90,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -122,6 +125,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -160,6 +164,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -198,6 +203,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -207,11 +213,13 @@ let lastStatementResult = undefined; sum = binaryOp(\\"+\\", sum, x, 3, 8); }, \\"x => {\\\\n sum = sum + x;\\\\n}\\"), callIfFuncAndRightArgs(stream, 4, 3, 1, 2, 3)); lastStatementResult = eval(\\"sum;\\"); - native.globals.variables.set(\\"sum\\", { + globals.variables.set(\\"sum\\", { kind: \\"let\\", - value: sum, + getValue: () => { + return sum; + }, assignNewValue: function (unique) { - return sum = this.value = unique; + return sum = unique; } }); } @@ -243,6 +251,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -277,6 +286,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -313,6 +323,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -347,6 +358,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -384,6 +396,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -397,13 +410,17 @@ let lastStatementResult = undefined; setProp(result, callIfFuncAndRightArgs(array_length, 3, 32, result), item, 3, 25); }, \\"item => {\\\\n result[array_length(result)] = item;\\\\n}\\"), s); lastStatementResult = eval(\\"boolOrErr(boolOrErr(binaryOp(\\\\\\"===\\\\\\", callIfFuncAndRightArgs(callIfFuncAndRightArgs(stream_ref, 4, 0, s, 4), 4, 0, 22), 22, 4, 0), 4, 0) && binaryOp(\\\\\\"===\\\\\\", callIfFuncAndRightArgs(callIfFuncAndRightArgs(stream_ref, 4, 30, s, 7), 4, 30, callIfFuncAndRightArgs(pair, 4, 46, '', '1')), '1', 4, 30), 4, 0) && result;\\"); - native.globals.variables.set(\\"s\\", { + globals.variables.set(\\"s\\", { kind: \\"const\\", - value: s + getValue: () => { + return s; + } }); - native.globals.variables.set(\\"result\\", { + globals.variables.set(\\"result\\", { kind: \\"const\\", - value: result + getValue: () => { + return result; + } }); } } @@ -437,6 +454,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -471,6 +489,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -505,6 +524,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -557,6 +577,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -594,6 +615,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -628,6 +650,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -662,6 +685,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -697,6 +721,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { @@ -734,6 +759,7 @@ const throwIfTimeout = native.operators.get(\\"throwIfTimeout\\"); const setProp = native.operators.get(\\"setProp\\"); const getProp = native.operators.get(\\"getProp\\"); let lastStatementResult = undefined; +const globals = $NATIVE_STORAGE.globals; (( ) => { return (() => { { diff --git a/src/transpiler.ts b/src/transpiler.ts index b3de6ad6b..b00c71ec8 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -15,8 +15,6 @@ import { ConstAssignment, UndefinedVariable } from './interpreter-errors' * There should be an explanation on it coming up soon. */ -type StorageLocations = 'globals' | 'operators' - interface ValueWrapper { kind: AllowedDeclarations value: Value @@ -59,28 +57,11 @@ const globalIds = { throwIfTimeout: create.identifier('dummy'), setProp: create.identifier('dummy'), getProp: create.identifier('dummy'), - lastStatementResult: create.identifier('dummy') + lastStatementResult: create.identifier('dummy'), + globals: create.identifier('dummy') } let contextId: number -function createStorageLocationAstFor(type: StorageLocations): es.MemberExpression { - return create.memberExpression( - { - type: 'MemberExpression', - object: globalIds.native, - property: create.literal(contextId), - computed: true - }, - type - ) -} - -function createGetFromStorageLocationAstFor(name: string, type: StorageLocations): es.Expression { - return create.callExpression(create.memberExpression(createStorageLocationAstFor(type), 'get'), [ - create.literal(name) - ]) -} - function createStatementAstToStoreBackCurrentlyDeclaredGlobal( name: string, kind: AllowedDeclarations @@ -89,7 +70,10 @@ function createStatementAstToStoreBackCurrentlyDeclaredGlobal( const variableIdentifier = create.identifier(name) const properties = [ create.property('kind', create.literal(kind)), - create.property('value', variableIdentifier) + create.property( + 'getValue', + create.blockArrowFunction([], [create.returnStatement(variableIdentifier)]) + ) ] if (kind === 'let') { properties.push( @@ -97,27 +81,14 @@ function createStatementAstToStoreBackCurrentlyDeclaredGlobal( 'assignNewValue', create.functionExpression( [paramName], - [ - create.returnStatement( - create.assignmentExpression( - variableIdentifier, - create.assignmentExpression( - create.memberExpression({ type: 'ThisExpression' }, 'value'), - paramName - ) - ) - ) - ] + [create.returnStatement(create.assignmentExpression(variableIdentifier, paramName))] ) ) ) } return create.expressionStatement( create.callExpression( - create.memberExpression( - create.memberExpression(createStorageLocationAstFor('globals'), 'variables'), - 'set' - ), + create.memberExpression(create.memberExpression(globalIds.globals, 'variables'), 'set'), [create.literal(name), create.objectExpression(properties)] ) ) @@ -130,16 +101,19 @@ function wrapWithPreviouslyDeclaredGlobals(statements: es.Statement[]) { while (currentVariableScope !== null) { const initialisingStatements: es.Statement[] = [] currentVariableScope.variables.forEach(({ kind }: ValueWrapper, name: string) => { - let unwrappedValueAst: es.Expression = createStorageLocationAstFor('globals') + let unwrappedValueAst: es.Expression = globalIds.globals for (let i = 0; i < timesToGoUp; i += 1) { unwrappedValueAst = create.memberExpression(unwrappedValueAst, 'previousScope') } - unwrappedValueAst = create.memberExpression( - create.callExpression( - create.memberExpression(create.memberExpression(unwrappedValueAst, 'variables'), 'get'), - [create.literal(name)] + unwrappedValueAst = create.callExpression( + create.memberExpression( + create.callExpression( + create.memberExpression(create.memberExpression(unwrappedValueAst, 'variables'), 'get'), + [create.literal(name)] + ), + 'getValue' ), - 'value' + [] ) initialisingStatements.push(create.declaration(name, kind, unwrappedValueAst)) }) @@ -308,20 +282,26 @@ export function checkForUndefinedVariablesAndTransformAssignmentsToPropagateBack skipErrors = false ) { const globalEnvironment = NATIVE_STORAGE[contextId].globals - const previousVariablesToTimesGoneUp = new Map< + const previousVariablesToAst = new Map< string, - { isConstant: boolean; timesGoneUp: number } + { isConstant: boolean; variableLocationId: es.Expression } >() let variableScope = globalEnvironment - let timesGoneUp = 0 + let variableScopeId: es.Expression = globalIds.globals while (variableScope !== null) { for (const [name, { kind }] of variableScope.variables) { - if (!previousVariablesToTimesGoneUp.has(name)) { - previousVariablesToTimesGoneUp.set(name, { isConstant: kind === 'const', timesGoneUp }) + if (!previousVariablesToAst.has(name)) { + previousVariablesToAst.set(name, { + isConstant: kind === 'const', + variableLocationId: create.callExpression( + create.memberExpression(create.memberExpression(variableScopeId, 'variables'), 'get'), + [create.literal(name)] + ) + }) } } variableScope = variableScope.previousScope - timesGoneUp += 1 + variableScopeId = create.memberExpression(variableScopeId, 'previousScope') } const identifiersIntroducedByNode = new Map>() function processBlock(node: es.Program | es.BlockStatement, ancestors: es.Node[]) { @@ -381,32 +361,66 @@ export function checkForUndefinedVariablesAndTransformAssignmentsToPropagateBack identifiersIntroducedByNode.get(ancestor)!.has(name) ) if (!isCurrentlyDeclared) { - if (previousVariablesToTimesGoneUp.has(name)) { + if (previousVariablesToAst.has(name)) { const lastAncestor: es.Node = ancestors[ancestors.length - 2] - // if this is an assignment expression, we want to propagate back the change + const { isConstant, variableLocationId } = previousVariablesToAst.get(name)! if (lastAncestor.type === 'AssignmentExpression') { - const { isConstant, timesGoneUp } = previousVariablesToTimesGoneUp.get(name)! + // if this is an assignment expression, we want to propagate back the change if (isConstant) { throw new ConstAssignment(identifier, name) } else { - let variableScope: es.Expression = createStorageLocationAstFor('globals') - for (let i = 0; i < timesGoneUp; i += 1) { - variableScope = create.memberExpression(variableScope, 'previousScope') - } lastAncestor.right = create.callExpression( - create.memberExpression( - create.callExpression( - create.memberExpression( - create.memberExpression(variableScope, 'variables'), - 'get' - ), - [create.literal(name)] - ), - 'assignNewValue' - ), + create.memberExpression(variableLocationId, 'assignNewValue'), [lastAncestor.right] ) } + } else { + /** + * if this is not the left side of an assignment expression, we need to replace this with + * the actual value stored in the correct scope, as calling functions defined in a + * previous block might have side effects that change the variable. + * e.g. + * // first eval: + * let counter = 0; + * function f() { + * counter = counter + 1; + * } + * becomes + * let counter = 0; + * function f() { + * counter = counter + 1; + * } + * variables.set("counter", getValue: ()=>counter, assignNewValue: newValue => counter = newValue); + * // second eval (wrong): + * f(); counter; + * becomes + * let counter = variables.get("counter").getValue(); // set back counter; + * { + * f(); // this has a side effect of incrementing counter + * return counter; // that does not get propagated here + * } + * // second eval (fixed): + * f(); counter; + * becomes + * let counter = variables.get("counter").getValue(); // set back counter; + * { + * f(); // this has a side effect of incrementing counter + * return (counter = variables.get("counter").getValue()); // we have no choice but to + * // always assume that counter is updated through a side effect and always retrieve its + * // real value + * } + */ + if (!isConstant) { + // if it is a constant, it will definitely not mutate so above change is not needed + const toExpression: es.AssignmentExpression = (identifier as unknown) as es.AssignmentExpression + toExpression.type = 'AssignmentExpression' + toExpression.operator = '=' + toExpression.left = create.identifier(name) + toExpression.right = create.callExpression( + create.memberExpression(variableLocationId, 'getValue'), + [] + ) + } } } else if (!nativeInternalNames.has(name)) { if (!skipErrors) { @@ -679,8 +693,32 @@ function getDeclarationsToAccessTranspilerInternals(): es.VariableDeclaration[] } else if (key === 'lastStatementResult') { value = create.primitive(undefined) kind = 'let' + } else if (key === 'globals') { + value = create.memberExpression( + { + type: 'MemberExpression', + object: create.identifier(GLOBAL_KEY_TO_ACCESS_NATIVE_STORAGE), + property: create.literal(contextId), + computed: true + }, + 'globals' + ) } else { - value = createGetFromStorageLocationAstFor(name, 'operators') + value = create.callExpression( + create.memberExpression( + create.memberExpression( + { + type: 'MemberExpression', + object: globalIds.native, + property: create.literal(contextId), + computed: true + }, + 'operators' + ), + 'get' + ), + [create.literal(name)] + ) } return create.declaration(name, kind, value) }) diff --git a/src/utils/evalContainer.ts b/src/utils/evalContainer.ts index 011811eb3..bff40bb0e 100644 --- a/src/utils/evalContainer.ts +++ b/src/utils/evalContainer.ts @@ -1,6 +1,5 @@ /* tslint:disable */ export const sandboxedEval = (code: string) => { const evalInGlobalScope = eval - // console.log(code) return evalInGlobalScope(code) } diff --git a/src/utils/testing.ts b/src/utils/testing.ts index 21259ebfd..725990d53 100644 --- a/src/utils/testing.ts +++ b/src/utils/testing.ts @@ -35,7 +35,7 @@ interface TestOptions { native?: boolean } -function createTestContext({ +export function createTestContext({ context, chapter = 1, testBuiltins = {} @@ -104,10 +104,11 @@ async function testInContext(code: string, options: TestOptions): Promise )') // replace declaration of builtins since they're repetitive const replacedBuiltins = replacedGlobalsLine.replace( - /\n const \w+ = native\.globals\.(previousScope.)+variables.get\("\w+"\)\.value;/g, + /\n const \w+ = globals\.(previousScope.)+variables.get\("\w+"\)\.getValue\(\);/g, '' ) - transpiled = replacedBuiltins + // replace the line globals = $$NATIVE_STORAGE[xxx].globals to remove [xxx] + transpiled = replacedBuiltins.replace(/\$\$NATIVE_STORAGE\[\d+]/, '$$NATIVE_STORAGE') } catch { transpiled = 'parseError' }