aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2022-02-19 09:29:29 -0400
committerEduardo Julian2022-02-19 09:29:29 -0400
commit2d1348a73159ec87fa0da2bd3768d641236693fb (patch)
tree812898ce66a12ef78afeb7542430d89a507783cc /stdlib
parent23f6d4d19c7f5d1f5b4f6db8a72cf52388689357 (diff)
Missing bits of the optimization.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux2
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/generation.lux8
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux24
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux7
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux6
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/implementation.lux28
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux49
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/reference.lux66
8 files changed, 99 insertions, 91 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux
index 7b8181b9c..3ca408bea 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux
@@ -75,4 +75,4 @@
("lux i64 or" @eval)
("lux i64 left-shift" 32)))
(generate archive exprS))]
- (generation.evaluate! [@module @eval] exprO)))))))
+ (generation.evaluate! [@module @eval] [{.#None} exprO])))))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux
index d130a38e6..2953b2886 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux
@@ -56,11 +56,11 @@
(type: .public (Host expression directive)
(Interface
- (: (-> unit.ID expression (Try Any))
+ (: (-> unit.ID [(Maybe unit.ID) expression] (Try Any))
evaluate)
(: (-> directive (Try Any))
execute)
- (: (-> unit.ID (Maybe Text) expression (Try [Text Any directive]))
+ (: (-> unit.ID (Maybe Text) [(Maybe unit.ID) expression] (Try [Text Any directive]))
define)
(: (-> unit.ID Binary directive)
@@ -203,7 +203,7 @@
(def: .public (evaluate! label code)
(All (_ anchor expression directive)
- (-> unit.ID expression (Operation anchor expression directive Any)))
+ (-> unit.ID [(Maybe unit.ID) expression] (Operation anchor expression directive Any)))
(function (_ (^@ state+ [bundle state]))
(case (# (value@ #host state) evaluate label code)
{try.#Success output}
@@ -225,7 +225,7 @@
(def: .public (define! context custom code)
(All (_ anchor expression directive)
- (-> unit.ID (Maybe Text) expression (Operation anchor expression directive [Text Any directive])))
+ (-> unit.ID (Maybe Text) [(Maybe unit.ID) expression] (Operation anchor expression directive [Text Any directive])))
(function (_ (^@ stateE [bundle state]))
(case (# (value@ #host state) define context custom code)
{try.#Success output}
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
index 4fb0a4715..87812e7be 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
@@ -90,7 +90,7 @@
id /////generation.next
codeG (generate archive codeS)
module_id (/////generation.module_id module archive)
- codeV (/////generation.evaluate! (..context [module_id id]) codeG)]
+ codeV (/////generation.evaluate! (..context [module_id id]) [{.#None} codeG])]
(in [code//type codeG codeV]))))
(def: .public (evaluate! archive type codeC)
@@ -124,17 +124,17 @@
[dependencies (cache/artifact.dependencies archive codeS)
[interim_artifacts codeG] (/////generation.with_interim_artifacts archive
(generate archive codeS))
- .let [function_artifact (case codeS
- (^ (/////synthesis.function/abstraction [env arity body]))
- (|> interim_artifacts
- list.last
- (maybe#each (|>> [arity])))
-
- _
- {.#None})]
+ .let [@abstraction (case codeS
+ (^ (/////synthesis.function/abstraction [env arity body]))
+ (|> interim_artifacts
+ list.last
+ (maybe#each (|>> [arity])))
+
+ _
+ {.#None})]
module_id (phase.lifted (archive.id module archive))
- @self (/////generation.learn [name function_artifact] false (list#mix set.has dependencies interim_artifacts))
- [target_name value directive] (/////generation.define! [module_id @self] {.#None} codeG)
+ @self (/////generation.learn [name @abstraction] false (list#mix set.has dependencies interim_artifacts))
+ [target_name value directive] (/////generation.define! [module_id @self] {.#None} [(maybe#each product.right @abstraction) codeG])
_ (/////generation.save! @self {.#None} directive)]
(in [code//type codeG value]))))
@@ -187,7 +187,7 @@
(generate archive codeS))
module_id (phase.lifted (archive.id current_module archive))
@self (<learn> extension (list#mix set.has dependencies interim_artifacts))
- [target_name value directive] (/////generation.define! [module_id @self] {.#None} codeG)
+ [target_name value directive] (/////generation.define! [module_id @self] {.#None} [{.#None} codeG])
_ (/////generation.save! @self {.#None} directive)]
(in [codeG value])))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux
index e01b1dd0d..d7998be17 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux
@@ -82,8 +82,8 @@
(|> (n.min arity /arity.maximum)
list.indices
(list#each (|>> ++ (/apply.method classT environment arity @begin body)))
- (list& (/implementation.method arity @begin body)))
- (list (/implementation.method arity @begin body)
+ (list& (/implementation.method classT arity @begin body)))
+ (list (/implementation.method classT arity @begin body)
(/apply.method classT environment arity @begin body 1)))))]
(do phase.monad
[instance (/new.instance generate archive classT environment arity)]
@@ -157,9 +157,8 @@
inputsG (monad.each ! (generate archive) inputsS)]
(in ($_ _.composite
abstractionG
- (_.checkcast :abstraction:)
(monad.all _.monad inputsG)
- (/implementation.call @abstraction arity)
+ (/implementation.call :abstraction: arity)
))))
(def: (apply/> generate archive [$abstraction @abstraction arity inputsS])
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux
index 5020c98c0..cd8ecbbb5 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux
@@ -90,7 +90,7 @@
0 ($_ _.composite
////reference.this
(..inputs ..this_offset apply_arity)
- (_.invokevirtual class //implementation.name (//implementation.type function_arity))
+ (//implementation.call class function_arity)
_.areturn)
_ (do _.monad
[@default _.new_label
@@ -118,7 +118,7 @@
(_#in []))
current_partials
(..inputs ..this_offset apply_arity)
- (_.invokevirtual class //implementation.name (//implementation.type function_arity))
+ (//implementation.call class function_arity)
_.areturn)
has_more_than_necessary?
@@ -129,7 +129,7 @@
(_.invokevirtual class //reset.name (//reset.type class))
current_partials
(..inputs ..this_offset arity_inputs)
- (_.invokevirtual class //implementation.name (//implementation.type function_arity))
+ (//implementation.call class function_arity)
(apply (n.+ ..this_offset arity_inputs) additional_inputs)
_.areturn))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/implementation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/implementation.lux
index ddcc315a2..924a2e21d 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/implementation.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/implementation.lux
@@ -28,18 +28,24 @@
(def: .public name "impl")
-(def: .public (type arity)
- (-> Arity (Type category.Method))
+(def: .public (type :it: arity)
+ (-> (Type Class) Arity (Type category.Method))
(type.method [(list)
- (list.repeated arity ////type.value)
+ (list& :it: (list.repeated arity ////type.value))
////type.value
(list)]))
-(def: .public (method arity @begin body)
- (-> Arity Label (Bytecode Any) (Resource Method))
- (method.method //.modifier
+(def: modifier
+ ($_ modifier#composite
+ method.static
+ //.modifier
+ ))
+
+(def: .public (method :it: arity @begin body)
+ (-> (Type Class) Arity Label (Bytecode Any) (Resource Method))
+ (method.method ..modifier
..name
- #0 (..type arity)
+ #0 (..type :it: arity)
(list)
{.#Some ($_ _.composite
(_.set_label @begin)
@@ -47,8 +53,6 @@
(_.when_continuous _.areturn)
)}))
-(def: .public (call @abstraction arity)
- (-> unit.ID Arity (Bytecode Any))
- (_.invokevirtual (type.class (runtime.class_name @abstraction) (list))
- ..name
- (..type arity)))
+(def: .public (call :it: arity)
+ (-> (Type Class) Arity (Bytecode Any))
+ (_.invokestatic :it: ..name (..type :it: arity)))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux
index e852b63a3..c9ad8c0eb 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux
@@ -46,7 +46,9 @@
[archive
["[0]" unit]]]]]]]
["[0]" // "_"
- ["[1][0]" runtime {"+" Definition}]]
+ ["[1][0]" runtime {"+" Definition}]
+ ["[1][0]" type]
+ ["[1][0]" value]]
)
(import: java/lang/reflect/Field
@@ -63,8 +65,6 @@
(import: java/lang/ClassLoader)
-(def: value::field "value")
-(def: value::type (type.class "java.lang.Object" (list)))
(def: value::modifier ($_ modifier#composite field.public field.final field.static))
(def: init::type (type.method [(list) (list) type.void (list)]))
@@ -90,7 +90,7 @@
(def: (class_value class_name class)
(-> Text (java/lang/Class java/lang/Object) (Try Any))
- (case (java/lang/Class::getField ..value::field class)
+ (case (java/lang/Class::getField //value.field class)
{try.#Success field}
(case (java/lang/reflect/Field::get {.#None} field)
{try.#Success ?value}
@@ -105,34 +105,33 @@
(exception.except ..cannot_load [class_name error]))
{try.#Failure error}
- (exception.except ..invalid_field [class_name ..value::field error])))
+ (exception.except ..invalid_field [class_name //value.field error])))
(def: class_path_separator
".")
-(def: .public (class_name [module_id artifact_id])
- (-> unit.ID Text)
- (format lux_context
- ..class_path_separator (%.nat version)
- ..class_path_separator (%.nat module_id)
- ..class_path_separator (%.nat artifact_id)))
-
-(def: (evaluate! library loader eval_class valueG)
- (-> Library java/lang/ClassLoader Text (Bytecode Any) (Try [Any Definition]))
+(def: (evaluate! library loader eval_class [@it valueG])
+ (-> Library java/lang/ClassLoader Text [(Maybe unit.ID) (Bytecode Any)] (Try [Any Definition]))
(let [bytecode_name (text.replaced class_path_separator .module_separator eval_class)
+ :value: (case @it
+ {.#Some @it}
+ (type.class (//runtime.class_name @it) (list))
+
+ {.#None}
+ //type.value)
bytecode (class.class version.v6_0
class.public
(encoding/name.internal bytecode_name)
{.#None}
(encoding/name.internal "java.lang.Object") (list)
- (list (field.field ..value::modifier ..value::field #0 ..value::type (sequence.sequence)))
+ (list (field.field ..value::modifier //value.field #0 :value: (sequence.sequence)))
(list (method.method ..init::modifier "<clinit>"
#0 ..init::type
(list)
{.#Some
($_ _.composite
valueG
- (_.putstatic (type.class bytecode_name (list)) ..value::field ..value::type)
+ (_.putstatic (type.class bytecode_name (list)) //value.field :value:)
_.return)}))
(sequence.sequence))]
(io.run! (do [! (try.with io.monad)]
@@ -157,12 +156,12 @@
(loader.store class_name class_bytecode library))]
(loader.load class_name loader))))
-(def: (define! library loader context custom valueG)
- (-> Library java/lang/ClassLoader unit.ID (Maybe Text) (Bytecode Any) (Try [Text Any Definition]))
- (let [class_name (maybe.else (..class_name context)
+(def: (define! library loader context custom @it,valueG)
+ (-> Library java/lang/ClassLoader unit.ID (Maybe Text) [(Maybe unit.ID) (Bytecode Any)] (Try [Text Any Definition]))
+ (let [class_name (maybe.else (//runtime.class_name context)
custom)]
(do try.monad
- [[value definition] (evaluate! library loader class_name valueG)]
+ [[value definition] (evaluate! library loader class_name @it,valueG)]
(in [class_name value definition]))))
(def: .public host
@@ -172,9 +171,9 @@
[loader
(: //runtime.Host
(implementation
- (def: (evaluate context valueG)
+ (def: (evaluate context @it,valueG)
(# try.monad each product.left
- (..evaluate! library loader (format "E" (..class_name context)) valueG)))
+ (..evaluate! library loader (format "E" (//runtime.class_name context)) @it,valueG)))
(def: execute
(..execute! library loader))
@@ -183,15 +182,15 @@
(..define! library loader))
(def: (ingest context bytecode)
- [(..class_name context) bytecode])
+ [(//runtime.class_name context) bytecode])
(def: (re_learn context custom [_ bytecode])
- (io.run! (loader.store (maybe.else (..class_name context) custom) bytecode library)))
+ (io.run! (loader.store (maybe.else (//runtime.class_name context) custom) bytecode library)))
(def: (re_load context custom [directive_name bytecode])
(io.run!
(do (try.with io.monad)
- [.let [class_name (maybe.else (..class_name context)
+ [.let [class_name (maybe.else (//runtime.class_name context)
custom)]
_ (loader.store class_name bytecode library)
class (loader.load class_name loader)]
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/reference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/reference.lux
index c197cb81a..cc36c0cd2 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/reference.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/reference.lux
@@ -1,30 +1,30 @@
(.using
- [library
- [lux "*"
- [abstract
- [monad {"+" do}]]
- [data
- [text
- ["%" format {"+" format}]]]
- [target
- [jvm
- ["_" bytecode {"+" Bytecode}]
- ["[0]" type]
- [encoding
- ["[0]" unsigned]]]]]]
- ["[0]" // "_"
- ["[1][0]" runtime {"+" Operation}]
- ["[1][0]" value]
- ["[1][0]" type]
- ["//[1]" /// "_"
- [//
- ["[0]" generation]
- [///
- ["[1]" phase ("operation#[0]" monad)]
- [reference
- ["[0]" variable {"+" Register Variable}]]
- [meta
- [archive {"+" Archive}]]]]]])
+ [library
+ [lux "*"
+ [abstract
+ [monad {"+" do}]]
+ [data
+ [text
+ ["%" format {"+" format}]]]
+ [target
+ [jvm
+ ["_" bytecode {"+" Bytecode}]
+ ["[0]" type]
+ [encoding
+ ["[0]" unsigned]]]]]]
+ ["[0]" // "_"
+ ["[1][0]" runtime {"+" Operation}]
+ ["[1][0]" value]
+ ["[1][0]" type]
+ ["//[1]" /// "_"
+ [//
+ ["[0]" generation]
+ [///
+ ["[1]" phase ("operation#[0]" monad)]
+ [reference
+ ["[0]" variable {"+" Register Variable}]]
+ [meta
+ [archive {"+" Archive}]]]]]])
(def: .public this
(Bytecode Any)
@@ -61,7 +61,13 @@
(def: .public (constant archive name)
(-> Archive Symbol (Operation (Bytecode Any)))
- (do [! ////.monad]
- [bytecode_name (# ! each //runtime.class_name
- (generation.remember archive name))]
- (in (_.getstatic (type.class bytecode_name (list)) //value.field //type.value))))
+ (do ////.monad
+ [[@definition |abstraction|] (generation.definition archive name)
+ .let [:definition: (type.class (//runtime.class_name @definition) (list))]]
+ (in (case |abstraction|
+ {.#Some [_ {.#Some [expected_arity @abstraction]}]}
+ (let [:abstraction: (type.class (//runtime.class_name @abstraction) (list))]
+ (_.getstatic :definition: //value.field :abstraction:))
+
+ _
+ (_.getstatic :definition: //value.field //type.value)))))