From 31d7f09f2c410951948134bb3045b2ca0147327d Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 17 Apr 2019 19:37:59 -0400 Subject: Some adjustments of the stdlib for the new JVM compiler. --- stdlib/source/lux/data/collection/list.lux | 13 +++-- stdlib/source/lux/data/collection/row.lux | 28 +++++----- stdlib/source/lux/data/text.lux | 10 +++- stdlib/source/lux/math.lux | 83 +++++++++++++++++++++--------- 4 files changed, 89 insertions(+), 45 deletions(-) diff --git a/stdlib/source/lux/data/collection/list.lux b/stdlib/source/lux/data/collection/list.lux index bf4661ad4..fa18cfd19 100644 --- a/stdlib/source/lux/data/collection/list.lux +++ b/stdlib/source/lux/data/collection/list.lux @@ -10,7 +10,10 @@ [predicate (#+ Predicate)]] [data ["." bit] - ["." product]]]) + ["." product]] + [tool + [compiler + ["." host]]]]) ## (type: (List a) ## #Nil @@ -551,10 +554,10 @@ (do monad [lMla MlMla ## TODO: Remove this version ASAP and use one below. - lla (: (($ 0) (List (List ($ 1)))) - (monad.seq @ lMla)) - ## lla (monad.seq @ lMla) - ] + lla (`` (for {(~~ (static host.old)) + (: (($ 0) (List (List ($ 1)))) + (monad.seq @ lMla))} + (monad.seq @ lMla)))] (wrap (concat lla))))) (def: #export (lift monad) diff --git a/stdlib/source/lux/data/collection/row.lux b/stdlib/source/lux/data/collection/row.lux index 2dc45312f..1810ca828 100644 --- a/stdlib/source/lux/data/collection/row.lux +++ b/stdlib/source/lux/data/collection/row.lux @@ -20,7 +20,10 @@ ["." array (#+ Array) ("#@." functor fold)]]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + ["s" syntax (#+ syntax: Syntax)]] + [tool + [compiler + ["@" host]]]]) (type: (Node a) (#Base (Array a)) @@ -206,10 +209,10 @@ ## If so, a brand-new root must be established, that is ## 1-level taller. (|> row - (set@ #root (|> (: (Hierarchy ($ 0)) - (new-hierarchy [])) - ## TODO: Remove version above once new-luxc becomes the standard compiler. - ## (new-hierarchy []) + (set@ #root (|> (`` (for {(~~ (static @.old)) + (: (Hierarchy ($ 0)) + (new-hierarchy []))} + (new-hierarchy []))) (array.write 0 (#Hierarchy (get@ #root row))) (array.write 1 (new-path (get@ #level row) (get@ #tail row))))) (update@ #level level-up)) @@ -258,14 +261,13 @@ (if (and (n/>= 0 idx) (n/< row-size idx)) (if (n/>= (tail-off row-size) idx) - (|> row - ## (update@ #tail (|>> array.clone (array.write (branch-idx idx) val))) - ## TODO: Remove once new-luxc becomes the standard compiler. - (update@ #tail (: (-> (Base ($ 0)) (Base ($ 0))) - (|>> array.clone (array.write (branch-idx idx) val)))) - ) - (|> row - (update@ #root (put' (get@ #level row) idx val)))) + (update@ #tail (`` (for {(~~ (static @.old)) + (: (-> (Base ($ 0)) (Base ($ 0))) + (|>> array.clone (array.write (branch-idx idx) val)))} + (|>> array.clone (array.write (branch-idx idx) val)))) + row) + (update@ #root (put' (get@ #level row) idx val) + row)) row))) (def: #export (update idx f row) diff --git a/stdlib/source/lux/data/text.lux b/stdlib/source/lux/data/text.lux index da3f4cd36..3174c9b8f 100644 --- a/stdlib/source/lux/data/text.lux +++ b/stdlib/source/lux/data/text.lux @@ -1,8 +1,6 @@ (.module: [lux #* [abstract - [fold (#+)] - [functor (#+)] hash [monoid (#+ Monoid)] [equivalence (#+ Equivalence)] @@ -207,6 +205,14 @@ (: (primitive "java.lang.String" [])) "jvm invokevirtual:java.lang.String:hashCode:" "jvm convert int-to-long" + (:coerce Nat)) + + (~~ (static host.jvm)) + (|> input + (:coerce (primitive "java.lang.String")) + ("jvm member invoke virtual" "java.lang.String" "hashCode") + "jvm object cast" + "jvm conversion int-to-long" (:coerce Nat))} ## Platform-independent default. (let [length ("lux text size" input)] diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux index 747f1337f..3916622cf 100644 --- a/stdlib/source/lux/math.lux +++ b/stdlib/source/lux/math.lux @@ -1,7 +1,9 @@ (.module: {#.doc "Common mathematical constants and functions."} - [lux #*]) + [lux #* + [tool + [compiler + ["." host]]]]) -## [Values] (template [ ] [(def: #export {#.doc } @@ -13,25 +15,60 @@ [tau +6.28318530717958647692 "The ratio of a circle's circumference to its radius."] ) -(template [ ] - [(def: #export ( input) - (-> Frac Frac) - ( input))] - - [cos "jvm invokestatic:java.lang.Math:cos:double"] - [sin "jvm invokestatic:java.lang.Math:sin:double"] - [tan "jvm invokestatic:java.lang.Math:tan:double"] - - [acos "jvm invokestatic:java.lang.Math:acos:double"] - [asin "jvm invokestatic:java.lang.Math:asin:double"] - [atan "jvm invokestatic:java.lang.Math:atan:double"] - - [exp "jvm invokestatic:java.lang.Math:exp:double"] - [log "jvm invokestatic:java.lang.Math:log:double"] - - [ceil "jvm invokestatic:java.lang.Math:ceil:double"] - [floor "jvm invokestatic:java.lang.Math:floor:double"] - ) +(`` (for {(~~ (static host.old)) + (as-is (template [ ] + [(def: #export ( input) + (-> Frac Frac) + ( input))] + + [cos "jvm invokestatic:java.lang.Math:cos:double"] + [sin "jvm invokestatic:java.lang.Math:sin:double"] + [tan "jvm invokestatic:java.lang.Math:tan:double"] + + [acos "jvm invokestatic:java.lang.Math:acos:double"] + [asin "jvm invokestatic:java.lang.Math:asin:double"] + [atan "jvm invokestatic:java.lang.Math:atan:double"] + + [exp "jvm invokestatic:java.lang.Math:exp:double"] + [log "jvm invokestatic:java.lang.Math:log:double"] + + [ceil "jvm invokestatic:java.lang.Math:ceil:double"] + [floor "jvm invokestatic:java.lang.Math:floor:double"] + ) + (def: #export (pow param subject) + (-> Frac Frac Frac) + ("jvm invokestatic:java.lang.Math:pow:double,double" subject param))) + + (~~ (static host.jvm)) + (as-is (template: (!double value) (|> value (:coerce (primitive "java.lang.Double")) "jvm object cast")) + (template: (!frac value) (|> value "jvm object cast" (: (primitive "java.lang.Double")) (:coerce Frac))) + (template [ ] + [(def: #export + (-> Frac Frac) + (|>> !double + ["double"] + ("jvm member invoke static" "java.lang.Math" ) + !frac))] + + [cos "cos"] + [sin "sin"] + [tan "tan"] + + [acos "acos"] + [asin "asin"] + [atan "atan"] + + [exp "exp"] + [log "log"] + + [ceil "ceil"] + [floor "floor"] + ) + (def: #export (pow param subject) + (-> Frac Frac Frac) + (|> ("jvm member invoke static" "java.lang.Math" "pow" + ["double" (!double subject)] ["double" (!double param)]) + !frac)))})) (def: #export (round input) (-> Frac Frac) @@ -46,10 +83,6 @@ ## else floored))) -(def: #export (pow param subject) - (-> Frac Frac Frac) - ("jvm invokestatic:java.lang.Math:pow:double,double" subject param)) - (def: #export (atan2 param subject) (-> Frac Frac Frac) (cond (f/> +0.0 param) -- cgit v1.2.3