diff options
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux b/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux new file mode 100644 index 000000000..860cc7fae --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux @@ -0,0 +1,56 @@ +(.module: + lux + (lux (control pipe) + (data [bit] + [number] + text/format) + [macro "meta/" Monad<Meta>]) + [//] + (// [".T" runtime])) + +(def: #export translate-bool + (-> Bool (Meta //.Expression)) + (|>> %b meta/wrap)) + +(def: low-mask Nat (n/dec (bit.shift-left +32 +1))) + +(def: #export (translate-nat value) + (-> Nat (Meta //.Expression)) + (let [high (|> value + (bit.shift-right +32) + nat-to-int %i) + low (|> value + (bit.and low-mask) + nat-to-int %i)] + (meta/wrap (format runtimeT.int//new "(" high "," low ")")))) + +(def: #export translate-int + (-> Int (Meta //.Expression)) + (|>> int-to-nat translate-nat)) + +(def: deg-to-nat + (-> Deg Nat) + (|>> (:! Nat))) + +(def: #export translate-deg + (-> Deg (Meta //.Expression)) + (|>> deg-to-nat translate-nat)) + +(def: #export translate-frac + (-> Frac (Meta //.Expression)) + (|>> (cond> [(f/= number.positive-infinity)] + [(new> "Infinity")] + + [(f/= number.negative-infinity)] + [(new> "-Infinity")] + + [(f/= number.not-a-number)] + [(new> "NaN")] + + ## else + [%f]) + meta/wrap)) + +(def: #export translate-text + (-> Text (Meta //.Expression)) + (|>> %t meta/wrap)) |