From: rayslava Date: Sun, 20 Jan 2013 08:44:25 +0000 (+0400) Subject: Optimal arithmetics generation X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=13b874aeb9802c26ad12821b9a24337c9c20bb64;p=jscl.git Optimal arithmetics generation --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 39750b9..2e4c4a6 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1547,6 +1547,22 @@ res) "0"))) +(defmacro arithmetic (op &rest args) + (let ((counter 0) + (checks ())) + (dolist (x args) + (push (list (concat "v" (ls-compile counter)) + "number" + (ls-compile x)) + checks) + (incf counter)) + `(js-eval + (type-check ,checks + ,(let ((res "")) + (dolist (x checks) + (setq res (concat (car x) (symbol-name op) res))) + (subseq res 0 (1- (length res)))))))) + (define-builtin-arithmetic +) (define-builtin-arithmetic -) (define-builtin-arithmetic *) @@ -1570,8 +1586,6 @@ (define-builtin-comparison >= ">=") (define-builtin-comparison <= "<=") (define-builtin-comparison = "==") -(define-builtin-comparison equal "==") -(define-builtin-comparison eq "===") (define-builtin numberp (x) (js!bool (concat "(typeof (" x ") == \"number\")"))) @@ -1653,6 +1667,9 @@ (define-builtin lambda-code (x) (concat "(" x ").toString()")) +(define-builtin eq (x y) (js!bool (concat "(" x " === " y ")"))) +(define-builtin equal (x y) (js!bool (concat "(" x " == " y ")"))) + (define-builtin char-to-string (x) (type-check (("x" "number" x)) "String.fromCharCode(x)")) @@ -1868,7 +1885,9 @@ remove-if remove-if-not return return-from revappend reverse second set setq some string-upcase string string= stringp subseq symbol-function symbol-name symbol-package symbol-plist symbol-value symbolp t tagbody third throw truncate unless unwind-protect variable -warn when write-line write-string zerop)) +warn when write-line write-string zerop +arithmetic +)) (setq *package* *user-package*)