X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fcompiler.lisp;h=d2b6975f7e49ab1c234bdfd3ddc56ca2f53b7ba1;hb=a2bb848e0037e127287781e99528bc4e93ccc2fb;hp=0ec5feaac7730589fed63707e663d5ecc20f2e4b;hpb=259f6aaee78865c11889b9b83f3306192fee6bd9;p=jscl.git diff --git a/src/compiler/compiler.lisp b/src/compiler/compiler.lisp index 0ec5fea..d2b6975 100644 --- a/src/compiler/compiler.lisp +++ b/src/compiler/compiler.lisp @@ -516,7 +516,7 @@ (push (cons sexp jsvar) *literal-table*) (toplevel-compilation `(var (,jsvar ,dumped))) (when (keywordp sexp) - (toplevel-compilation `(= ,(get jsvar "value") ,jsvar))) + (toplevel-compilation `(= (get ,jsvar "value") ,jsvar))) jsvar))))))) @@ -600,20 +600,13 @@ (when (find :compile-toplevel situations) (eval (cons 'progn body))) ;; `load-toplevel' is given, then just compile the subforms as usual. - (if (find :load-toplevel situations) - (convert `(progn ,@body)))) + (when (find :load-toplevel situations) + (convert-toplevel `(progn ,@body) *multiple-value-p*))) ((find :execute situations) (convert `(progn ,@body) *multiple-value-p*)) (t (convert nil)))) -(define-compilation eval-when-compile (&rest body) - (if *compiling-file* - (progn - (eval (cons 'progn body)) - (convert 0)) - (convert `(progn ,@body)))) - (defmacro define-transformation (name args form) `(define-compilation ,name ,args (convert ,form))) @@ -1079,9 +1072,6 @@ (throw (+ "Function `" (call |xstring| (get symbol "name")) "' is undefined."))) (return func))) -(define-builtin symbol-plist (x) - `(or (get ,x "plist") ,(convert nil))) - (define-builtin lambda-code (x) `(call |make_lisp_string| (method-call ,x "toString"))) @@ -1162,9 +1152,6 @@ (define-builtin functionp (x) `(bool (=== (typeof ,x) "function"))) -(define-builtin %write-string (x) - `(method-call |lisp| "write" ,x)) - (define-builtin /debug (x) `(method-call |console| "log" (call |xstring| ,x))) @@ -1248,7 +1235,7 @@ ,@(mapcar (lambda (key) `(progn (= obj (property obj (call |xstring| ,(convert key)))) - (if (=== object undefined) + (if (=== obj undefined) (throw "Impossible to set object property.")))) (butlast keys)) (var (tmp @@ -1274,6 +1261,10 @@ (define-builtin in (key object) `(bool (in (call |xstring| ,key) ,object))) +(define-builtin delete-property (key object) + `(selfcall + (delete (property ,object (call |xstring| ,key))))) + (define-builtin map-for-in (function object) `(selfcall (var (f ,function) @@ -1362,14 +1353,14 @@ #+jscl((symbolp function) `(call ,(convert `#',function) ,@arglist)) ((and (consp function) (eq (car function) 'lambda)) - `(call ,(convert `#',function) ,@arglist)) + `(call ,(convert `(function ,function)) ,@arglist)) ((and (consp function) (eq (car function) 'oget)) `(call |js_to_lisp| (call ,(reduce (lambda (obj p) `(property ,obj (call |xstring| ,p))) (mapcar #'convert (cdr function))) ,@(mapcar (lambda (s) - `(call |lisp_to_js| ,s)) + `(call |lisp_to_js| ,(convert s))) args)))) (t (error "Bad function descriptor"))))) @@ -1431,7 +1422,13 @@ (subseq string 0 n))) (defun convert-toplevel (sexp &optional multiple-value-p) - (let ((*toplevel-compilations* nil)) + ;; Macroexpand sexp as much as possible + (multiple-value-bind (sexp expandedp) (!macroexpand-1 sexp) + (when expandedp + (return-from convert-toplevel (convert-toplevel sexp multiple-value-p)))) + ;; Process as toplevel + (let ((*convert-level* -1) + (*toplevel-compilations* nil)) (cond ;; Non-empty toplevel progn ((and (consp sexp)