add macros to KissInterp2

This commit is contained in:
2025-11-14 13:48:45 -06:00
parent d291037059
commit e481120950
3 changed files with 12 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
(prop &mut :ReadTable endOfFileReadTable (new Map))
(prop &mut :Map<String,ReaderExpDef> identAliases (new Map))
(prop &mut :Map<String,ReaderExpDef> callAliases (new Map))
(prop &mut :Map<String,kiss.PortableMacros.PortableMacroFunction> macros (kiss.PortableMacros.builtins))
(prop :Map<String,Dynamic> globals [
=>"false" false
@@ -256,6 +257,9 @@
// Special form call
((when (specialForms.exists form) (CallExp (object def (Symbol form)) args))
((dictGet specialForms form) args cc))
// Macro call
((when (macros.exists form) (CallExp (object def (Symbol form)) args))
(evalCC ((dictGet macros form) (makeExp def) args) cc))
// Method/function call with call alias
((when (callAliases.exists name) (CallExp (object def (Symbol name)) args))
(evalCC (dictGet callAliases name) ->f

View File

@@ -46,5 +46,8 @@ class KissInterp2TestCase extends Test {
function testFor() {
_testFor();
}
function testDestructive() {
_testDestructive();
}
}

View File

@@ -58,4 +58,8 @@
(function _testFor []
(let [interp (new Interp)]
(assertEval [1 2 3] "(for i (range 3) (+ i 1))")))
(assertEval [1 2 3] "(for i (range 3) (+ i 1))")))
(function _testDestructive []
(let [interp (new Interp)]
(assertEval 5 "(let [i 2] (+= i 3) i)")))