X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=ecmalisp.lisp;h=0d091a66a5b354e1bd53033c938239bd238c0147;hb=4951c2dad634560b91b4d0bf3b6545dd02bfa887;hp=6a7e019fcab81a05875e78805fd7a0e3a20eed1d;hpb=24ccbdeee987c9e08653acf198f708017913100d;p=jscl.git diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 6a7e019..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 id (x) { return x; }") +(js-eval "function pv (x) { return x; }") +#+ecmalisp +(js-eval "var values = pv;") #+ecmalisp (progn @@ -281,7 +283,7 @@ (revappend list '())) (defmacro psetq (&rest pairs) - (let (;; For each pair, we store here a list of the form + (let ( ;; For each pair, we store here a list of the form ;; (VARIABLE GENSYM VALUE). (assignments '())) (while t @@ -675,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. @@ -973,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) @@ -1094,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)) @@ -1129,6 +1142,7 @@ "return func;" *newline*) (join strs))) + (define-compilation lambda (lambda-list &rest body) (let ((required-arguments (lambda-list-required-arguments lambda-list)) (optional-arguments (lambda-list-optional-arguments lambda-list)) @@ -1230,6 +1244,7 @@ (concat "(" var " = " (ls-compile val) ")")) + ;;; Literals (defun escape-string (string) (let ((output "") @@ -1539,7 +1554,6 @@ "})" *newline*) (error (concat "Unknown tag `" n "'."))))) - (define-compilation unwind-protect (form &rest clean-up) (js!selfcall "var ret = " (ls-compile nil) ";" *newline* @@ -1550,6 +1564,28 @@ "}" *newline* "return ret;" *newline*)) +(define-compilation multiple-value-call (func-form &rest forms) + (let ((func (ls-compile func-form))) + (js!selfcall + "var args = [values];" *newline* + "values = function(){" *newline* + (indent "var result = [];" *newline* + "result['multiple-value'] = true;" *newline* + "for (var i=0; i