git » jacl.git » commit 09940cc

wip %SET

author Alan Dipert
2019-10-18 13:45:27 UTC
committer Alan Dipert
2019-10-18 13:45:27 UTC
parent 7dddd2090faf6dbba093eb24f1c352955ba2bdde

wip %SET

jacl.js +25 -4

diff --git a/jacl.js b/jacl.js
index 2a8f00f..6f9441b 100644
--- a/jacl.js
+++ b/jacl.js
@@ -229,8 +229,11 @@ class Package {
     if (!sym) {
       sym = new LispSymbol(name, this.name);
       this.symbols.set(name, sym);
+      if (this.name === 'KEYWORD') sym.setConstant();
+    }
+    if (this.name === 'KEYWORD') {
+      this.exports.add(name);
     }
-    if (this.name === 'KEYWORD') this.exports.add(name);
     return sym;
   }
   usePackage(otherPackage) {
@@ -712,9 +715,16 @@ class Reader {
 }
 
 // Special forms
-for (const s of ['%DOT', '%CALL', '%LAMBDA']) {
-  JACLPKG.intern(s);
-}
+
+const SPECIAL_FORMS = [
+  '%CALL', 
+  '%DOT',
+  '%LAMBDA',
+  '%SET',
+  '%TAGBODY'
+];
+
+for (const s of SPECIAL_FORMS) JACLPKG.intern(s); 
 
 CLPKG.intern('QUOTE').setMacro().fvalue = function(env, form, x) {
   return Cons.listOf(JACLPKG.intern('%QUOTE'), x);
@@ -884,6 +894,17 @@ const analyzeSpecials = new Map([
     Object.assign(node, analyzeBlock(bodyEnv, node, exprs));
     return node;
   }],
+  [JACLPKG.intern('%SET'), (env, parent, form) => {
+    const [, target, val] = form;
+    if (!(target instanceof LispSymbol))
+      throw new Error(`Can't assign to non-symbol`);
+    if (target.isConstant)
+      throw new Erorr(`Can't set constant`);
+    const symNode = analyze(env, null, target);
+    if (symNode.op === 'global') {
+    } else if (symNode.op === 'local' || symNode.op === 'js-var') {
+    } 
+  }],
   [JACLPKG.intern("%TAGBODY"), (env, parent, form) => {
     const [, ...tagsStmts] = form;
     // Map from tag names (string or int) to arrays of statements