Fix several newly introduced bugs in the migration to mutable strings
authorDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 10:41:31 +0000 (11:41 +0100)
committerDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 10:41:31 +0000 (11:41 +0100)
jscl.html
src/boot.lisp
src/compiler.lisp
src/prelude.js
src/toplevel.lisp
tests/eval.lisp

index 1dfe7fc..0fde9fc 100644 (file)
--- a/jscl.html
+++ b/jscl.html
         jqconsole.RegisterMatching('(', ')', 'parents');
 
         lisp.write = function(str){
-           jqconsole.Write(str, 'jqconsole-output', false);
+           jqconsole.Write(xstring(str), 'jqconsole-output', false);
            return str;
         }
 
         var startPrompt = function () {
           // Start the prompt with history enabled.
-          jqconsole.Write(lisp.evalString(pv, 1, make_lisp_string('(CL:PACKAGE-NAME CL:*PACKAGE*)')) + '> ', 'jqconsole-prompt');
+          jqconsole.Write(xstring(lisp.evalString(pv, 1, make_lisp_string('(CL:PACKAGE-NAME CL:*PACKAGE*)'))) + '> ', 'jqconsole-prompt');
           jqconsole.Prompt(true, function (input) {
             // Output input with the class jqconsole-return.
             if (input[0] != ','){
                 try {
                     var vs = lisp.evalInput(mv, 1, make_lisp_string(input));
                     for (var i=0; i<vs.length; i++){
-                       jqconsole.Write(lisp.print(pv, 1, vs[i]) + '\n', 'jqconsole-return');
+                       jqconsole.Write(xstring(lisp.print(pv, 1, vs[i])) + '\n', 'jqconsole-return');
                     }
                 } catch(error) {
                     jqconsole.Write('ERROR: ' + (error.message || error) + '\n', 'jqconsole-error');
                 }
             } else {
-                jqconsole.Write(lisp.compileString(pv, 1, make_lisp_string(input.slice(1))) + '\n', 'jqconsole-return');
+                jqconsole.Write(xstring(lisp.compileString(pv, 1, make_lisp_string(input.slice(1)))) + '\n', 'jqconsole-return');
             }
             // Restart the prompt.
             startPrompt();
index 19e077e..4cb0fe4 100644 (file)
 (defun atom (x)
   (not (consp x)))
 
-(defun find (item list &key key (test #'eql))
+(defun find (item list &key (key #'identity) (test #'eql))
   (dolist (x list)
     (when (funcall test (funcall key x) item)
       (return x))))
index 8a9fc36..29c491b 100644 (file)
      "return typeof(x) == 'object' && 'length' in x && x.type == 'character';")))
 
 (define-builtin string-upcase (x)
-  (code "make_lisp_string(" x ".join('').toUppercase())"))
+  (code "make_lisp_string(xstring(" x ").toUpperCase())"))
 
 (define-builtin string-length (x)
   (code x ".length"))
 (define-builtin js-eval (string)
   (if *multiple-value-p*
       (js!selfcall
-        "var v = globalEval(" string ".join(''));" *newline*
+        "var v = globalEval(xstring(" string "));" *newline*
         "return values.apply(this, forcemv(v));" *newline*)
-      (code "globalEval(" string ".join(''))")))
+      (code "globalEval(xstring(" string ")")))
 
 (define-builtin %throw (string)
   (js!selfcall "throw " string ";" *newline*))
 
 (define-builtin oget (object key)
   (js!selfcall
-    "var tmp = " "(" object ")[" key "];" *newline*
+    "var tmp = " "(" object ")[xstring(" key ")];" *newline*
     "return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*))
 
 (define-builtin oset (object key value)
-  (code "((" object ")[" key "] = " value ")"))
+  (code "((" object ")[xstring(" key ")] = " value ")"))
 
 (define-builtin in (key object)
-  (js!bool (code "((" key ") in (" object "))")))
+  (js!bool (code "(xstring(" key ") in (" object ")")))
 
 (define-builtin functionp (x)
   (js!bool (code "(typeof " x " == 'function')")))
 
 (define-builtin write-string (x)
-  (code "lisp.write(" x ".join(''))"))
+  (code "lisp.write(xstring(" x "))"))
 
 (define-builtin make-array (n)
   (js!selfcall
index e76d761..1aa5e0f 100644 (file)
@@ -59,3 +59,4 @@ function make_lisp_string (string){
     return array;
 }
 
+function xstring(x){ return x.join(''); }
index d6f8cb4..4c63b2a 100644 (file)
    (ls-compile
     `(progn
        ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s))))
-                 *literal-table*)
+                 (remove-if-not #'symbolp *literal-table* :key #'car))
        (setq *literal-table* ',*literal-table*)
        (setq *variable-counter* ,*variable-counter*)
        (setq *gensym-counter* ,*gensym-counter*)))))
index 4d6d780..f17414a 100644 (file)
@@ -1,3 +1,5 @@
-(print "testing")
-(print (eval '(+ 1 3)))
+(print "<<<")
+(print (find 'a '((b) (c) (a)) :key #'car))
+(print ">>>")
+
 (test (= (eval '(+ 1 2)) 3))