X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=ecmalisp.lisp;h=0801df4f45a88266e40c01ab26aa684da8b56243;hb=ad28d0c42e2a8b37c0213a37f5966f7198fe8b02;hp=995632cbb11adeedb52cd862b2408b2fb231412d;hpb=e4f7297f1a3936fa667caccb4d10156d05112a12;p=jscl.git diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 995632c..0801df4 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -23,7 +23,7 @@ ;;; language to the compiler to be able to run. #+ecmalisp -(js-eval "function id (x) { return 'car' in x ? x.car : x; }") +(js-eval "function pv (x) { return typeof x === 'object' && 'car' in x ? x.car : x; }") #+ecmalisp (progn @@ -601,17 +601,7 @@ (oset exports (symbol-name symb) symb)))) (defun get-universal-time () - (+ (get-unix-time) 2208988800)) - - ;; The `values-list' primitive cannot be inlined out of functions as - ;; the VALUES argument is not available there. We declare it - ;; NOTINLINE to avoid it. - (declaim (notinline values-list)) - (defun values-list (list) - (values-list list)) - - (defun values (&rest args) - (values-list args))) + (+ (get-unix-time) 2208988800))) ;;; The compiler offers some primitives and special forms which are @@ -685,6 +675,15 @@ (aset v i x) (incf i)))) +#+ecmalisp +(progn + (defun values-list (list) + (values-array (list-to-vector list))) + + (defun values (&rest args) + (values-list args))) + + ;;; Like CONCAT, but prefix each line with four spaces. Two versions ;;; of this function are available, because the Ecmalisp version is ;;; very slow and bootstraping was annoying. @@ -1139,10 +1138,14 @@ "return func;" *newline*) (join strs))) + +(defvar *compiling-lambda-p* nil) + (define-compilation lambda (lambda-list &rest body) (let ((required-arguments (lambda-list-required-arguments lambda-list)) (optional-arguments (lambda-list-optional-arguments lambda-list)) (rest-argument (lambda-list-rest-argument lambda-list)) + (*compiling-lambda-p* t) documentation) ;; Get the documentation string for the lambda function (when (and (stringp (car body)) @@ -1850,7 +1853,7 @@ (define-raw-builtin funcall (func &rest args) (concat "(" (ls-compile func) ")(" - (join (cons "id" (mapcar #'ls-compile args)) + (join (cons "pv" (mapcar #'ls-compile args)) ", ") ")")) @@ -1861,7 +1864,7 @@ (last (car (last args)))) (js!selfcall "var f = " (ls-compile func) ";" *newline* - "var args = [" (join (cons "id" (mapcar #'ls-compile args)) + "var args = [" (join (cons "pv" (mapcar #'ls-compile args)) ", ") "];" *newline* "var tail = (" (ls-compile last) ");" *newline* @@ -1930,8 +1933,14 @@ (define-builtin get-unix-time () (concat "(Math.round(new Date() / 1000))")) -(define-raw-builtin values-list (list) - (concat "values(" list ")")) +(define-builtin values-array (array) + (concat "values.apply(this, " array ")")) + +(define-raw-builtin values (&rest args) + (if *compiling-lambda-p* + (concat "values(" (join (mapcar #'ls-compile args) ", ") ")") + (compile-funcall 'values args))) + (defun macro (x) (and (symbolp x) @@ -1961,11 +1970,11 @@ (if (and (symbolp function) (claimp function 'function 'non-overridable)) (concat (ls-compile `',function) ".fvalue(" - (join (cons "id" (mapcar #'ls-compile args)) + (join (cons "pv" (mapcar #'ls-compile args)) ", ") ")") (concat (ls-compile `#',function) "(" - (join (cons "id" (mapcar #'ls-compile args)) + (join (cons "pv" (mapcar #'ls-compile args)) ", ") ")")))