Skip to content

Commit 1d1a812

Browse files
committed
some missing compatibility fns & macors
1 parent 4652498 commit 1d1a812

File tree

4 files changed

+186
-28
lines changed

4 files changed

+186
-28
lines changed

devnotes/corelib.org

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ does what?
114114
* bound-fn*
115115
* bound?
116116
* DONE butlast
117-
* TODO byte
117+
* DONE byte
118118
* byte-array
119119
* bytes
120120
* DONE case
121121
* cast
122-
* char
122+
* DONE char
123123
* char-array
124124
* char-escape-string
125125
* char-name-string
@@ -197,7 +197,7 @@ For macros only, uses clojure.core version
197197
* dosync
198198
* DONE dotimes
199199
* DONE doto
200-
* TODO double
200+
* DONE double
201201
* DONE double-array
202202
* TODO doubles
203203
* DONE drop
@@ -232,7 +232,7 @@ macro currently expands into extend call
232232
* find-var
233233
* DONE first
234234
* DONE flatten
235-
* float
235+
* DONE float
236236
* float-array
237237
* float?
238238
* floats
@@ -479,7 +479,7 @@ as macro
479479
* set-error-mode!
480480
* set-validator!
481481
* DONE set?
482-
* short
482+
* DONE short
483483
* short-array
484484
* shorts
485485
* TODO shuffle
@@ -525,27 +525,27 @@ as macro
525525
* DONE tree-seq
526526
* DONE true?
527527
* DONE type - returns JS constructor
528-
* TODO unchecked-add
529-
* TODO unchecked-add-int
530-
* TODO unchecked-byte
531-
* TODO unchecked-char
532-
* TODO unchecked-dec
533-
* TODO unchecked-dec-int
534-
* TODO unchecked-divide-int
535-
* TODO unchecked-double
536-
* TODO unchecked-float
537-
* TODO unchecked-inc
538-
* TODO unchecked-inc-int
539-
* TODO unchecked-int
540-
* TODO unchecked-long
541-
* TODO unchecked-multiply
542-
* TODO unchecked-multiply-int
543-
* TODO unchecked-negate
544-
* TODO unchecked-negate-int
545-
* TODO unchecked-remainder-int
546-
* TODO unchecked-short
547-
* TODO unchecked-subtract
548-
* TODO unchecked-subtract-int
528+
* DONE unchecked-add
529+
* DONE unchecked-add-int
530+
* DONE unchecked-byte
531+
* DONE unchecked-char
532+
* DONE unchecked-dec
533+
* DONE unchecked-dec-int
534+
* DONE unchecked-divide-int
535+
* DONE unchecked-double
536+
* DONE unchecked-float
537+
* DONE unchecked-inc
538+
* DONE unchecked-inc-int
539+
* DONE unchecked-int
540+
* DONE unchecked-long
541+
* DONE unchecked-multiply
542+
* DONE unchecked-multiply-int
543+
* DONE unchecked-negate
544+
* DONE unchecked-negate-int
545+
* DONE unchecked-remainder-int
546+
* DONE unchecked-short
547+
* DONE unchecked-subtract
548+
* DONE unchecked-subtract-int
549549
* DONE underive
550550
* unquote
551551
* unquote-splicing

src/clj/cljs/analyzer.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
{:name fld
384384
:field true
385385
:mutable (-> fld meta :mutable)
386+
:unsynchronized-mutable (-> fld meta :unsynchronized-mutable)
387+
:volatile-mutable (-> fld meta :volatile-mutable)
386388
:tag (-> fld meta :tag)
387389
:shadow (m fld)}))
388390
locals fields)
@@ -554,7 +556,9 @@
554556
(let [local (-> env :locals target)]
555557
(assert (or (nil? local)
556558
(and (:field local)
557-
(:mutable local)))
559+
(or (:mutable local)
560+
(:unsynchronized-mutable local)
561+
(:volatile-mutable local))))
558562
"Can't set! local var or non-mutable field"))
559563
(analyze-symbol enve target))
560564

src/clj/cljs/core.clj

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
aget aset
2121
+ - * / < <= > >= == zero? pos? neg? inc dec max min mod
22+
byte char short int long float double
23+
unchecked-byte unchecked-char unchecked-short unchecked-int
24+
unchecked-long unchecked-float unchecked-double
25+
unchecked-add unchecked-add-int unchecked-dec unchecked-dec-int
26+
unchecked-divide unchecked-divide-int unchecked-inc unchecked-inc-int
27+
unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int
28+
unchecked-subtract unchecked-subtract-int unchecked-remainder-int
29+
2230
bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set
2331
bit-test bit-shift-left bit-shift-right bit-xor])
2432
(:require clojure.walk))
@@ -224,6 +232,60 @@
224232
([x y] (list 'js* "(~{} + ~{})" x y))
225233
([x y & more] `(+ (+ ~x ~y) ~@more)))
226234

235+
(defmacro byte [x] x)
236+
(defmacro char [x] x)
237+
(defmacro short [x] x)
238+
(defmacro float [x] x)
239+
(defmacro double [x] x)
240+
241+
(defmacro unchecked-byte [x] x)
242+
(defmacro unchecked-char [x] x)
243+
(defmacro unchecked-short [x] x)
244+
(defmacro unchecked-float [x] x)
245+
(defmacro unchecked-double [x] x)
246+
247+
(defmacro unchecked-add
248+
([& xs] `(+ ~@xs)))
249+
250+
(defmacro unchecked-add-int
251+
([& xs] `(+ ~@xs)))
252+
253+
(defmacro unchecked-dec
254+
([x] `(dec ~x)))
255+
256+
(defmacro unchecked-dec-int
257+
([x] `(dec ~x)))
258+
259+
(defmacro unchecked-divide-int
260+
([& xs] `(/ ~@xs)))
261+
262+
(defmacro unchecked-inc
263+
([x] `(inc ~x)))
264+
265+
(defmacro unchecked-inc-int
266+
([x] `(inc ~x)))
267+
268+
(defmacro unchecked-multiply
269+
([& xs] `(* ~@xs)))
270+
271+
(defmacro unchecked-multiply-int
272+
([& xs] `(* ~@xs)))
273+
274+
(defmacro unchecked-negate
275+
([x] `(- ~x)))
276+
277+
(defmacro unchecked-negate-int
278+
([x] `(- ~x)))
279+
280+
(defmacro unchecked-remainder-int
281+
([x n] `(mod ~x n)))
282+
283+
(defmacro unchecked-subtract
284+
([& xs] `(- ~@xs)))
285+
286+
(defmacro unchecked-subtract-int
287+
([& xs] `(- ~@xs)))
288+
227289
(defmacro -
228290
([x] (list 'js* "(- ~{})" x))
229291
([x y] (list 'js* "(~{} - ~{})" x y))
@@ -1130,7 +1192,7 @@
11301192
(~print-fn (str ~bs-str ", " ~expr-str ", "
11311193
~iterations " runs, " elapsed# " msecs"))))))
11321194

1133-
(def cs (into [] (map (comp symbol core/str char) (range 97 118))))
1195+
(def cs (into [] (map (comp symbol core/str core/char) (range 97 118))))
11341196

11351197
(defn gen-apply-to-helper
11361198
([] (gen-apply-to-helper 1))

src/cljs/cljs/core.cljs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,88 @@ reduces them without incurring seq initialization"
13611361
([x y & more]
13621362
(reduce min (cljs.core/min x y) more)))
13631363

1364+
(defn byte [x] x)
1365+
(defn char [x] x)
1366+
(defn short [x] x)
1367+
(defn float [x] x)
1368+
(defn double [x] x)
1369+
1370+
(defn unchecked-byte [x] x)
1371+
(defn unchecked-char [x] x)
1372+
(defn unchecked-short [x] x)
1373+
(defn unchecked-float [x] x)
1374+
(defn unchecked-double [x] x)
1375+
1376+
(defn unchecked-add
1377+
"Returns the sum of nums. (+) returns 0."
1378+
([] 0)
1379+
([x] x)
1380+
([x y] (cljs.core/unchecked-add x y))
1381+
([x y & more] (reduce unchecked-add (cljs.core/unchecked-add x y) more)))
1382+
1383+
(defn unchecked-add-int
1384+
"Returns the sum of nums. (+) returns 0."
1385+
([] 0)
1386+
([x] x)
1387+
([x y] (cljs.core/unchecked-add-int x y))
1388+
([x y & more] (reduce unchecked-add-int (cljs.core/unchecked-add-int x y) more)))
1389+
1390+
(defn unchecked-dec [x]
1391+
(cljs.core/unchecked-dec x))
1392+
1393+
(defn unchecked-dec-int [x]
1394+
(cljs.core/unchecked-dec-int x))
1395+
1396+
(defn unchecked-divide-int
1397+
"If no denominators are supplied, returns 1/numerator,
1398+
else returns numerator divided by all of the denominators."
1399+
([x] (unchecked-divide-int 1 x))
1400+
([x y] (js* "(~{x} / ~{y})")) ;; FIXME: waiting on cljs.core//
1401+
([x y & more] (reduce unchecked-divide-int (unchecked-divide-int x y) more)))
1402+
1403+
(defn unchecked-inc [x]
1404+
(cljs.core/unchecked-inc x))
1405+
1406+
(defn unchecked-inc-int [x]
1407+
(cljs.core/unchecked-inc-int x))
1408+
1409+
(defn unchecked-multiply
1410+
"Returns the product of nums. (*) returns 1."
1411+
([] 1)
1412+
([x] x)
1413+
([x y] (cljs.core/unchecked-multiply x y))
1414+
([x y & more] (reduce unchecked-multiply (cljs.core/unchecked-multiply x y) more)))
1415+
1416+
(defn unchecked-multiply-int
1417+
"Returns the product of nums. (*) returns 1."
1418+
([] 1)
1419+
([x] x)
1420+
([x y] (cljs.core/unchecked-multiply-int x y))
1421+
([x y & more] (reduce unchecked-multiply-int (cljs.core/unchecked-multiply-int x y) more)))
1422+
1423+
(defn unchecked-negate [x]
1424+
(cljs.core/unchecked-negate x))
1425+
1426+
(defn unchecked-negate-int [x]
1427+
(cljs.core/unchecked-negate-int ~x))
1428+
1429+
(defn unchecked-remainder-int [x n]
1430+
(cljs.core/unchecked-remainder-int x n))
1431+
1432+
(defn unchecked-substract
1433+
"If no ys are supplied, returns the negation of x, else subtracts
1434+
the ys from x and returns the result."
1435+
([x] (cljs.core/unchecked-subtract x))
1436+
([x y] (cljs.core/unchecked-subtract x y))
1437+
([x y & more] (reduce unchecked-substract (cljs.core/unchecked-subtract x y) more)))
1438+
1439+
(defn unchecked-substract-int
1440+
"If no ys are supplied, returns the negation of x, else subtracts
1441+
the ys from x and returns the result."
1442+
([x] (cljs.core/unchecked-subtract-int x))
1443+
([x y] (cljs.core/unchecked-subtract-int x y))
1444+
([x y & more] (reduce unchecked-substract-int (cljs.core/unchecked-subtract-int x y) more)))
1445+
13641446
(defn- fix [q]
13651447
(if (>= q 0)
13661448
(Math/floor q)
@@ -1371,11 +1453,21 @@ reduces them without incurring seq initialization"
13711453
[x]
13721454
(fix x))
13731455

1456+
(defn unchecked-int
1457+
"Coerce to int by stripping decimal places."
1458+
[x]
1459+
(fix x))
1460+
13741461
(defn long
13751462
"Coerce to long by stripping decimal places. Identical to `int'."
13761463
[x]
13771464
(fix x))
13781465

1466+
(defn unchecked-long
1467+
"Coerce to long by stripping decimal places. Identical to `int'."
1468+
[x]
1469+
(fix x))
1470+
13791471
(defn js-mod
13801472
"Modulus of num and div with original javascript behavior. i.e. bug for negative numbers"
13811473
[n d]

0 commit comments

Comments
 (0)