Add typed Kotlin Float32 fixed formatter
ober
72e8809c61fd49a715fcdaaf693e3e07708fe363
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -461,6 +461,9 @@ (cons 'float32-round->int32 (make-typed-call-sig (list 'Float32) 'Int32 '() 'jvm-float32-round-to-int32 '())) + (cons 'float32-fixed3 + (make-typed-call-sig (list 'Float32) 'String '() + 'jvm-float32-fixed3 '())) (cons 'string-take (make-typed-call-sig (list 'String 'Int32) 'String '() 'jvm-string-take '())) --- a/lib/jerboa/typed/core.ss +++ b/lib/jerboa/typed/core.ss @@ -129,6 +129,7 @@ integer->le-bytes make-bytevector jvm-bytes-lower-hex + jvm-float32-fixed3 exact->inexact log2 debug-string --- a/lib/jerboa/typed/kotlin/lower.ss +++ b/lib/jerboa/typed/kotlin/lower.ss @@ -262,6 +262,11 @@ '())] [(jvm-float32-round-to-int32) (make-kt-call (make-kt-name '(java lang Math round)) args)] + [(jvm-float32-fixed3) + (make-kt-member-call + (make-kt-lit 'String "%.3f") + 'format + args)] [(string-length) (make-kt-member-call (make-kt-member-get (car args) 'length) --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -435,14 +435,17 @@ (define float32-math-form '(typed-library (sample typed floatmath) - (export near spread) + (export near spread fixed3) (type Float32) + (type String) (type Int32) (def (near (a : Float32) (b : Float32)) : Bool (<= (float32-abs (- a b)) (float32 (float32-round->int32 (* (float32 0.25) a))))) (def (spread (a : Float32) (b : Float32)) : Float32 - (float32-ln (float32-max a b))))) + (float32-ln (float32-max a b))) + (def (fixed3 (x : Float32)) : String + (float32-fixed3 x)))) (define float32-math-kotlin (typed-library-form->kotlin-string float32-math-form)) @@ -454,6 +457,8 @@ "kotlin.math.ln(kotlin.math.max(a, b).toDouble()).toFloat()") (test-contains "Float32 round to Int32 lowers to Java Math.round" float32-math-kotlin "java.lang.Math.round((0.25f * a))") +(test-contains "Float32 fixed3 lowers to String.format extension" float32-math-kotlin + "\"%.3f\".format(x)") (define array-form '(typed-library (sample typed arrays)