|
242 | 242 | (def boolean-infix-operators |
243 | 243 | #{"==" "===" "<" ">" "<=" ">=" "!=" "instanceof"}) |
244 | 244 |
|
| 245 | +(def numeric-infix-operators |
| 246 | + #{"+" "+=" "-" "-=" "/" "*" "%" "<<" ">>" "<<<" ">>>" "&" "|" |
| 247 | + "bit-or" "bit-and" "js-mod"}) |
| 248 | + |
245 | 249 | (def chainable-infix-operators #{"+" "-" "*" "/" "&" "|" "&&" "||" "bit-or" "bit-and" "js-??"}) |
246 | 250 |
|
247 | 251 | (defn infix-operator? [env expr] |
|
263 | 267 | (let [env (assoc enc-env :context :expr :top-level false) |
264 | 268 | acount (count args) |
265 | 269 | op-name (name operator) |
266 | | - bool? (contains? boolean-infix-operators op-name)] |
| 270 | + bool? (contains? boolean-infix-operators op-name) |
| 271 | + numeric? (contains? numeric-infix-operators op-name)] |
267 | 272 | (if (and (not (chainable-infix-operators op-name)) (> acount 2)) |
268 | 273 | (emit (list 'cljs.core/&& |
269 | 274 | (list operator (first args) (second args)) |
|
289 | 294 | wrap-parens |
290 | 295 | (emit-return enc-env) |
291 | 296 | (cond-> |
292 | | - bool? (tagged-expr 'boolean)))))) |
| 297 | + bool? (tagged-expr 'boolean) |
| 298 | + numeric? (tagged-expr 'number)))))) |
293 | 299 |
|
294 | 300 | (def core-vars (atom #{})) |
295 | 301 |
|
|
980 | 986 | (emit-return (wrap-parens (str "new " (emit class (expr-env env)) (comma-list (emit-args env args)))) env)) |
981 | 987 |
|
982 | 988 | (defmethod emit-special 'dec [_type env [_ var]] |
983 | | - (emit-return (str "(" (emit var (assoc env :context :expr)) " - " 1 ")") env)) |
| 989 | + (-> (emit-return (str "(" (emit var (assoc env :context :expr)) " - " 1 ")") env) |
| 990 | + (tagged-expr 'number))) |
984 | 991 |
|
985 | 992 | (defmethod emit-special 'inc [_type env [_ var]] |
986 | | - (emit-return (str "(" (emit var (assoc env :context :expr)) " + " 1 ")") env)) |
| 993 | + (-> (emit-return (str "(" (emit var (assoc env :context :expr)) " + " 1 ")") env) |
| 994 | + (tagged-expr 'number))) |
987 | 995 |
|
988 | 996 | (defmethod emit-special 'while [_type env [_while test & body]] |
989 | 997 | (str "while (" (emit test (expr-env env)) ") { \n" |
|
0 commit comments