From d18911b2d537b459221a39bc492bdb522c2a97b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Sun, 30 Jun 2013 16:42:48 +0200 Subject: [PATCH] compile reswip: compile rest arguments --- src/compiler.lisp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/compiler.lisp b/src/compiler.lisp index 045ab63..c02d326 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -302,11 +302,15 @@ (n-optional-arguments (length (ll-optional-arguments ll))) (rest-argument (ll-rest-argument ll))) (when rest-argument - (let ((js!rest (translate-variable rest-argument))) - `(code "var " ,js!rest "= " ,(ls-compile nil) ";" - "for (var i = nargs-1; i>=" ,(+ n-required-arguments n-optional-arguments) - "; i--)" - (code ,js!rest " = {car: arguments[i+2], cdr: " ,js!rest "};")))))) + (let ((js!rest (make-symbol (translate-variable rest-argument)))) + `(progn + (var (,js!rest ,(ls-compile nil))) + (var i) + (for ((= i (- |nargs| 1)) + (>= i ,(+ n-required-arguments n-optional-arguments)) + (post-- i)) + (= ,js!rest (object "car" (property |arguments| (+ i 2)) + "cdr" ,js!rest)))))))) (defun compile-lambda-parse-keywords (ll) (let ((n-required-arguments @@ -423,8 +427,9 @@ n-optional-arguments (or rest-argument keyword-arguments)) (code - ,(compile-lambda-optional ll) - ,(compile-lambda-rest ll) + ,(compile-lambda-optional ll)) + ,(compile-lambda-rest ll) + (code ,(compile-lambda-parse-keywords ll)) ,(let ((*multiple-value-p* t)) -- 1.7.10.4