Skip to content

Commit

Permalink
bit-and + bit-or
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 9, 2023
1 parent 9ae9743 commit 7107200
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[Squint](https://github.com/squint-cljs/squint): ClojureScript syntax to JavaScript compiler

## 0.2.31 (2023-10-09)

- Add `bit-and` and `bit-or`

## 0.2.30 (2023-10-04)

- Include `lib/squint.core.umd.js` which defines a global `squint.core` object (easy to use in browsers)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "squint-cljs",
"type": "module",
"sideEffects": false,
"version": "0.2.30",
"version": "0.2.31",
"files": [
"core.js",
"src/squint/core.js",
Expand Down
9 changes: 6 additions & 3 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@
(def suffix-unary-operators '#{++ --})

(def infix-operators #{"+" "+=" "-" "-=" "/" "*" "%" "=" "==" "===" "<" ">" "<=" ">=" "!="
"<<" ">>" "<<<" ">>>" "!==" "&" "|" "&&" "||" "not=" "instanceof"})
"<<" ">>" "<<<" ">>>" "!==" "&" "|" "&&" "||" "not=" "instanceof"
"bit-or" "bit-and"})

(def chainable-infix-operators #{"+" "-" "*" "/" "&" "|" "&&" "||"})
(def chainable-infix-operators #{"+" "-" "*" "/" "&" "|" "&&" "||" "bit-or" "bit-and"})

(defn infix-operator? [env expr]
(contains? (or (:infix-operators env)
Expand Down Expand Up @@ -163,7 +164,9 @@
(str "-" (emit (first args) env))
(-> (let [substitutions {'= "===" == "===" '!= "!=="
'not= "!=="
'+ "+"}]
'+ "+"
'bit-or "|"
'bit-and "&"}]
(str "(" (str/join (str " " (or (substitutions operator)
operator) " ")
(emit-args env args)) ")"))
Expand Down
21 changes: 8 additions & 13 deletions src/squint/repl/node.cljs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
(ns squint.repl.node
(:require
["fs" :as fs]
["net" :as net]
["path" :as path]
["process" :as process]
["readline" :as readline]
["squint-cljs/core.js" :as squint]
["url" :as url]
["vm" :as vm]
[clojure.string :as str]
[edamame.core :as e]
[shadow.esm :as esm]
[squint.compiler :as compiler]
[squint.compiler-common :refer [*async* *cljs-ns* *repl*]]))

Expand Down Expand Up @@ -72,14 +67,14 @@
(def last-ns (atom *cljs-ns*))

#_(defn eval-js [js-str]
(let [filename (str ".repl/" (gensym) ".mjs")]
(when-not (fs/existsSync ".repl")
(fs/mkdirSync ".repl"))
(fs/writeFileSync filename js-str)
(-> (esm/dynamic-import (-> (path/resolve (process/cwd) filename)
url/pathToFileURL
str))
(.finally (fn [] #_(prn filename) (fs/unlinkSync filename))))))
(let [filename (str ".repl/" (gensym) ".mjs")]
(when-not (fs/existsSync ".repl")
(fs/mkdirSync ".repl"))
(fs/writeFileSync filename js-str)
(-> (esm/dynamic-import (-> (path/resolve (process/cwd) filename)
url/pathToFileURL
str))
(.finally (fn [] #_(prn filename) (fs/unlinkSync filename))))))

(defn compile [the-val rl socket]
(let [{js-str :javascript
Expand Down
3 changes: 3 additions & 0 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,5 +1457,8 @@
(deftest re-seq-test
(is (eq #js ["foo" "foo" "foo"] (jsv! "(vec (re-seq #\"foo\" \"foobfoobfoo\"))"))))

(deftest bit-and-or
(is (= 3 (jsv! "(+ (bit-and 1 2 3) (bit-or 1 2 3))"))))

(defn init []
(t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test))

0 comments on commit 7107200

Please sign in to comment.