aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-01-21 12:58:48 -0400
committerEduardo Julian2018-01-21 12:58:48 -0400
commit498af2e0123c1ce65e46bf15fe3854266ad58f53 (patch)
treee8235092c959b91c4328c838450a9ac391e0cbcc /new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux
parent002ee0418195afccd1a1b500a36cc5b2adc44791 (diff)
- WIP: Host procedures for JS.
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.lux56
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))