source-academy / source-programs

Notable Source programs, developed for SICP JS and other educational projects
GNU General Public License v3.0
7 stars 18 forks source link

Implement Cheney's GC for source 2 machine and Add tests #14

Closed moziliar closed 4 years ago

moziliar commented 4 years ago

Implemented Cheney's GC

Update on environment frames: Instead of copying the enclosing environment frame and adding onto it, this implementation creates environment frames by creating fresh new frames and reimplements how LD works in the VM by including an index of the number of frames to look up to load the name.

moziliar commented 4 years ago

Fixes:

  1. Fixed the error in environment extension which used to point the parent environment to the current environment, not the one in the current closure as suggested in the lecture note.

  2. Fixed the issue in the test script where all the files in the folder with /__test__/ folder present will force the tests. (can be removed in the future if full test suite is demanded from all the source-programs)

Updates:

Changed the display of the VM output for source-2.js and source-2-with-copying-gc.js to be test-compatible. It now only outputs result: heap node of type = [TYPE], value = [VALUE] directly, with trailing GC count if the VM comes with GC, e.g. result: heap node of type = pair, value = [1,[2,[3,[4,null]]]]; GC count: 0

moziliar commented 4 years ago

Note: Not using --variant param as it is not compatible yet.