patches.lisp
60 lines
| 1.8 KiB
| text/x-common-lisp
|
CommonLispLexer
/ src / patches.lisp
r23 | ||||
(in-package parenscript) | ||||
;;; async/await | ||||
(defprinter ps-js::await (x) | ||||
(psw (string-downcase "await ")) | ||||
(print-op-argument 'ps-js::await x)) | ||||
(define-trivial-special-ops await) | ||||
(define-statement-operator async-defun (name lambda-list &rest body) | ||||
(multiple-value-bind (effective-args body-block docstring) | ||||
(compile-named-function-body name lambda-list body) | ||||
(list 'ps-js::async-defun name effective-args docstring body-block))) | ||||
(defprinter ps-js::async-defun (name args docstring body-block) | ||||
(when docstring (print-comment docstring)) | ||||
(psw "async ") | ||||
(print-fun-def name args body-block)) | ||||
(define-expression-operator async-lambda (lambda-list &rest body) | ||||
(multiple-value-bind (effective-args effective-body) | ||||
(parse-extended-function lambda-list body) | ||||
`(ps-js::async-lambda | ||||
,effective-args | ||||
,(let ((*function-block-names* ())) | ||||
(compile-function-body effective-args effective-body))))) | ||||
(defprinter ps-js::async-lambda (args body-block) | ||||
(psw "async ") | ||||
(print-fun-def nil args body-block)) | ||||
(cl:export 'await) | ||||
(cl:export 'async-defun) | ||||
(cl:export 'async-lambda) | ||||
;;; ES6 | ||||
(define-expression-operator => (lambda-list &rest body) | ||||
(unless (listp lambda-list) | ||||
(setf lambda-list (list lambda-list))) | ||||
(multiple-value-bind (effective-args effective-body) | ||||
(parse-extended-function lambda-list body) | ||||
`(ps-js::=> | ||||
,effective-args | ||||
,(let ((*function-block-names* ())) | ||||
(compile-function-body effective-args effective-body))))) | ||||
(defprinter ps-js::=> (args body) | ||||
(unless (= 1 (length args)) | ||||
(psw "(")) | ||||
(loop for (arg . remaining) on args do | ||||
(psw (symbol-to-js-string arg)) (when remaining (psw ", "))) | ||||
(unless (= 1 (length args)) | ||||
(psw ")")) | ||||
(psw " => ") | ||||
(ps-print body)) | ||||
(cl:export '=>) | ||||