Skip to content

Notable Source programs, developed for SICP JS and other educational projects

License

Notifications You must be signed in to change notification settings

source-academy/source-programs

Repository files navigation

Source Programs

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".

Evaluators

The evaluators in this section all follow the general style of SICP JS Chapter 4.

Classics

Some classic problems, solved in Source.

Steppers

The steppers in this section implement a small-step semantics, following the substitution model of SICP JS Chapter 1 and 2.

Type checkers

The type checkers in this section follow a rule-based static semantics available in doc/type-checking.pdf.

Virtual machines

The 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.

Tool Demos

(click to run; for actual sources, go to src/tool-demos/)

Module Demos

(click to run; for actual sources, go to src/module-demos/)

Test framework

Testing

[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 with src/test/framework/ is pending a fix to the --variant parameter; any help appreciated.

License

GPL 3 All JavaScript programs in this repository are licensed under the GNU General Public License Version 3.

About

Notable Source programs, developed for SICP JS and other educational projects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published