-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the CSET machine, along with macros (#1728)
* add prelimiary framework for macro system * Allow Scheme data types as part of control * add functionality to scheme eval metaprocedure * update macro skeleton * add pattern matching system prototype * complete first iteration of pattern matching functions * finish first implementation of pattern matcher * update tests for call/cc * complete CSEP machine behaviour for standard syntax forms * add tags to modified estree nodes, and deparser * fix pattern matching logic * allow let, cond, etc... to be defined in the prelude * allow runtime checks for basic forms * remove hack of storing scheme lists in estree nodes * fix behaviour of ... in macros * fix tests with scheme * undo fix tests with scheme * reduce strictness of scm-slang parser for FULL_SCHEME * add more error-checking for CSEP machine * add tests for CSEP machine and macros * rename csep machine to cset machine * implement the macro environment * improve behaviour of CSET machine * fix formatting issues * Clean up helper functions * create apply metaprocedure * add tests for base cset machine and apply * add named let to scheme prelude --------- Co-authored-by: Kyriel Abad <[email protected]>
- Loading branch information
Showing
28 changed files
with
3,137 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule scm-slang
updated
18 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/cse-machine/__tests__/__snapshots__/cset-machine-apply.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`eval of strings: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval \\"hello\\") | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": "hello", | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`incorrect use of apply throws error (insufficient arguments): expectParsedError 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(apply) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 1, | ||
"parsedErrors": "Expected 2 arguments, but got 0.", | ||
"result": undefined, | ||
"resultStatus": "error", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`incorrect use of apply throws error (last argument not a list): expectParsedError 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(apply + 1 2 3) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 1, | ||
"parsedErrors": "Error: Last argument of apply must be a list", | ||
"result": undefined, | ||
"resultStatus": "error", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`multi-operand apply: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(define args '(1 2 3 4 5)) | ||
(apply + 6 7 8 9 10 args) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 55n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`two-operand apply: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(define args '(1 2)) | ||
(apply + args) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 3n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; |
224 changes: 224 additions & 0 deletions
224
src/cse-machine/__tests__/__snapshots__/cset-machine-eval.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`eval of application: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(+ 1 2)) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 3n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of begin: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(begin 1 2 3)) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 3n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of booleans: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval #t) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": true, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of define: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(define x 1)) | ||
x | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of empty list: expectParsedError 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '()) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 1, | ||
"parsedErrors": "Error: Cannot evaluate null", | ||
"result": undefined, | ||
"resultStatus": "error", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of if: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(if #t 1 2)) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of lambda: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(lambda (x) x)) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": [Function], | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of numbers: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval 1) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of quote: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval '(quote (1 2 3))) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": Array [ | ||
SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
Array [ | ||
SchemeInteger { | ||
"numberType": 1, | ||
"value": 2n, | ||
}, | ||
Array [ | ||
SchemeInteger { | ||
"numberType": 1, | ||
"value": 3n, | ||
}, | ||
null, | ||
], | ||
], | ||
], | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
|
||
exports[`eval of set!: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(define x 2) | ||
(eval '(set! x 1)) | ||
x | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
exports[`eval of strings: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(eval \\"hello\\") | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": "hello", | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; | ||
exports[`eval of symbols: expectResult 1`] = ` | ||
Object { | ||
"alertResult": Array [], | ||
"code": " | ||
(define hello 1) | ||
(eval 'hello) | ||
", | ||
"displayResult": Array [], | ||
"numErrors": 0, | ||
"parsedErrors": "", | ||
"result": SchemeInteger { | ||
"numberType": 1, | ||
"value": 1n, | ||
}, | ||
"resultStatus": "finished", | ||
"visualiseListResult": Array [], | ||
} | ||
`; |
Oops, something went wrong.