Support Kotlin Float32 interop type
ober
44099aa03262a79a870b4a7baa7145d956abfb92
--- a/docs/typed-kotlin.md +++ b/docs/typed-kotlin.md @@ -15,6 +15,11 @@ by the Rust and LLVM work: comparison, boolean operations, record construction/access, variant construction, and simple `for/fold`. +For JVM/Android interop, a typed module may declare nominal external types with +`(type ...)`. The Kotlin backend preserves those names, except for the +conventional `(type Float32)`, which lowers to Kotlin `Float` for APIs such as +Android graphics and ML Kit models. + Public entry points: ```scheme --- a/lib/jerboa/typed/kotlin/lower.ss +++ b/lib/jerboa/typed/kotlin/lower.ss @@ -84,6 +84,7 @@ [(Int Fixnum) (make-kt-type 'Long #f '())] [(Nat) (make-kt-type 'ULong #f '())] [(Float) (make-kt-type 'Double #f '())] + [(Float32) (make-kt-type 'Float #f '())] [(String) (make-kt-type 'String #f '())] [(Bytes) (make-kt-type 'ByteArray #f '())] [(Symbol Keyword) (make-kt-type 'String #f '())] --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -126,5 +126,20 @@ (test-contains "variant constructor lowering" data-kotlin "return EditOp.Insert(at, text)") +(define jvm-form + '(typed-library (sample typed jvm) + (export make-OcrWord OcrWord? OcrWord-conf) + (type Float32) + (type FloatArray) + (record OcrWord + ((text : String) + (conf : Float32) + (bbox : FloatArray))))) + +(define jvm-kotlin (typed-library-form->kotlin-string jvm-form)) + +(test-contains "declared Float32 lowers to JVM Float" jvm-kotlin + "data class OcrWord(val text: String, val conf: Float, val bbox: FloatArray)") + (printf "typed-kotlin tests: ~a passed, ~a failed~%" pass fail) (when (> fail 0) (exit 1))