Migrate FUNCALL
authorDavid Vázquez <davazp@gmail.com>
Thu, 27 Jun 2013 13:59:14 +0000 (15:59 +0200)
committerDavid Vázquez <davazp@gmail.com>
Thu, 27 Jun 2013 13:59:14 +0000 (15:59 +0200)
src/compiler.lisp

index a903fbd..09ca814 100644 (file)
                    (== (get x "stringp") 1))))))
 
 (define-raw-builtin funcall (func &rest args)
-  (js!selfcall
-    "var f = " (ls-compile func) ";"
-    "return (typeof f === 'function'? f: f.fvalue)("
-    `(code
-     ,@(interleave (list* (if *multiple-value-p* "values" "pv")
-                          (integer-to-string (length args))
-                          (mapcar #'ls-compile args))
-                   ", "))
-    ")"))
+  (js!selfcall*
+    `(var (f ,(ls-compile func)))
+    `(return (call (if (=== (typeof f) "function")
+                       f
+                       (get f "fvalue"))
+                   ,@(list* (if *multiple-value-p* '|values| '|pv|)
+                            (length args)
+                            (mapcar #'ls-compile args))))))
 
 (define-raw-builtin apply (func &rest args)
   (if (null args)