You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-3Lines changed: 75 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,13 @@ All programs in this repository are runnable in the [Source Academy playground](
6
6
7
7
## Evaluators
8
8
9
-
The evaluators in this section all follow the general style of SICP JS Section 4.1.
9
+
The evaluators in this section all follow the general style of SICP JS Chapter 4.
10
10
11
11
*[`src/evaluators/source-0.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/source-0.js): evaluator for Source §0 (calculator language)
12
12
*[`src/evaluators/source-0pp.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/source-0pp.js): evaluator for Source §0++ (calculator language plus conditionals, blocks and sequences)
13
-
*[`src/evaluators/source-1.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/source-1.js): evaluator for Source §1
13
+
*[`src/evaluators/source-4-1.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/source-4-1.js): evaluator for Source §1, described in SICP JS 4.1
14
14
*[`src/evaluators/typed-source.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/typed-source.js): evaluator for Typed Source (typed version of a Source §1 sublanguage)
15
+
*[`src/evaluators/source-4-3.js`](https://github.com/source-academy/source-programs/blob/master/src/evaluators/source-4-3.js): meta-circular evaluator for Source §4.3 (non-deterministic programming)
15
16
16
17
## Steppers
17
18
@@ -36,14 +37,21 @@ The virtual machines in this section are SECD-style and follow a description in
36
37
*[`src/virtual-machines/source-1.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/source-1.js): virtual machine for a Source §1 sublanguage (without memory management)
37
38
*[`src/virtual-machines/source-1-with-copying-gc.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/source-1-with-copying-gc.js): virtual machine for a Source §1 sublanguage with a Cheney-style stop-and-copy garbage collector
38
39
*[`src/virtual-machines/register-machine-gcd.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/register-machine-gcd.js): register machine following SICP JS Section 5.2, using GCD example
40
+
*[`src/virtual-machines/source-2.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/source-2.js): virtual machine for a Source §2 sublanguage (without memory management)
41
+
*[`src/virtual-machines/source-2-with-copying-gc.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/source-2-with-copying-gc.js): virtual machine for a Source §2 sublanguage with a Cheney-style stop-and-copy garbage collector
42
+
*[`src/virtual-machines/source-2-with-ms-gc.js`](https://github.com/source-academy/source-programs/blob/master/src/virtual-machines/source-2-with-ms-gc.js): virtual machine for a Source §2 sublanguage with a Mark-and-Sweep-style garbage collector
39
43
40
44
## Tool Demos
41
45
46
+
(click to run; for actual sources, go to [`src/tool-demos/`](https://github.com/source-academy/source-programs/blob/master/src/tool-demos/))
47
+
42
48
*[`src/tool-demos/stepper.js`](https://tinyurl.com/SICPJS-stepper): stepper tool (small-step semantics, based on substitution)
43
49
*[`src/tool-demos/box-and-pointer-diagrams.js`](https://tinyurl.com/SICPJS-box-and-pointer): box-and-pointer diagram visualizer for pairs and lists (following SICP JS chapter 2)
44
50
*[`src/tool-demos/environment-model.js`](https://tinyurl.com/SICPJS-env-diagram): environment model visualizer (following SICP JS chapter 3)
45
51
46
-
## Library Demos
52
+
## Module Demos
53
+
54
+
(click to run; for actual sources, go to [`src/module-demos/`](https://github.com/source-academy/source-programs/blob/master/src/module-demos/))
47
55
48
56
*[`src/module-demos/runes.js`](https://tinyurl.com/SICPJS-hearts): the "picture language" of SICP JS 2.2.4
49
57
*[`src/module-demos/twist.js`](https://tinyurl.com/SICPJS-twist): some fun with the "picture language"
@@ -53,4 +61,68 @@ The virtual machines in this section are SECD-style and follow a description in
53
61
*[`src/module-demos/bohemian.js`](https://tinyurl.com/SICPJS-rhapsody): Bohemian Rhapsody cover using the "sounds" library
54
62
*[`src/module-demos/pix-n-flix.js`](https://tinyurl.com/SICP-distortion): a library for image and video processing, based on the constituent pixels
55
63
64
+
## Test framework
65
+
*[`src/test/framework/main.js`](https://github.com/source-academy/source-programs/blob/master/src/test/framework/): test framework for Source programs, written in Source §4
66
+
67
+
# Testing
68
+
69
+
[requires bash (any version) and awk (BSD awk 20070501); does not work with gawk]
70
+
71
+
For testing your Source programs, you need `node` and `yarn`.
72
+
73
+
Write your test cases in a folder `__tests__` in each `src` subfolder. The name of the file specifies the targeted Source of your test case. For example, if `src/steppers/source-0.js` is the Source, a test case might be `src/steppers/__tests__/source-0.test1.js`.
74
+
75
+
Only the tests written will be run.
76
+
77
+
Each test case is appended to your Source, and then run with `js-slang` (using Source §4). The last line of the test case is a `//` comment that must contain the expected result. For example, a stepper test case may be:
78
+
79
+
```js
80
+
parse_and_evaluate("! (1 === 1 && 2 > 3);");
81
+
// true
82
+
```
83
+
84
+
Before you can run the tests, you need to install `js-slang` by typing:
85
+
86
+
```sh
87
+
% yarn
88
+
% yarn install
89
+
```
90
+
91
+
Run all test cases by typing:
92
+
93
+
```sh
94
+
% yarn test
95
+
```
96
+
97
+
For failure cases (where you program is to throw error, e.g. memory exhausted error for virtual machines), you can include the error message as per normal. The lastest JS-Slang already throws the error message explicitly, without letting the underlying TypeScript handling it. Hence, an error message
98
+
99
+
```sh
100
+
Line 2073: Error: memory exhausted despite garbage collection undefined
101
+
```
102
+
103
+
can be written in the test file:
104
+
105
+
```js
106
+
// Line 2073: Error: memory exhausted despite garbage collection undefined
where only the part that starts from `Error:` will be compared. Line number is be ignored as it varies. If line number is needed for a particular reason, it can be appended to the back.
116
+
117
+
>**Note**: for virtual machine tests, you will have to make a function that outputs a single line output without the help of any `displays()`, as the test currently only supports 1 line comparison. Help to make this generic is appreciated.
118
+
119
+
>Integration of the `test` script with `src/test/framework/` is pending a fix to the `--variant` parameter; any help appreciated.
120
+
121
+
# License
122
+
123
+
[![GPL 3][gpl3-image]][gpl3]
124
+
All JavaScript programs in this repository are licensed under the
0 commit comments