Skip to content

Commit 5509075

Browse files
authored
Merge pull request #24 from xllx1/non-det-meta-circular-evaluator
Add test for src/evaluators/source-4-3.js
2 parents adcd860 + ac14e01 commit 5509075

File tree

7 files changed

+83
-29
lines changed

7 files changed

+83
-29
lines changed

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env bash
22

3-
JS_SLANG="node node_modules/js-slang/dist/repl/repl.js"
3+
JS_SLANG="node --stack-size=2000 node_modules/js-slang/dist/repl/repl.js"
44

55
# must use BSD awk
66
AWK="awk"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parse_and_run('function a(){const b = 2; return b;} a();');
2+
// 2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parse_and_run('function factorial(n) {\n' +
2+
' return n === 1\n' +
3+
' ? 1\n' +
4+
' : factorial(n - 1) * n;\n' +
5+
'}' +
6+
'factorial(4);');
7+
// 24
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parse_and_run('function x() {\n' +
2+
' let a = 1;\n' +
3+
' return a;\n' +
4+
' a = 2;\n' +
5+
'}\n' +
6+
'x();');
7+
// 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parse_and_run("function foo() {\
2+
return 5;\
3+
}\
4+
foo();");
5+
// 5
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const result = parse_and_run(" \
2+
function multiple_dwelling() { \
3+
const baker = amb(1, 2, 3, 4, 5); \
4+
const cooper = amb(1, 2, 3, 4, 5); \
5+
const fletcher = amb(1, 2, 3, 4, 5); \
6+
const miller = amb(1, 2, 3, 4, 5); \
7+
const smith = amb(1, 2, 3, 4, 5); \
8+
require(distinct(list(baker, cooper, fletcher, miller, smith))); \
9+
require(! (baker === 5)); \
10+
require(! (cooper === 1)); \
11+
require(! (fletcher === 5)); \
12+
require(! (fletcher === 1)); \
13+
require(! (miller > cooper)); \
14+
require(! ((math_abs(smith - fletcher)) === 1)); \
15+
require(! ((math_abs(fletcher - cooper)) === 1)); \
16+
return list(list('baker', baker), \
17+
list('cooper', cooper), \
18+
list('fletcher', fletcher), \
19+
list('miller', miller), \
20+
list('smith', smith)); \
21+
} \
22+
multiple_dwelling(); \
23+
");
24+
25+
function print_one_line_list(li) {
26+
let result = "";
27+
for_each((s) => { result = result + head(s) + stringify(head(tail(s))) + ","; }, li);
28+
return result;
29+
}
30+
print_one_line_list(result);
31+
// 'baker1,cooper4,fletcher2,miller3,smith5,'

src/evaluators/source-4-3.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ function analyze_sequence(stmts) {
588588
a(env,
589589
(a_value, fail2) => {
590590
if (is_return_value(a_value)) {
591-
return succeed(return_value_content(a_value), fail2);
591+
return succeed(a_value, fail2);
592592
} else {
593593
return b(env, succeed, fail2);
594594
}
@@ -613,8 +613,7 @@ function analyze_sequence(stmts) {
613613
function analyze_block(stmts) {
614614
const body = block_body(stmts);
615615
const locals = local_names(body);
616-
const temp_values = map(x => no_value_yet,
617-
locals);
616+
const temp_values = map(x => no_value_yet, locals);
618617
return (env, succeed, fail) => analyze(body)(extend_environment(locals, temp_values, env), succeed, fail);
619618
}
620619

@@ -732,7 +731,6 @@ function execute_application(fun, args, succeed, fail) {
732731
function_environment(fun)),
733732
(return_value, fail2) => {
734733
if (is_return_value(return_value)) {
735-
736734
return succeed(return_value_content(return_value),fail2);
737735
} else {
738736
return succeed(undefined,fail2);
@@ -844,32 +842,36 @@ function parse_and_run(str) {
844842
// 'factorial(4);');
845843

846844
// parse_and_run('function x() {\n' +
847-
// ' const a = 1;\n' +
845+
// ' let a = 1;\n' +
848846
// ' return a;\n' +
849847
// ' a = 2;\n' +
850848
// '}\n' +
851849
// 'x();');
852850

853-
parse_and_run(" \
854-
function multiple_dwelling() { \
855-
const baker = amb(1, 2, 3, 4, 5); \
856-
const cooper = amb(1, 2, 3, 4, 5); \
857-
const fletcher = amb(1, 2, 3, 4, 5); \
858-
const miller = amb(1, 2, 3, 4, 5); \
859-
const smith = amb(1, 2, 3, 4, 5); \
860-
require(distinct(list(baker, cooper, fletcher, miller, smith))); \
861-
require(! (baker === 5)); \
862-
require(! (cooper === 1)); \
863-
require(! (fletcher === 5)); \
864-
require(! (fletcher === 1)); \
865-
require(! (miller > cooper)); \
866-
require(! ((math_abs(smith - fletcher)) === 1)); \
867-
require(! ((math_abs(fletcher - cooper)) === 1)); \
868-
return list(list('baker', baker), \
869-
list('cooper', cooper), \
870-
list('fletcher', fletcher), \
871-
list('miller', miller), \
872-
list('smith', smith)); \
873-
} \
874-
multiple_dwelling(); \
875-
");
851+
// parse_and_run("function foo() {\
852+
// return 5;\
853+
// }\
854+
// foo();");
855+
// parse_and_run(" \
856+
// function multiple_dwelling() { \
857+
// const baker = amb(1, 2, 3, 4, 5); \
858+
// const cooper = amb(1, 2, 3, 4, 5); \
859+
// const fletcher = amb(1, 2, 3, 4, 5); \
860+
// const miller = amb(1, 2, 3, 4, 5); \
861+
// const smith = amb(1, 2, 3, 4, 5); \
862+
// require(distinct(list(baker, cooper, fletcher, miller, smith))); \
863+
// require(! (baker === 5)); \
864+
// require(! (cooper === 1)); \
865+
// require(! (fletcher === 5)); \
866+
// require(! (fletcher === 1)); \
867+
// require(! (miller > cooper)); \
868+
// require(! ((math_abs(smith - fletcher)) === 1)); \
869+
// require(! ((math_abs(fletcher - cooper)) === 1)); \
870+
// return list(list('baker', baker), \
871+
// list('cooper', cooper), \
872+
// list('fletcher', fletcher), \
873+
// list('miller', miller), \
874+
// list('smith', smith)); \
875+
// } \
876+
// multiple_dwelling(); \
877+
// ");

0 commit comments

Comments
 (0)