Skip to content

Commit

Permalink
Fix let (requires prelude to be merged first) (BREAKING CHANGE) (#321)
Browse files Browse the repository at this point in the history
* Add prelude, that predeclares Source-implementable functions

List and stream functions that can be implemented in Source
now are put in the prelude, and are no longer native JS functions.

* Update tests

* Add tests for stream

* Add tests for stream

* Add tests for stream

* Fix bug where mutating variables in a outer scope didn't work properly

* Make mutating let variables in outer scopes propagate properly

* Order imports

* Remove redundant assigning for constant

* Revert yarn.lock

* Remove inconsistent snapshot

* Add check for undefined variables too

* Update tests
  • Loading branch information
openorclose authored and martin-henz committed Aug 6, 2019
1 parent 8739509 commit 492e486
Show file tree
Hide file tree
Showing 28 changed files with 23,673 additions and 3,557 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
*.js
!*.prelude.js
*.map
dist/

Expand Down
25 changes: 20 additions & 5 deletions src/__tests__/__snapshots__/allowed-syntax.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,10 @@ let lastStatementResult = undefined;
lastStatementResult = eval(\\"i;\\");
native.globals.variables.set(\\"i\\", {
kind: \\"let\\",
value: i
value: i,
assignNewValue: function (unique) {
return i = this.value = unique;
}
});
native.globals.variables.set(\\"startTime\\", {
kind: \\"const\\",
Expand Down Expand Up @@ -3899,7 +3902,10 @@ let lastStatementResult = undefined;
lastStatementResult = eval(\\"i;\\");
native.globals.variables.set(\\"i\\", {
kind: \\"let\\",
value: i
value: i,
assignNewValue: function (unique) {
return i = this.value = unique;
}
});
native.globals.variables.set(\\"startTime\\", {
kind: \\"const\\",
Expand Down Expand Up @@ -5356,7 +5362,10 @@ let lastStatementResult = undefined;
lastStatementResult = eval(\\"i;\\");
native.globals.variables.set(\\"i\\", {
kind: \\"let\\",
value: i
value: i,
assignNewValue: function (unique) {
return i = this.value = unique;
}
});
native.globals.variables.set(\\"startTime\\", {
kind: \\"const\\",
Expand Down Expand Up @@ -6325,7 +6334,10 @@ let lastStatementResult = undefined;
lastStatementResult = eval(\\"getProp(x, 1, 2, 0);\\");
native.globals.variables.set(\\"x\\", {
kind: \\"let\\",
value: x
value: x,
assignNewValue: function (unique) {
return x = this.value = unique;
}
});
}
}
Expand Down Expand Up @@ -6818,7 +6830,10 @@ let lastStatementResult = undefined;
lastStatementResult = eval(\\"setProp(x, 1, 4, 2, 0);\\");
native.globals.variables.set(\\"x\\", {
kind: \\"let\\",
value: x
value: x,
assignNewValue: function (unique) {
return x = this.value = unique;
}
});
}
}
Expand Down
59 changes: 11 additions & 48 deletions src/__tests__/__snapshots__/environment.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,22 @@ Array [
"head": Object {
"Infinity": Infinity,
"NaN": NaN,
"accumulate": [Function],
"append": [Function],
"apply_in_underlying_javascript": [Function],
"array_length": [Function],
"build_list": [Function],
"display": [Function],
"draw_data": [Function],
"enum_list": [Function],
"equal": [Function],
"error": [Function],
"filter": [Function],
"for_each": [Function],
"head": [Function],
"is_array": [Function],
"is_boolean": [Function],
"is_function": [Function],
"is_list": [Function],
"is_null": [Function],
"is_number": [Function],
"is_pair": [Function],
"is_string": [Function],
"is_undefined": [Function],
"length": [Function],
"list": [Function],
"list_ref": [Function],
"list_to_string": [Function],
"map": [Function],
"list_to_stream": [Function],
"math_E": 2.718281828459045,
"math_LN10": 2.302585092994046,
"math_LN2": 0.6931471805599453,
Expand Down Expand Up @@ -125,18 +114,16 @@ Array [
"math_tan": [Function],
"math_tanh": [Function],
"math_trunc": [Function],
"member": [Function],
"pair": [Function],
"parse": [Function],
"parse_int": [Function],
"prompt": [Function],
"raw_display": [Function],
"remove": [Function],
"remove_all": [Function],
"reverse": [Function],
"runtime": [Function],
"set_head": [Function],
"set_tail": [Function],
"stream": [Function],
"stream_tail": [Function],
"stringify": [Function],
"tail": [Function],
"undefined": undefined,
Expand All @@ -162,6 +149,7 @@ Array [
"externalContext": undefined,
"externalSymbols": Array [],
"numberOfOuterEnvironments": 2,
"prelude": null,
"runtime": Object {
"break": false,
"debuggerOn": true,
Expand Down Expand Up @@ -547,33 +535,22 @@ Array [
"head": Object {
"Infinity": Infinity,
"NaN": NaN,
"accumulate": [Function],
"append": [Function],
"apply_in_underlying_javascript": [Function],
"array_length": [Function],
"build_list": [Function],
"display": [Function],
"draw_data": [Function],
"enum_list": [Function],
"equal": [Function],
"error": [Function],
"filter": [Function],
"for_each": [Function],
"head": [Function],
"is_array": [Function],
"is_boolean": [Function],
"is_function": [Function],
"is_list": [Function],
"is_null": [Function],
"is_number": [Function],
"is_pair": [Function],
"is_string": [Function],
"is_undefined": [Function],
"length": [Function],
"list": [Function],
"list_ref": [Function],
"list_to_string": [Function],
"map": [Function],
"list_to_stream": [Function],
"math_E": 2.718281828459045,
"math_LN10": 2.302585092994046,
"math_LN2": 0.6931471805599453,
Expand Down Expand Up @@ -617,18 +594,16 @@ Array [
"math_tan": [Function],
"math_tanh": [Function],
"math_trunc": [Function],
"member": [Function],
"pair": [Function],
"parse": [Function],
"parse_int": [Function],
"prompt": [Function],
"raw_display": [Function],
"remove": [Function],
"remove_all": [Function],
"reverse": [Function],
"runtime": [Function],
"set_head": [Function],
"set_tail": [Function],
"stream": [Function],
"stream_tail": [Function],
"stringify": [Function],
"tail": [Function],
"undefined": undefined,
Expand All @@ -654,6 +629,7 @@ Array [
"externalContext": undefined,
"externalSymbols": Array [],
"numberOfOuterEnvironments": 2,
"prelude": null,
"runtime": Object {
"break": false,
"debuggerOn": true,
Expand Down Expand Up @@ -1032,33 +1008,22 @@ Array [
"head": Object {
"Infinity": Infinity,
"NaN": NaN,
"accumulate": [Function],
"append": [Function],
"apply_in_underlying_javascript": [Function],
"array_length": [Function],
"build_list": [Function],
"display": [Function],
"draw_data": [Function],
"enum_list": [Function],
"equal": [Function],
"error": [Function],
"filter": [Function],
"for_each": [Function],
"head": [Function],
"is_array": [Function],
"is_boolean": [Function],
"is_function": [Function],
"is_list": [Function],
"is_null": [Function],
"is_number": [Function],
"is_pair": [Function],
"is_string": [Function],
"is_undefined": [Function],
"length": [Function],
"list": [Function],
"list_ref": [Function],
"list_to_string": [Function],
"map": [Function],
"list_to_stream": [Function],
"math_E": 2.718281828459045,
"math_LN10": 2.302585092994046,
"math_LN2": 0.6931471805599453,
Expand Down Expand Up @@ -1102,18 +1067,16 @@ Array [
"math_tan": [Function],
"math_tanh": [Function],
"math_trunc": [Function],
"member": [Function],
"pair": [Function],
"parse": [Function],
"parse_int": [Function],
"prompt": [Function],
"raw_display": [Function],
"remove": [Function],
"remove_all": [Function],
"reverse": [Function],
"runtime": [Function],
"set_head": [Function],
"set_tail": [Function],
"stream": [Function],
"stream_tail": [Function],
"stringify": [Function],
"tail": [Function],
"undefined": undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/__snapshots__/index.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,11 @@ Object {
"code": "function f(x) {
return 5;
}
toString(a=>b) + toString(f);",
toString(a=>a) + toString(f);",
"displayResult": Array [],
"errors": Array [],
"parsedErrors": "",
"result": "a => bfunction f(x) {
"result": "a => afunction f(x) {
return 5;
}",
"resultStatus": "finished",
Expand All @@ -906,7 +906,7 @@ let lastStatementResult = undefined;
value: 5
};
}, \\"function f(x) {\\\\n return 5;\\\\n}\\");
lastStatementResult = eval(\\"binaryOp(\\\\\\"+\\\\\\", callIfFuncAndRightArgs(toString, 4, 0, wrap(a => ({ isTail: false, value: b }), \\\\\\"a => b\\\\\\")), callIfFuncAndRightArgs(toString, 4, 17, f), 4, 0);\\");
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\\", {
kind: \\"const\\",
value: f
Expand Down

0 comments on commit 492e486

Please sign in to comment.