diff --git a/host/chez/java/host-class.ss b/host/chez/java/host-class.ss index b2844c1..1deaac0 100644 --- a/host/chez/java/host-class.ss +++ b/host/chez/java/host-class.ss @@ -91,6 +91,7 @@ '(("String" . "java.lang.String") ("Number" . "java.lang.Number") ("Boolean" . "java.lang.Boolean") ("Long" . "java.lang.Long") ("Integer" . "java.lang.Integer") ("Double" . "java.lang.Double") + ("Float" . "java.lang.Float") ("Byte" . "java.lang.Byte") ("Short" . "java.lang.Short") ("Object" . "java.lang.Object") ("Character" . "java.lang.Character") ("InputStream" . "java.io.InputStream") ("OutputStream" . "java.io.OutputStream") ("File" . "java.io.File") ("Reader" . "java.io.Reader") ("Writer" . "java.io.Writer") @@ -160,6 +161,7 @@ (for-each (lambda (nm) (def-var! "clojure.core" nm nm)) '("java.lang.Long" "java.lang.Integer" "java.lang.Double" "java.lang.Float" + "java.lang.Byte" "java.lang.Short" "java.lang.Number" "java.lang.String" "java.lang.Boolean" "java.lang.Character" "java.lang.Object" ;; exception classes compared against (class e): (= java.net.SocketTimeoutException (class e)) diff --git a/host/chez/java/host-static-methods.ss b/host/chez/java/host-static-methods.ss index 8977d88..8a98f6e 100644 --- a/host/chez/java/host-static-methods.ss +++ b/host/chez/java/host-static-methods.ss @@ -136,6 +136,19 @@ (cons "toBinaryString" (lambda (x) (number->string (int->u32 (jnum->exact x)) 2))) (cons "toString" (lambda (x . r) (number->string (jnum->exact x) (if (null? r) 10 (jnum->exact (car r)))))))) +;; Byte / Short bounds (their values are plain integers on jolt; the statics let +;; libraries reference the JVM ranges — clojure.test.check generates over them). +(register-class-statics! "Byte" + (list (cons "MAX_VALUE" (->num 127)) (cons "MIN_VALUE" (->num -128)) + (cons "valueOf" (lambda (x . r) (->num (if (number? x) x (parse-int-or-throw x 10 "valueOf"))))) + (cons "parseByte" (lambda (x . r) (parse-int-or-throw x (if (null? r) 10 (jnum->exact (car r))) "parseByte"))) + (cons "toString" (lambda (x . r) (number->string (jnum->exact x)))))) +(register-class-statics! "Short" + (list (cons "MAX_VALUE" (->num 32767)) (cons "MIN_VALUE" (->num -32768)) + (cons "valueOf" (lambda (x . r) (->num (if (number? x) x (parse-int-or-throw x 10 "valueOf"))))) + (cons "parseShort" (lambda (x . r) (parse-int-or-throw x (if (null? r) 10 (jnum->exact (car r))) "parseShort"))) + (cons "toString" (lambda (x . r) (number->string (jnum->exact x)))))) + (register-class-statics! "Boolean" (list (cons "parseBoolean" (lambda (s) (string=? "true" (ascii-string-down (if (string? s) s (jolt-str-render-one s)))))) (cons "TRUE" #t) (cons "FALSE" #f))) diff --git a/test/chez/corpus.edn b/test/chez/corpus.edn index 5c810f7..956a6b8 100644 --- a/test/chez/corpus.edn +++ b/test/chez/corpus.edn @@ -3301,4 +3301,5 @@ {:suite "defn / attr-map" :label "attr-map on a multi-arity defn" :expected "true" :actual "(do (defn h \"d\" {:my :a} ([] 1) ([a] a)) (= :a (:my (meta (var h)))))"} {:suite "defn / attr-map" :label "attr-map values are evaluated" :expected "true" :actual "(do (defn m {:val (+ 1 2)} [] 1) (= 3 (:val (meta (var m)))))"} {:suite "records / clojure.lang interop" :label "a record's Associative/ILookup methods delegate to the map fns" :expected "[1 9 true true 2]" :actual "(do (defrecord M [a b]) (let [m (->M 1 2)] [(.valAt m :a) (.valAt m :z 9) (= {:a 1 :b 2 :c 3} (into {} (.assoc m :c 3))) (.containsKey m :a) (.count m)]))"} + {:suite "interop / number classes" :label "Byte/Short bounds + class tokens" :expected "[127 -128 32767 -32768 true]" :actual "[Byte/MAX_VALUE Byte/MIN_VALUE Short/MAX_VALUE Short/MIN_VALUE (= java.lang.Byte java.lang.Byte)]"} ]