patches.lisp
74 lines
| 2.1 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)) | ||||
r29 | (define-trivial-special-ops await ps-js::await) | |||
r23 | ||||
(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 '=>) | ||||
r27 | ||||
;;; Actually return nothing (with no empty return) | ||||
(defvar *old-return-result-of* (function return-result-of)) | ||||
(defun return-result-of (tag form) | ||||
(if (equal form '(void)) | ||||
nil | ||||
(funcall *old-return-result-of* tag form))) | ||||
(export 'void) | ||||
r33 | ||||
;;; Bitwise stuff | ||||
;; No idea why these are not exported | ||||
(export '<<) | ||||
(export '>>) | ||||