diff options
-rw-r--r-- | luxc/src/lux/analyser/proc/common.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/compiler/js/proc/common.clj | 68 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/proc/common.clj | 4 | ||||
-rw-r--r-- | stdlib/source/lux/math.lux | 3 | ||||
-rw-r--r-- | stdlib/test/test/lux/math.lux | 3 |
5 files changed, 68 insertions, 14 deletions
diff --git a/luxc/src/lux/analyser/proc/common.clj b/luxc/src/lux/analyser/proc/common.clj index c91074676..050877ed5 100644 --- a/luxc/src/lux/analyser/proc/common.clj +++ b/luxc/src/lux/analyser/proc/common.clj @@ -391,8 +391,6 @@ ^:private analyse-math-log "log" ^:private analyse-math-root2 "root2" ^:private analyse-math-root3 "root3" - ^:private analyse-math-degrees "degrees" - ^:private analyse-math-radians "radians" ^:private analyse-math-ceil "ceil" ^:private analyse-math-floor "floor" ^:private analyse-math-round "round" @@ -615,8 +613,6 @@ "log" (analyse-math-log analyse exo-type ?values) "root2" (analyse-math-root2 analyse exo-type ?values) "root3" (analyse-math-root3 analyse exo-type ?values) - "degrees" (analyse-math-degrees analyse exo-type ?values) - "radians" (analyse-math-radians analyse exo-type ?values) "ceil" (analyse-math-ceil analyse exo-type ?values) "floor" (analyse-math-floor analyse exo-type ?values) "round" (analyse-math-round analyse exo-type ?values) diff --git a/luxc/src/lux/compiler/js/proc/common.clj b/luxc/src/lux/compiler/js/proc/common.clj index 60ade9300..942f24c79 100644 --- a/luxc/src/lux/compiler/js/proc/common.clj +++ b/luxc/src/lux/compiler/js/proc/common.clj @@ -439,6 +439,50 @@ (str "LuxRT.toNumberI64(" =milliseconds ")") ")")))) +(do-template [<name> <field>] + (defn <name> [compile ?values special-args] + (|do [:let [(&/$Nil) ?values]] + (return (str "Math." <field>)))) + + ^:private compile-math-e "E" + ^:private compile-math-pi "PI" + ) + +(do-template [<name> <method>] + (defn <name> [compile ?values special-args] + (|do [:let [(&/$Cons ?input (&/$Nil)) ?values] + =input (compile ?input)] + (return (str "Math." <method> "(" =input ")")))) + + ^:private compile-math-cos "cos" + ^:private compile-math-sin "sin" + ^:private compile-math-tan "tan" + ^:private compile-math-acos "acos" + ^:private compile-math-asin "asin" + ^:private compile-math-atan "atan" + ^:private compile-math-cosh "cosh" + ^:private compile-math-sinh "sinh" + ^:private compile-math-tanh "tanh" + ^:private compile-math-exp "exp" + ^:private compile-math-log "log" + ^:private compile-math-root2 "sqrt" + ^:private compile-math-root3 "cbrt" + ^:private compile-math-ceil "ceil" + ^:private compile-math-floor "floor" + ^:private compile-math-round "round" + ) + +(do-template [<name> <method>] + (defn <name> [compile ?values special-args] + (|do [:let [(&/$Cons ?input (&/$Cons ?param (&/$Nil))) ?values] + =input (compile ?input) + =param (compile ?param)] + (return (str "Math." <method> "(" =input "," =param ")")))) + + ^:private compile-math-atan2 "atan2" + ^:private compile-math-pow "pow" + ) + (defn compile-proc [compile category proc ?values special-args] (case category "lux" @@ -566,6 +610,30 @@ "to-nat" (compile-char-to-nat compile ?values special-args) ) + "math" + (case proc + "e" (compile-math-e compile ?values special-args) + "pi" (compile-math-pi compile ?values special-args) + "cos" (compile-math-cos compile ?values special-args) + "sin" (compile-math-sin compile ?values special-args) + "tan" (compile-math-tan compile ?values special-args) + "acos" (compile-math-acos compile ?values special-args) + "asin" (compile-math-asin compile ?values special-args) + "atan" (compile-math-atan compile ?values special-args) + "cosh" (compile-math-cosh compile ?values special-args) + "sinh" (compile-math-sinh compile ?values special-args) + "tanh" (compile-math-tanh compile ?values special-args) + "exp" (compile-math-exp compile ?values special-args) + "log" (compile-math-log compile ?values special-args) + "root2" (compile-math-root2 compile ?values special-args) + "root3" (compile-math-root3 compile ?values special-args) + "ceil" (compile-math-ceil compile ?values special-args) + "floor" (compile-math-floor compile ?values special-args) + "round" (compile-math-round compile ?values special-args) + "atan2" (compile-math-atan2 compile ?values special-args) + "pow" (compile-math-pow compile ?values special-args) + ) + "atom" (case proc "new" (compile-atom-new compile ?values special-args) diff --git a/luxc/src/lux/compiler/jvm/proc/common.clj b/luxc/src/lux/compiler/jvm/proc/common.clj index 6a952e6d3..b7e80dd2e 100644 --- a/luxc/src/lux/compiler/jvm/proc/common.clj +++ b/luxc/src/lux/compiler/jvm/proc/common.clj @@ -774,8 +774,6 @@ ^:private compile-math-log "log" ^:private compile-math-root2 "sqrt" ^:private compile-math-root3 "cbrt" - ^:private compile-math-degrees "toDegrees" - ^:private compile-math-radians "toRadians" ^:private compile-math-ceil "ceil" ^:private compile-math-floor "floor" ) @@ -1023,8 +1021,6 @@ "log" (compile-math-log compile ?values special-args) "root2" (compile-math-root2 compile ?values special-args) "root3" (compile-math-root3 compile ?values special-args) - "degrees" (compile-math-degrees compile ?values special-args) - "radians" (compile-math-radians compile ?values special-args) "ceil" (compile-math-ceil compile ?values special-args) "floor" (compile-math-floor compile ?values special-args) "round" (compile-math-round compile ?values special-args) diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux index 6f41b3e9b..c49e82969 100644 --- a/stdlib/source/lux/math.lux +++ b/stdlib/source/lux/math.lux @@ -47,9 +47,6 @@ [root2 "root2"] [root3 "root3"] - [degrees "degrees"] - [radians "radians"] - [ceil "ceil"] [floor "floor"] [round "round"] diff --git a/stdlib/test/test/lux/math.lux b/stdlib/test/test/lux/math.lux index 18cb1545c..769a6f889 100644 --- a/stdlib/test/test/lux/math.lux +++ b/stdlib/test/test/lux/math.lux @@ -35,9 +35,6 @@ ## (assert "Tangent and arc-tangent are inverse functions." ## (|> angle &;tan &;atan (within? margin angle))) - -## (assert "Can freely go between degrees and radians." -## (|> angle &;degrees &;radians (within? margin angle))) ## )) (test: "Roots" |