X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=ecmalisp.lisp;h=0d091a66a5b354e1bd53033c938239bd238c0147;hb=4951c2dad634560b91b4d0bf3b6545dd02bfa887;hp=02aa16ed5a6dc341973bf770d0310eba20e20e5d;hpb=819d4a5bc9214fdb79ade55f10ba7349110316bf;p=jscl.git diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 02aa16e..0d091a6 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -23,7 +23,9 @@ ;;; language to the compiler to be able to run. #+ecmalisp -(js-eval "function pv (x) { return typeof x === 'object' && 'car' in x ? x.car : x; }") +(js-eval "function pv (x) { return x; }") +#+ecmalisp +(js-eval "var values = pv;") #+ecmalisp (progn @@ -601,13 +603,7 @@ (oset exports (symbol-name symb) symb)))) (defun get-universal-time () - (+ (get-unix-time) 2208988800)) - - (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 @@ -681,6 +677,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. @@ -979,6 +984,8 @@ ;;; too. The respective real functions are defined in the target (see ;;; the beginning of this file) as well as some primitive functions. +(defvar *multiple-value-p* nil) + (defvar *compilation-unit-checks* '()) (defun make-binding (name type value &optional declarations) @@ -1100,8 +1107,8 @@ (define-compilation if (condition true false) (concat "(" (ls-compile condition) " !== " (ls-compile nil) - " ? " (ls-compile true) - " : " (ls-compile false) + " ? " (ls-compile true *multiple-value-p*) + " : " (ls-compile false *multiple-value-p*) ")")) (defvar *lambda-list-keywords* '(&optional &rest)) @@ -1136,13 +1143,10 @@ (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)) @@ -1564,15 +1568,22 @@ (let ((func (ls-compile func-form))) (js!selfcall "var args = [values];" *newline* - "function values(){" *newline* + "values = function(){" *newline* (indent "var result = [];" *newline* + "result['multiple-value'] = true;" *newline* "for (var i=0; i