From 399e62303b29b0aaf594f0a63563ea7fe9fe6669 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Sat, 22 Dec 2012 02:39:55 +0000 Subject: [PATCH] Fix apply --- lispstrack.lisp | 16 ++++------------ test.lisp | 15 ++++++++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index e3bcb6f..7826970 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -578,7 +578,7 @@ (concat "(" (ls-compile func env fenv) ")()") (let ((args (butlast args)) (last (car (last args)))) - (concat "function(){" *newline* + (concat "(function(){" *newline* "var f = " (ls-compile func env fenv) ";" *newline* "var args = [" (join (mapcar (lambda (x) (ls-compile x env fenv)) @@ -587,11 +587,11 @@ "];" *newline* "var tail = (" (ls-compile last env fenv) ");" *newline* "while (tail != false){" *newline* - " args.push(tail[0]);" *newline* - " args = args.slice(1);" *newline* + " args.push(tail.car);" *newline* + " tail = tail.cdr;" *newline* "}" *newline* "return f.apply(this, args);" *newline* - "}" *newline*)))) + "})()" *newline*)))) (define-compilation js-eval (string) (concat "eval(" (ls-compile string env fenv) ")")) @@ -652,14 +652,6 @@ (ls-compile (ls-macroexpand-1 sexp env fenv) env fenv) (compile-funcall (car sexp) (cdr sexp) env fenv)))))) -(defmacro with-compilation-unit (&rest body) - `(progn - (setq *compilation-unit-checks* nil) - ,@body - (dolist (check *compilation-unit-checks*) - (funcall check)) - (setq *compilation-unit-checks* nil))) - (defun ls-compile-toplevel (sexp) (setq *toplevel-compilations* nil) (let ((code (ls-compile sexp nil nil))) diff --git a/test.lisp b/test.lisp index f56ff77..b7662fb 100644 --- a/test.lisp +++ b/test.lisp @@ -816,12 +816,13 @@ ", ") ")")) + (define-compilation apply (func &rest args) (if (null args) (concat "(" (ls-compile func env fenv) ")()") (let ((args (butlast args)) (last (car (last args)))) - (concat "function(){" *newline* + (concat "(function(){" *newline* "var f = " (ls-compile func env fenv) ";" *newline* "var args = [" (join (mapcar (lambda (x) (ls-compile x env fenv)) @@ -830,11 +831,12 @@ "];" *newline* "var tail = (" (ls-compile last env fenv) ");" *newline* "while (tail != false){" *newline* - " args.push(tail[0]);" *newline* - " args = args.slice(1);" *newline* + " args.push(tail.car);" *newline* + " tail = tail.cdr;" *newline* "}" *newline* "return f.apply(this, args);" *newline* - "}" *newline*)))) + "})()" *newline*)))) + (define-compilation js-eval (string) (concat "eval(" (ls-compile string env fenv) ")")) @@ -948,4 +950,7 @@ (js-eval (ls-compile x nil nil))) -(debug (ls-compile 't nil nil)) +(debug (apply #'+ 1 '(2))) + +;; (with-compilation-unit +;; (debug (ls-compile (quote (function 1+)) nil nil))) -- 1.7.10.4