From: David Vazquez Date: Mon, 17 Dec 2012 14:41:57 +0000 (+0000) Subject: Fix list allocation in &rest arguments X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=0ef25ffae5dd2d182bc69daa9dc41bfec53d7729;p=jscl.git Fix list allocation in &rest arguments --- diff --git a/lispstrack.lisp b/lispstrack.lisp index 0c90bb2..f3f01df 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -306,10 +306,12 @@ "){" *newline* (if rest-argument - (concat "var " (lookup-variable rest-argument new-env) - " = arguments.slice(" - (prin1-to-string (length required-arguments)) - ");" + (concat "var " (lookup-variable rest-argument new-env) ";" *newline* + "for (var i = arguments.length-1; i>=" + (integer-to-string (length required-arguments)) + "; i--)" *newline* + (lookup-variable rest-argument new-env) " = " + "{car: arguments[i], cdr: " (lookup-variable rest-argument new-env) "};" *newline*) "") (concat (ls-compile-block (butlast body) new-env fenv) diff --git a/test.lisp b/test.lisp index ae8b02d..7635aaa 100644 --- a/test.lisp +++ b/test.lisp @@ -1,76 +1 @@ ;;; Library - -;;; Tests - -(lambda (x y) x) - -(debug "hola") -(debug '(1 2 3 4)) -(debug (if 2 (+ 2 1) 0)) -(debug (= (+ 2 1) (- 4 1))) - -;;; Variables -(debug "---VARIABLES---") -(eval-when-compile - (%compile-defvar 'name)) -(setq name 10) -(debug name) - -;;; Functions -(debug "---FUNCTIONS---") -(eval-when-compile - (%compile-defun 'f)) -(fsetq f (lambda (x) (+ x 10))) -(debug (f 20)) - -(debug ((lambda (x) x) 9999)) - -(debug #'f) - -;;; Macros -(debug "---MACROS---") - - - -(defmacro incf (x) - (list 'setq x (list '+ 1 x))) - -(eval-when-compile - (%compile-defvar 'x)) - -(setq x 10) -(incf x) -(debug x) - -;;; Conses -(debug (cons 1 2)) -(debug (car (cons 1 2))) -(debug (cdr (cons 1 2))) - -(setq x '(1 . 2)) -(debug x) -(debug (eq x x)) -(debug (eq '(1 . 2) '(1 . 2))) - -;;; Symbols -(debug (symbol-name 'foo)) -(debug (symbol-name 'foo-bar)) - -(debug (progn 1 2 3 123)) - -(debug (let ((x 99999)) - (incf x))) - -;;; &rest lambda-list - -(debug (lambda (&rest x) x)) -(debug (lambda (x y &rest z) z)) -(debug (lambda (x y &rest z) x)) - - -;; (eval-when-compile -;; (%compile-defmacro 'defun -;; (lambda (name args &rest body) -;; (list 'eval-when-compile -;; (list 'compile-defun) -;; (list 'fsetq (list 'lambda args (list 'progn body)))))))