aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2021-06-02 00:13:17 -0400
committerEduardo Julian2021-06-02 00:13:17 -0400
commit19b14056e95bbde2f852c5ce4ed16b36c9f85217 (patch)
tree2eab6ed877761866acbb20f48628d80f5d06e4f1 /stdlib
parent26c22f6a8dccb41c41ff9f64ac1b7b2d5340baef (diff)
Struggling against the lexing limitations of Renjin.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/target/r.lux73
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux67
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux112
3 files changed, 133 insertions, 119 deletions
diff --git a/stdlib/source/lux/target/r.lux b/stdlib/source/lux/target/r.lux
index c60456ad2..2e8283a9e 100644
--- a/stdlib/source/lux/target/r.lux
+++ b/stdlib/source/lux/target/r.lux
@@ -71,11 +71,13 @@
(:abstraction
(format "(" code ")")))
+ (def: nested_new_line
+ (format text.new_line text.tab))
+
(def: nest
(-> Text Text)
- (let [nested_new_line (format text.new_line text.tab)]
- (|>> (format text.new_line)
- (text.replace_all text.new_line nested_new_line))))
+ (|>> (text.replace_all text.new_line ..nested_new_line)
+ (format ..nested_new_line)))
(def: (_block expression)
(-> Text Text)
@@ -84,12 +86,14 @@
(def: #export (block expression)
(-> Expression Expression)
(:abstraction
- (format "{" (:representation expression) "}")))
+ (format "{"
+ (..nest (:representation expression))
+ text.new_line "}")))
(template [<name> <r>]
[(def: #export <name>
Expression
- (..self_contained <r>))]
+ (:abstraction <r>))]
[null "NULL"]
[n/a "NA"]
@@ -107,11 +111,11 @@
(-> Bit Expression)
(|>> (case> #0 "FALSE"
#1 "TRUE")
- ..self_contained))
+ :abstraction))
(def: #export (int value)
(-> Int Expression)
- (..self_contained (format "as.integer(" (%.int value) ")")))
+ (:abstraction (format "as.integer(" (%.int value) ")")))
(def: #export float
(-> Frac Expression)
@@ -146,31 +150,8 @@
(def: #export string
(-> Text Expression)
- (|>> %.text ..sanitize ..self_contained))
-
- (def: (composite_literal left_delimiter right_delimiter entry_serializer)
- (All [a] (-> Text Text (-> a Text)
- (-> (List a) Expression)))
- (.function (_ entries)
- (..self_contained
- (format left_delimiter
- (|> entries (list\map entry_serializer) (text.join_with ","))
- right_delimiter))))
-
- (def: #export named_list
- (-> (List [Text Expression]) Expression)
- (composite_literal "list(" ")" (.function (_ [key value])
- (format key "=" (:representation value)))))
-
- (template [<name> <function>]
- [(def: #export <name>
- (-> (List Expression) Expression)
- (composite_literal (format <function> "(") ")" ..code))]
+ (|>> ..sanitize %.text :abstraction))
- [vector "c"]
- [list "list"]
- )
-
(def: #export (slice from to list)
(-> Expression Expression Expression Expression)
(..self_contained
@@ -185,8 +166,30 @@
(def: #export (apply args func)
(-> (List Expression) Expression Expression)
- (..self_contained
- (format (:representation func) "(" (text.join_with "," (list\map ..code args)) ")")))
+ (let [func (:representation func)
+ spacing (|> " " (list.repeat (text.size func)) (text.join_with ""))]
+ (:abstraction
+ (format func "("
+ (|> args
+ (list\map ..code)
+ (text.join_with (format "," text.new_line))
+ ..nest)
+ ")"))))
+
+ (template [<name> <function>]
+ [(def: #export (<name> members)
+ (-> (List Expression) Expression)
+ (..apply members (..var <function>)))]
+
+ [vector "c"]
+ [list "list"]
+ )
+
+ (def: #export named_list
+ (-> (List [Text Expression]) Expression)
+ (|>> (list\map (.function (_ [key value])
+ (:abstraction (format key "=" (:representation value)))))
+ ..list))
(def: #export (apply_kw args kw_args func)
(-> (List Expression) (List [Text Expression]) Expression Expression)
@@ -228,9 +231,9 @@
[0
[["commandArgs"]]]
[1
- []]
+ [["intToUtf8"]]]
[2
- []]
+ [["paste"]]]
)
(def: #export (nth idx list)
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux
index cb82c6cb4..d9178d8c2 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux
@@ -92,25 +92,25 @@
## ## (-> Expression Expression Expression))
## ## (//runtime.i64//64 (operation parameter subject)))
-## (def: i64_procs
-## Bundle
-## (<| (/.prefix "i64")
-## (|> /.empty
-## (/.install "and" (binary _.logand/2))
-## (/.install "or" (binary _.logior/2))
-## (/.install "xor" (binary _.logxor/2))
-## (/.install "left-shift" (binary _.ash/2))
-## (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift)))
-## (/.install "=" (binary _.=/2))
-## (/.install "<" (binary _.</2))
-## (/.install "+" (binary _.+/2))
-## (/.install "-" (binary _.-/2))
-## (/.install "*" (binary _.*/2))
-## (/.install "/" (binary _.floor/2))
-## (/.install "%" (binary _.rem/2))
-## ## (/.install "f64" (unary (_.//2 (_.float +1.0))))
-## (/.install "char" (unary (|>> _.code-char/1 _.string/1)))
-## )))
+(def: i64_procs
+ Bundle
+ (<| (/.prefix "i64")
+ (|> /.empty
+ ## (/.install "and" (binary _.logand/2))
+ ## (/.install "or" (binary _.logior/2))
+ ## (/.install "xor" (binary _.logxor/2))
+ ## (/.install "left-shift" (binary _.ash/2))
+ ## (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift)))
+ ## (/.install "=" (binary _.=/2))
+ ## (/.install "<" (binary _.</2))
+ ## (/.install "+" (binary _.+/2))
+ ## (/.install "-" (binary _.-/2))
+ ## (/.install "*" (binary _.*/2))
+ ## (/.install "/" (binary _.floor/2))
+ ## (/.install "%" (binary _.rem/2))
+ ## (/.install "f64" (unary (_.//2 (_.float +1.0))))
+ (/.install "char" (unary (|>> //runtime.i64_low _.intToUtf8/1)))
+ )))
## (def: f64_procs
## Bundle
@@ -140,19 +140,18 @@
## (Binary (Expression Any))
## (_.char-code/1 (_.char/2 [text index])))
-## (def: text_procs
-## Bundle
-## (<| (/.prefix "text")
-## (|> /.empty
-## (/.install "=" (binary _.string=/2))
-## ## (/.install "<" (binary (product.uncurry _.string<?/2)))
-## (/.install "concat" (binary (function (_ [left right])
-## (_.concatenate/3 [(_.symbol "string") left right]))))
-## (/.install "index" (trinary ..text//index))
-## (/.install "size" (unary _.length/1))
-## (/.install "char" (binary ..text//char))
-## (/.install "clip" (trinary ..text//clip))
-## )))
+(def: text_procs
+ Bundle
+ (<| (/.prefix "text")
+ (|> /.empty
+ ## (/.install "=" (binary _.string=/2))
+ ## (/.install "<" (binary (product.uncurry _.string<?/2)))
+ (/.install "concat" (binary _.paste/2))
+ ## (/.install "index" (trinary ..text//index))
+ ## (/.install "size" (unary _.length/1))
+ ## (/.install "char" (binary ..text//char))
+ ## (/.install "clip" (trinary ..text//clip))
+ )))
## (def: (io//log! message)
## (Unary (Expression Any))
@@ -172,8 +171,8 @@
(<| (/.prefix "lux")
(|> /.empty
## (dictionary.merge lux_procs)
- ## (dictionary.merge i64_procs)
+ (dictionary.merge i64_procs)
## (dictionary.merge f64_procs)
- ## (dictionary.merge text_procs)
+ (dictionary.merge text_procs)
## (dictionary.merge io_procs)
)))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux
index 1b7119378..326d688c2 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux
@@ -94,43 +94,11 @@
(_.named_list (list [..i64_high_field (_.int high)]
[..i64_low_field (_.int low)]))))
-(def: #export variant_tag_field "luxVT")
-(def: #export variant_flag_field "luxVF")
-(def: #export variant_value_field "luxVV")
-
-(def: #export (flag value)
- (-> Bit Expression)
- (if value
- (_.string "")
- _.null))
-
-(def: (variant' tag last? value)
- (-> Expression Expression Expression Expression)
- (_.named_list (list [..variant_tag_field tag]
- [..variant_flag_field last?]
- [..variant_value_field value])))
-
-(def: #export (variant tag last? value)
- (-> Nat Bit Expression Expression)
- (variant' (_.int (.int tag))
- (flag last?)
- value))
-
-(def: #export none
- Expression
- (variant 0 #0 ..unit))
-
-(def: #export some
- (-> Expression Expression)
- (variant 1 #1))
-
-(def: #export left
- (-> Expression Expression)
- (variant 0 #0))
-
-(def: #export right
- (-> Expression Expression)
- (variant 1 #1))
+(def: #export (lux_i64 high low)
+ (-> Int Int Int)
+ (|> high
+ (i64.left_shift 32)
+ (i64.or low)))
(syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))}
body)
@@ -180,6 +148,47 @@
(_.function (list (~+ inputsC))
(~ code))))))))))))))
+(def: #export variant_tag_field "luxVT")
+(def: #export variant_flag_field "luxVF")
+(def: #export variant_value_field "luxVV")
+
+(def: #export (flag value)
+ (-> Bit Expression)
+ (if value
+ (_.string "")
+ _.null))
+
+(def: (variant' tag last? value)
+ (-> Expression Expression Expression Expression)
+ (_.named_list (list [..variant_tag_field tag]
+ [..variant_flag_field last?]
+ [..variant_value_field value])))
+
+(runtime: (adt::variant tag last? value)
+ (..variant' tag last? value))
+
+(def: #export (variant tag last? value)
+ (-> Nat Bit Expression Expression)
+ (adt::variant (_.int (.int tag))
+ (flag last?)
+ value))
+
+(def: #export none
+ Expression
+ (variant 0 #0 ..unit))
+
+(def: #export some
+ (-> Expression Expression)
+ (variant 1 #1))
+
+(def: #export left
+ (-> Expression Expression)
+ (variant 0 #0))
+
+(def: #export right
+ (-> Expression Expression)
+ (variant 1 #1))
+
(def: high_shift (_.bit_shl (_.int +32)))
(runtime: f2^32 (|> (_.int +2) (_.** (_.int +32))))
@@ -628,6 +637,7 @@
@tuple::left
@tuple::right
@sum::get
+ @adt::variant
))
(template [<name> <op>]
@@ -667,6 +677,21 @@
(def: runtime::i64
Expression
($_ _.then
+ @f2^32
+ @f2^63
+
+ @i64::new
+ @i64::from_float
+
+ @i64::and
+ @i64::or
+ @i64::xor
+ @i64::not
+ @i64::left_shift
+ @i64::arithmetic_right_shift_32
+ @i64::arithmetic_right_shift
+ @i64::right_shift
+
@i64::zero
@i64::one
@i64::min
@@ -682,15 +707,6 @@
@i64::*
@i64::/
@i64::%
-
- @i64::and
- @i64::or
- @i64::xor
- @i64::not
- @i64::left_shift
- @i64::arithmetic_right_shift_32
- @i64::arithmetic_right_shift
- @i64::right_shift
))
(runtime: (frac::decode input)
@@ -822,10 +838,6 @@
Expression
($_ _.then
runtime::lux
- @f2^32
- @f2^63
- @i64::new
- @i64::from_float
runtime::i64
runtime::adt
runtime::frac