Permalink
Browse files

some missing compatibility fns & macors

  • Loading branch information...
1 parent 4652498 commit 1d1a8124f886c42fdec14df7b63cef9bfee8a401 @swannodette swannodette committed Feb 21, 2013
Showing with 186 additions and 28 deletions.
  1. +26 −26 devnotes/corelib.org
  2. +5 −1 src/clj/cljs/analyzer.clj
  3. +63 −1 src/clj/cljs/core.clj
  4. +92 −0 src/cljs/cljs/core.cljs
View
@@ -114,12 +114,12 @@ does what?
* bound-fn*
* bound?
* DONE butlast
-* TODO byte
+* DONE byte
* byte-array
* bytes
* DONE case
* cast
-* char
+* DONE char
* char-array
* char-escape-string
* char-name-string
@@ -197,7 +197,7 @@ For macros only, uses clojure.core version
* dosync
* DONE dotimes
* DONE doto
-* TODO double
+* DONE double
* DONE double-array
* TODO doubles
* DONE drop
@@ -232,7 +232,7 @@ macro currently expands into extend call
* find-var
* DONE first
* DONE flatten
-* float
+* DONE float
* float-array
* float?
* floats
@@ -479,7 +479,7 @@ as macro
* set-error-mode!
* set-validator!
* DONE set?
-* short
+* DONE short
* short-array
* shorts
* TODO shuffle
@@ -525,27 +525,27 @@ as macro
* DONE tree-seq
* DONE true?
* DONE type - returns JS constructor
-* TODO unchecked-add
-* TODO unchecked-add-int
-* TODO unchecked-byte
-* TODO unchecked-char
-* TODO unchecked-dec
-* TODO unchecked-dec-int
-* TODO unchecked-divide-int
-* TODO unchecked-double
-* TODO unchecked-float
-* TODO unchecked-inc
-* TODO unchecked-inc-int
-* TODO unchecked-int
-* TODO unchecked-long
-* TODO unchecked-multiply
-* TODO unchecked-multiply-int
-* TODO unchecked-negate
-* TODO unchecked-negate-int
-* TODO unchecked-remainder-int
-* TODO unchecked-short
-* TODO unchecked-subtract
-* TODO unchecked-subtract-int
+* DONE unchecked-add
+* DONE unchecked-add-int
+* DONE unchecked-byte
+* DONE unchecked-char
+* DONE unchecked-dec
+* DONE unchecked-dec-int
+* DONE unchecked-divide-int
+* DONE unchecked-double
+* DONE unchecked-float
+* DONE unchecked-inc
+* DONE unchecked-inc-int
+* DONE unchecked-int
+* DONE unchecked-long
+* DONE unchecked-multiply
+* DONE unchecked-multiply-int
+* DONE unchecked-negate
+* DONE unchecked-negate-int
+* DONE unchecked-remainder-int
+* DONE unchecked-short
+* DONE unchecked-subtract
+* DONE unchecked-subtract-int
* DONE underive
* unquote
* unquote-splicing
@@ -383,6 +383,8 @@
{:name fld
:field true
:mutable (-> fld meta :mutable)
+ :unsynchronized-mutable (-> fld meta :unsynchronized-mutable)
+ :volatile-mutable (-> fld meta :volatile-mutable)
:tag (-> fld meta :tag)
:shadow (m fld)}))
locals fields)
@@ -554,7 +556,9 @@
(let [local (-> env :locals target)]
(assert (or (nil? local)
(and (:field local)
- (:mutable local)))
+ (or (:mutable local)
+ (:unsynchronized-mutable local)
+ (:volatile-mutable local))))
"Can't set! local var or non-mutable field"))
(analyze-symbol enve target))
View
@@ -19,6 +19,14 @@
aget aset
+ - * / < <= > >= == zero? pos? neg? inc dec max min mod
+ byte char short int long float double
+ unchecked-byte unchecked-char unchecked-short unchecked-int
+ unchecked-long unchecked-float unchecked-double
+ unchecked-add unchecked-add-int unchecked-dec unchecked-dec-int
+ unchecked-divide unchecked-divide-int unchecked-inc unchecked-inc-int
+ unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int
+ unchecked-subtract unchecked-subtract-int unchecked-remainder-int
+
bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set
bit-test bit-shift-left bit-shift-right bit-xor])
(:require clojure.walk))
@@ -224,6 +232,60 @@
([x y] (list 'js* "(~{} + ~{})" x y))
([x y & more] `(+ (+ ~x ~y) ~@more)))
+(defmacro byte [x] x)
+(defmacro char [x] x)
+(defmacro short [x] x)
+(defmacro float [x] x)
+(defmacro double [x] x)
+
+(defmacro unchecked-byte [x] x)
+(defmacro unchecked-char [x] x)
+(defmacro unchecked-short [x] x)
+(defmacro unchecked-float [x] x)
+(defmacro unchecked-double [x] x)
+
+(defmacro unchecked-add
+ ([& xs] `(+ ~@xs)))
+
+(defmacro unchecked-add-int
+ ([& xs] `(+ ~@xs)))
+
+(defmacro unchecked-dec
+ ([x] `(dec ~x)))
+
+(defmacro unchecked-dec-int
+ ([x] `(dec ~x)))
+
+(defmacro unchecked-divide-int
+ ([& xs] `(/ ~@xs)))
+
+(defmacro unchecked-inc
+ ([x] `(inc ~x)))
+
+(defmacro unchecked-inc-int
+ ([x] `(inc ~x)))
+
+(defmacro unchecked-multiply
+ ([& xs] `(* ~@xs)))
+
+(defmacro unchecked-multiply-int
+ ([& xs] `(* ~@xs)))
+
+(defmacro unchecked-negate
+ ([x] `(- ~x)))
+
+(defmacro unchecked-negate-int
+ ([x] `(- ~x)))
+
+(defmacro unchecked-remainder-int
+ ([x n] `(mod ~x n)))
+
+(defmacro unchecked-subtract
+ ([& xs] `(- ~@xs)))
+
+(defmacro unchecked-subtract-int
+ ([& xs] `(- ~@xs)))
+
(defmacro -
([x] (list 'js* "(- ~{})" x))
([x y] (list 'js* "(~{} - ~{})" x y))
@@ -1130,7 +1192,7 @@
(~print-fn (str ~bs-str ", " ~expr-str ", "
~iterations " runs, " elapsed# " msecs"))))))
-(def cs (into [] (map (comp symbol core/str char) (range 97 118))))
+(def cs (into [] (map (comp symbol core/str core/char) (range 97 118))))
(defn gen-apply-to-helper
([] (gen-apply-to-helper 1))
View
@@ -1361,6 +1361,88 @@ reduces them without incurring seq initialization"
([x y & more]
(reduce min (cljs.core/min x y) more)))
+(defn byte [x] x)
+(defn char [x] x)
+(defn short [x] x)
+(defn float [x] x)
+(defn double [x] x)
+
+(defn unchecked-byte [x] x)
+(defn unchecked-char [x] x)
+(defn unchecked-short [x] x)
+(defn unchecked-float [x] x)
+(defn unchecked-double [x] x)
+
+(defn unchecked-add
+ "Returns the sum of nums. (+) returns 0."
+ ([] 0)
+ ([x] x)
+ ([x y] (cljs.core/unchecked-add x y))
+ ([x y & more] (reduce unchecked-add (cljs.core/unchecked-add x y) more)))
+
+(defn unchecked-add-int
+ "Returns the sum of nums. (+) returns 0."
+ ([] 0)
+ ([x] x)
+ ([x y] (cljs.core/unchecked-add-int x y))
+ ([x y & more] (reduce unchecked-add-int (cljs.core/unchecked-add-int x y) more)))
+
+(defn unchecked-dec [x]
+ (cljs.core/unchecked-dec x))
+
+(defn unchecked-dec-int [x]
+ (cljs.core/unchecked-dec-int x))
+
+(defn unchecked-divide-int
+ "If no denominators are supplied, returns 1/numerator,
+ else returns numerator divided by all of the denominators."
+ ([x] (unchecked-divide-int 1 x))
+ ([x y] (js* "(~{x} / ~{y})")) ;; FIXME: waiting on cljs.core//
+ ([x y & more] (reduce unchecked-divide-int (unchecked-divide-int x y) more)))
+
+(defn unchecked-inc [x]
+ (cljs.core/unchecked-inc x))
+
+(defn unchecked-inc-int [x]
+ (cljs.core/unchecked-inc-int x))
+
+(defn unchecked-multiply
+ "Returns the product of nums. (*) returns 1."
+ ([] 1)
+ ([x] x)
+ ([x y] (cljs.core/unchecked-multiply x y))
+ ([x y & more] (reduce unchecked-multiply (cljs.core/unchecked-multiply x y) more)))
+
+(defn unchecked-multiply-int
+ "Returns the product of nums. (*) returns 1."
+ ([] 1)
+ ([x] x)
+ ([x y] (cljs.core/unchecked-multiply-int x y))
+ ([x y & more] (reduce unchecked-multiply-int (cljs.core/unchecked-multiply-int x y) more)))
+
+(defn unchecked-negate [x]
+ (cljs.core/unchecked-negate x))
+
+(defn unchecked-negate-int [x]
+ (cljs.core/unchecked-negate-int ~x))
+
+(defn unchecked-remainder-int [x n]
+ (cljs.core/unchecked-remainder-int x n))
+
+(defn unchecked-substract
+ "If no ys are supplied, returns the negation of x, else subtracts
+ the ys from x and returns the result."
+ ([x] (cljs.core/unchecked-subtract x))
+ ([x y] (cljs.core/unchecked-subtract x y))
+ ([x y & more] (reduce unchecked-substract (cljs.core/unchecked-subtract x y) more)))
+
+(defn unchecked-substract-int
+ "If no ys are supplied, returns the negation of x, else subtracts
+ the ys from x and returns the result."
+ ([x] (cljs.core/unchecked-subtract-int x))
+ ([x y] (cljs.core/unchecked-subtract-int x y))
+ ([x y & more] (reduce unchecked-substract-int (cljs.core/unchecked-subtract-int x y) more)))
+
(defn- fix [q]
(if (>= q 0)
(Math/floor q)
@@ -1371,11 +1453,21 @@ reduces them without incurring seq initialization"
[x]
(fix x))
+(defn unchecked-int
+ "Coerce to int by stripping decimal places."
+ [x]
+ (fix x))
+
(defn long
"Coerce to long by stripping decimal places. Identical to `int'."
[x]
(fix x))
+(defn unchecked-long
+ "Coerce to long by stripping decimal places. Identical to `int'."
+ [x]
+ (fix x))
+
(defn js-mod
"Modulus of num and div with original javascript behavior. i.e. bug for negative numbers"
[n d]

0 comments on commit 1d1a812

Please sign in to comment.