This repo contains programs written in Source, developed for SICP JS and other educational projects.
All programs in this repository are runnable in the Source Academy playground: copy the program into the editor, choose "Source §4", and press "Run".
The evaluators in this section all follow the general style of SICP JS Chapter 4.
src/evaluators/source-0.js
: evaluator for Source §0 (calculator language)Some classic problems, solved in Source.
src/classics/permutations.js
: permutations of a listsrc/classics/sorting_lists.js
: some list sorting functionssrc/classics/subsets.js
: compute all subsets of a listThe steppers in this section implement a small-step semantics, following the substitution model of SICP JS Chapter 1 and 2.
src/steppers/source-0.js
: stepper for Source §0The type checkers in this section follow a rule-based static semantics available in doc/type-checking.pdf.
src/type-checkers/source-0.js
: type checker for Source §0The virtual machines in this section are SECD-style and follow a description in doc/virtual-machines.pdf. Each virtual machine comes with a compiler, implemented in the same file.
src/virtual-machines/source-0.js
: virtual machine for Source §0 (calculator language)(click to run; for actual sources, go to src/tool-demos/
)
src/tool-demos/stepper.js
: stepper tool (small-step semantics, based on substitution)src/tool-demos/box-and-pointer-diagrams.js
: box-and-pointer diagram visualizer for pairs and lists (following SICP JS chapter 2)src/tool-demos/environment-model.js
: environment model visualizer (following SICP JS chapter 3)(click to run; for actual sources, go to src/module-demos/
)
src/module-demos/runes.js
: the "picture language" of SICP JS 2.2.4src/module-demos/twist.js
: some fun with the "picture language"src/module-demos/curves.js
: a "curves" library for drawing curves with functional programmingsrc/module-demos/times.js
: visual times tables using the "curves" librarysrc/module-demos/sounds.js
: a "sounds" library for generating sounds and music, starting from their constituent sine wavessrc/module-demos/bohemian.js
: Bohemian Rhapsody cover using the "sounds" librarysrc/test/framework/main.js
: test framework for Source programs, written in Source §4[requires bash (any version) and awk (BSD awk 20070501); does not work with gawk]
For testing your Source programs, you need node
and yarn
.
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
.
Only the tests written will be run.
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:
parse_and_evaluate("! (1 === 1 && 2 > 3);");
// true
Before you can run the tests, you need to install js-slang
by typing:
% yarn
% yarn install
Run all test cases by typing:
% yarn test
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
Line 2073: Error: memory exhausted despite garbage collection undefined
can be written in the test file:
// Line 2073: Error: memory exhausted despite garbage collection undefined
or
// 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.
Integration of the
test
script withsrc/test/framework/
is pending a fix to the--variant
parameter; any help appreciated.
All JavaScript programs in this repository are licensed under the GNU General Public License Version 3.