git » jacl.git » commit 39184b8

&key wip

author Alan Dipert
2019-11-04 01:51:13 UTC
committer Alan Dipert
2019-11-04 01:51:13 UTC
parent 2a7fcb4003ab5dc4971c299de0a89321e62b7e1c

&key wip

jacl.js +21 -14

diff --git a/jacl.js b/jacl.js
index fe9f85d..b25da95 100644
--- a/jacl.js
+++ b/jacl.js
@@ -889,8 +889,8 @@ const parseLambdaList = list => {
       optionalSvars: [],
       // null or symbol
       rest: null,
-      // Array of [keyword, symbol, expr, symbol] for [key, name, init, svar]
-      key: [],
+      // Map of keyword => [symbol, expr, symbol] for key => [name, init, svar]
+      key: new Map(),
       // Array of [symbol, expr] for [name, init]
       aux: []
     },
@@ -972,21 +972,24 @@ const parseLambdaList = list => {
         } else if (eqClSym(x, '&AUX')) {
           state = 'aux';
         } else if (x instanceof LispSymbol) {
-          sections.key.push({
-            key: LispSymbol.intern('KEYWORD', x.name),
+          const key = LispSymbol.intern('KEYWORD', x.name);
+          if (sections.key.has(key))
+            throw new Error(`Duplicate key: ${key.name}`);
+          sections.key.set(key, {
             name: checkValidLocal(x),
             initform: UNDEFINED,
             svar: UNDEFINED
           });
         } else if (Cons.isProperList(x)) {
-          const len = Cons.length(x);
-          if (len === 0 || len > 3) 
-            throw new Error(`&KEY parameter list wrong size`);
-          sections.key.push({
-            name: checkValidLocal(x.car),
-            initform: len > 1 ? Cons.nth(x, 1) : UNDEFINED,
-            svar: len === 3 ? checkValidLocal(Cons.nth(x, 2)) : UNDEFINED
-          });
+          throw new Error(`TODO`);
+          //const len = Cons.length(x);
+          //if (len === 0 || len > 3) 
+          //  throw new Error(`&KEY parameter list wrong size`);
+          //sections.key.push({
+          //  name: checkValidLocal(x.car),
+          //  initform: len > 1 ? Cons.nth(x, 1) : UNDEFINED,
+          //  svar: len === 3 ? checkValidLocal(Cons.nth(x, 2)) : UNDEFINED
+          //});
         } else {
           throw new Error(`&KEY parameter not symbol or valid list`);
         }
@@ -1495,18 +1498,22 @@ const emitNode = (print, node) => {
         print('break;\n');
         print('}\n');
       }
+      const restStart = node.lambdaList.required.length
+        + node.lambdaList.optional.length;
       // &rest
       if (node.lambdaList.rest) {
         print(mungeSym(node.lambdaList.rest, 'local'));
         print('=');
-        const restStart = node.lambdaList.required.length
-          + node.lambdaList.optional.length;
         // TODO Here we cons up a list from an array. It would be better if we
         // could avoid copying and maybe had a 'cdr-coded' type, or array-backed
         // pseudo-cons type thing. Then we could creat one of those in constant
         // time.
         print(`Cons.fromArray(Array.prototype.slice.call(arguments, ${restStart}));\n`);
       }
+      // &key
+      if (node.lambdaList.key) {
+        // TODO
+      }
       emitBlock(print, node.statements, node.ret);
       print('})');
       break;