From 18eb199841541edad87956b2380fd012e5a60769 Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Thu, 17 Sep 2009 19:59:06 -0400 Subject: [PATCH] Reimplement (.method object . args) syntax Using PS:FUNCALL, PS:CHAIN, or ((PS:SLOT-VALUE ...) ...) for method invocation is rather unwieldy for something so common in javascript. This reenables the convenient (.method ...) call syntax in a way that seems reasonably clean. This may have subtle issues with the lexical-let variable renamer and such, but my cursory skimming of the new compiler source doesn't seem to indicate any serious issues. --- src/compiler.lisp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compiler.lisp b/src/compiler.lisp index 9fbba55..1d9dc7d 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -68,6 +68,11 @@ lexical block.") (not (ps-special-form-p form)) (not (null (op-precedence (first form)))))) +(defun method-call-form-p (form) + (and (listp form) + (symbolp (car form)) + (char= #\. (char (symbol-name (car form)) 0)))) + (defun funcall-form-p (form) (and form (listp form) @@ -265,6 +270,12 @@ the form cannot be compiled to a symbol." (ps-compile-expression (ps-macroexpand form))) (cdr form)))) +(defun compile-method-call-form (form) + (compile-funcall-form + `((js:slot-value ,(second form) + ',(make-symbol (subseq (symbol-name (first form)) 1))) + ,@(cddr form)))) + (defun compile-funcall-form (form) `(js:funcall ,(ps-compile-expression (if (symbolp (car form)) @@ -293,9 +304,11 @@ the form cannot be compiled to a symbol." (compile-op-form form)))) ((op-form-p form) (compile-op-form form)) + ((method-call-form-p form) + (compile-method-call-form form)) ((funcall-form-p form) (compile-funcall-form form)) - (t (error "Cannot compile ~S to a ParenScript form." form)))))) + (t (error "Cannot compile ~S to a ParenScript form." form)))))) (defun ps-compile-statement (form) (let ((compile-expression? nil)) -- 2.20.1