aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux
diff options
context:
space:
mode:
authorEduardo Julian2021-12-31 00:58:08 -0400
committerEduardo Julian2021-12-31 00:58:08 -0400
commit9afaa3a3236366d57cb1c3d771b25779ee76269b (patch)
tree83016d292711e242be3bdaef4dd2cca0aae05dc9 /stdlib/source/library/lux
parent00d92539208da86557e592a8c8df03d3b08e6b40 (diff)
Fixes for the pure-Lux JVM compiler machinery.
Diffstat (limited to 'stdlib/source/library/lux')
-rw-r--r--stdlib/source/library/lux/target/python.lux9
-rw-r--r--stdlib/source/library/lux/target/ruby.lux15
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux44
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux4
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/abstract.lux7
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux138
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux32
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/type.lux4
8 files changed, 122 insertions, 131 deletions
diff --git a/stdlib/source/library/lux/target/python.lux b/stdlib/source/library/lux/target/python.lux
index 79a15c682..6d3746721 100644
--- a/stdlib/source/library/lux/target/python.lux
+++ b/stdlib/source/library/lux/target/python.lux
@@ -1,6 +1,6 @@
(.using
[library
- [lux {"-" Location Code Label not or and list if cond int comment exec try}
+ [lux {"-" Location Code Label not or and list if int comment exec try}
["@" target]
["[0]" ffi]
[abstract
@@ -454,13 +454,6 @@
(:representation on))))
)
-(def: .public (cond clauses else!)
- (-> (List [(Expression Any) (Statement Any)]) (Statement Any) (Statement Any))
- (list#mix (.function (_ [test then!] next!)
- (..if test then! next!))
- else!
- (list.reversed clauses)))
-
(syntax: (arity_inputs [arity <code>.nat])
(in (case arity
0 (.list)
diff --git a/stdlib/source/library/lux/target/ruby.lux b/stdlib/source/library/lux/target/ruby.lux
index 3280ac134..b2c9088dc 100644
--- a/stdlib/source/library/lux/target/ruby.lux
+++ b/stdlib/source/library/lux/target/ruby.lux
@@ -1,6 +1,6 @@
(.using
[library
- [lux {"-" Location Code static int if cond function or and not comment local global symbol}
+ [lux {"-" Location Code static int if function or and not comment local global symbol}
["@" target]
[abstract
[equivalence {"+" Equivalence}]
@@ -202,14 +202,14 @@
:abstraction))
(def: .public array
- (-> (List Expression) Literal)
+ (-> (List Expression) Computation)
(|>> (list#each (|>> :representation))
(text.interposed ..input_separator)
(text.enclosed ["[" "]"])
:abstraction))
(def: .public hash
- (-> (List [Expression Expression]) Literal)
+ (-> (List [Expression Expression]) Computation)
(|>> (list#each (.function (_ [k v])
(format (:representation k) " => " (:representation v))))
(text.interposed ..input_separator)
@@ -374,7 +374,7 @@
(..nested (:representation body!)))))
(def: .public (lambda name args body!)
- (-> (Maybe LVar) (List Var) Statement Literal)
+ (-> (Maybe LVar) (List Var) Statement Computation)
(let [proc (|> (format (|> args
(list#each (|>> :representation))
(text.interposed ..input_separator)
@@ -456,13 +456,6 @@
(-> (List Expression) Expression Computation)
(..do "call" args {.#None} lambda))
-(def: .public (cond clauses else!)
- (-> (List [Expression Statement]) Statement Statement)
- (list#mix (.function (_ [test then!] next!)
- (..if test then! next!))
- else!
- (list.reversed clauses)))
-
(syntax: (arity_inputs [arity <code>.nat])
(in (case arity
0 (.list)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux
index d960e465d..76cf4f82a 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux
@@ -1,26 +1,26 @@
(.using
- [library
- [lux "*"
- [abstract
- ["[0]" monad {"+" do}]]
- [control
- pipe
- ["[0]" try]
- ["[0]" exception {"+" exception:}]]
- [data
- ["[0]" text ("[1]#[0]" equivalence)
- ["%" format {"+" format}]]
- [collection
- ["[0]" list ("[1]#[0]" mix functor)]
- [dictionary
- ["[0]" plist]]]]
- ["[0]" meta]]]
- ["[0]" /// "_"
- ["[1][0]" extension]
- [//
- ["/" analysis {"+" Operation}]
- [///
- ["[1]" phase]]]])
+ [library
+ [lux "*"
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ pipe
+ ["[0]" try]
+ ["[0]" exception {"+" exception:}]]
+ [data
+ ["[0]" text ("[1]#[0]" equivalence)
+ ["%" format {"+" format}]]
+ [collection
+ ["[0]" list ("[1]#[0]" mix functor)]
+ [dictionary
+ ["[0]" plist]]]]
+ ["[0]" meta]]]
+ ["[0]" /// "_"
+ ["[1][0]" extension]
+ [//
+ ["/" analysis {"+" Operation}]
+ [///
+ ["[1]" phase]]]])
(type: .public Tag Text)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
index 0d2774331..d4f994a5d 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
@@ -118,8 +118,8 @@
($_ _.composite
..peek
(_.checkcast //type.variant)
- (//structure.tag lefts <right?>)
- (//structure.flag <right?>)
+ (//structure.lefts lefts <right?>)
+ (//structure.right? <right?>)
//runtime.case
_.dup
(_.ifnull @fail)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/abstract.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/abstract.lux
index 2601cda6d..d8bd53835 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/abstract.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/abstract.lux
@@ -13,11 +13,12 @@
[constant
["[0]" arity]]]])
-(def: .public artifact_id
- 1)
+... (def: .public artifact_id
+... 1)
(def: .public class
- (type.class (%.nat artifact_id) (list)))
+ ... (type.class (%.nat artifact_id) (list))
+ (type.class "library.lux.Function" (list)))
(def: .public init
(Type Method)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
index c753851bc..fccfabf64 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
@@ -90,9 +90,9 @@
(def: .public (class_name [module id])
(-> generation.Context Text)
(format lux_context
- "/" (%.nat version.version)
- "/" (%.nat module)
- "/" (%.nat id)))
+ "." (%.nat version.version)
+ "." (%.nat module)
+ "." (%.nat id)))
(def: artifact_id
0)
@@ -135,40 +135,40 @@
(def: .public unit (_.string synthesis.unit))
(def: variant::name "variant")
-(def: variant::type (type.method [(list) (list //type.tag //type.flag //type.value) //type.variant (list)]))
+(def: variant::type (type.method [(list) (list //type.lefts //type.right? //type.value) //type.variant (list)]))
(def: .public variant (..procedure ..variant::name ..variant::type))
-(def: variant_tag _.iconst_0)
-(def: variant_last? _.iconst_1)
+(def: variant_lefts _.iconst_0)
+(def: variant_right? _.iconst_1)
(def: variant_value _.iconst_2)
(def: variant::method
(let [new_variant ($_ _.composite
_.iconst_3
(_.anewarray //type.value))
- $tag ($_ _.composite
- _.iload_0
- (//value.wrap type.int))
- $last? _.aload_1
+ $lefts ($_ _.composite
+ _.iload_0
+ (//value.wrap type.int))
+ $right? _.aload_1
$value _.aload_2]
(method.method ..modifier ..variant::name
..variant::type
(list)
{.#Some ($_ _.composite
- new_variant ... A[3]
- (..set! ..variant_tag $tag) ... A[3]
- (..set! ..variant_last? $last?) ... A[3]
- (..set! ..variant_value $value) ... A[3]
+ new_variant ... A[3]
+ (..set! ..variant_lefts $lefts) ... A[3]
+ (..set! ..variant_right? $right?) ... A[3]
+ (..set! ..variant_value $value) ... A[3]
_.areturn)})))
-(def: .public left_flag _.aconst_null)
-(def: .public right_flag ..unit)
+(def: .public left_right? _.aconst_null)
+(def: .public right_right? ..unit)
(def: .public left_injection
(Bytecode Any)
($_ _.composite
_.iconst_0
- ..left_flag
+ ..left_right?
_.dup2_x1
_.pop2
..variant))
@@ -176,8 +176,8 @@
(def: .public right_injection
(Bytecode Any)
($_ _.composite
- _.iconst_1
- ..right_flag
+ _.iconst_0
+ ..right_right?
_.dup2_x1
_.pop2
..variant))
@@ -188,7 +188,7 @@
(Bytecode Any)
($_ _.composite
_.iconst_0
- ..left_flag
+ ..left_right?
..unit
..variant))
@@ -288,7 +288,7 @@
_.areturn))}))
(def: case::name "case")
-(def: case::type (type.method [(list) (list //type.variant //type.tag //type.flag) //type.value (list)]))
+(def: case::type (type.method [(list) (list //type.variant //type.lefts //type.right?) //type.value (list)]))
(def: .public case (..procedure ..case::name ..case::type))
(def: case::method
@@ -298,68 +298,72 @@
(do _.monad
[@loop _.new_label
@perfect_match! _.new_label
- @tags_match! _.new_label
+ @lefts_match! _.new_label
@maybe_nested _.new_label
@mismatch! _.new_label
- .let [::tag ($_ _.composite
- (..get ..variant_tag)
- (//value.unwrap type.int))
- ::last? (..get ..variant_last?)
+ .let [$variant _.aload_0
+ $lefts _.iload_1
+ $right? _.aload_2
+
+ ::lefts ($_ _.composite
+ (..get ..variant_lefts)
+ (//value.unwrap type.int))
+ ::right? (..get ..variant_right?)
::value (..get ..variant_value)
- $variant _.aload_0
- $tag _.iload_1
- $last? _.aload_2
-
not_found _.aconst_null
- update_$tag _.isub
+ super_nested_lefts ($_ _.composite
+ _.swap
+ _.isub
+ (_.int (i32.i32 (.i64 +1)))
+ _.isub)
+ super_nested ($_ _.composite
+ ... lefts, sumT
+ super_nested_lefts ... super_lefts
+ $variant ::right? ... super_lefts, super_right
+ $variant ::value ... super_lefts, super_right, super_value
+ ..variant)
+
update_$variant ($_ _.composite
$variant ::value
(_.checkcast //type.variant)
_.astore_0)
- recur (: (-> Label (Bytecode Any))
- (function (_ @loop_start)
+ update_$lefts ($_ _.composite
+ _.isub
+ (_.int (i32.i32 (.i64 +1)))
+ _.isub)
+ again (: (-> Label (Bytecode Any))
+ (function (_ @)
($_ _.composite
- ... tag, sumT
- update_$variant ... tag, sumT
- update_$tag ... sub_tag
- (_.goto @loop_start))))
-
- super_nested_tag ($_ _.composite
- ... tag, sumT
- _.swap ... sumT, tag
- _.isub)
- super_nested ($_ _.composite
- ... tag, sumT
- super_nested_tag ... super_tag
- $variant ::last? ... super_tag, super_last
- $variant ::value ... super_tag, super_last, super_value
- ..variant)]]
+ ... lefts, sumT
+ update_$variant ... lefts, sumT
+ update_$lefts ... sub_lefts
+ (_.goto @))))]]
($_ _.composite
- $tag
+ $lefts
(_.set_label @loop)
- $variant ::tag
- _.dup2 (_.if_icmpeq @tags_match!)
+ $variant ::lefts
+ _.dup2 (_.if_icmpeq @lefts_match!)
_.dup2 (_.if_icmpgt @maybe_nested)
- $last? (_.ifnull @mismatch!) ... tag, sumT
+ $right? (_.ifnull @mismatch!) ... lefts, sumT
super_nested ... super_variant
_.areturn
- (_.set_label @tags_match!) ... tag, sumT
- $last? ... tag, sumT, wants_last?
- $variant ::last? ... tag, sumT, wants_last?, is_last?
- (_.if_acmpeq @perfect_match!) ... tag, sumT
- (_.set_label @maybe_nested) ... tag, sumT
- $variant ::last? ... tag, sumT, last?
- (_.ifnull @mismatch!) ... tag, sumT
- (recur @loop)
- (_.set_label @perfect_match!) ... tag, sumT
+ (_.set_label @lefts_match!) ... lefts, sumT
+ $right? ... lefts, sumT, wants_right?
+ $variant ::right? ... lefts, sumT, wants_right?, is_right?
+ (_.if_acmpeq @perfect_match!) ... lefts, sumT
+ (_.set_label @mismatch!) ... lefts, sumT
... _.pop2
- $variant ::value
+ not_found
_.areturn
- (_.set_label @mismatch!) ... tag, sumT
+ (_.set_label @maybe_nested) ... lefts, sumT
+ $variant ::right? ... lefts, sumT, right?
+ (_.ifnull @mismatch!) ... lefts, sumT
+ (again @loop)
+ (_.set_label @perfect_match!) ... lefts, sumT
... _.pop2
- not_found
+ $variant ::value
_.areturn
))}))
@@ -599,8 +603,10 @@
(list& <init>::method apply::method+)
(sequence.sequence)))]
(do ////.monad
- [_ (generation.execute! [class bytecode])]
- (generation.save! //function.artifact_id {.#None} [class bytecode]))))
+ [_ (generation.execute! [class bytecode])
+ ... _ (generation.save! //function.artifact_id {.#None} [class bytecode])
+ ]
+ (in []))))
(def: .public generate
(Operation [Registry Output])
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
index 0f0012727..cf9f6b02e 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
@@ -55,42 +55,40 @@
_ (_.anewarray $Object)]
(monad.all ! membersI))))))
-(def: .public (tag lefts right?)
+(def: .public (lefts lefts right?)
(-> Nat Bit (Bytecode Any))
- (case (if right?
- (.++ lefts)
- lefts)
+ (case lefts
0 _.iconst_0
1 _.iconst_1
2 _.iconst_2
3 _.iconst_3
4 _.iconst_4
5 _.iconst_5
- tag (case (signed.s1 (.int tag))
+ _ (case (signed.s1 (.int lefts))
+ {try.#Success value}
+ (_.bipush value)
+
+ {try.#Failure _}
+ (case (signed.s2 (.int lefts))
{try.#Success value}
- (_.bipush value)
+ (_.sipush value)
{try.#Failure _}
- (case (signed.s2 (.int tag))
- {try.#Success value}
- (_.sipush value)
-
- {try.#Failure _}
- (_.int (.i64 tag))))))
+ (_.int (.i64 lefts))))))
-(def: .public (flag right?)
+(def: .public (right? right?)
(-> Bit (Bytecode Any))
(if right?
- //runtime.right_flag
- //runtime.left_flag))
+ //runtime.right_right?
+ //runtime.left_right?))
(def: .public (variant phase archive [lefts right? valueS])
(Generator (Variant Synthesis))
(do phase.monad
[valueI (phase archive valueS)]
(in (do _.monad
- [_ (..tag lefts right?)
- _ (..flag right?)
+ [_ (..lefts lefts right?)
+ _ (..right? right?)
_ valueI]
(_.invokestatic //runtime.class "variant"
(type.method [(list)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/type.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/type.lux
index 893d38bbc..a7f05a114 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/type.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/type.lux
@@ -10,8 +10,8 @@
(def: .public value (type.class "java.lang.Object" (list)))
-(def: .public tag type.int)
-(def: .public flag ..value)
+(def: .public lefts type.int)
+(def: .public right? ..value)
(def: .public variant (type.array ..value))
(def: .public offset type.int)