aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler
diff options
context:
space:
mode:
authorEduardo Julian2022-06-14 02:33:54 -0400
committerEduardo Julian2022-06-14 02:33:54 -0400
commitc4d938ebb2f5245b4c3faa22c4f217e7e818589f (patch)
treeb4ffb4ece96cd711c270932ca500c49192c6bb46 /stdlib/source/library/lux/tool/compiler
parent63dec2e80905100ae2b48ada1d4e0d675338d00f (diff)
Better syntax for invoking super methods inside overriden methods.
Diffstat (limited to 'stdlib/source/library/lux/tool/compiler')
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux87
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux20
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux142
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux10
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux9
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux8
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux8
7 files changed, 246 insertions, 38 deletions
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
index bb307180d..e285ff15a 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
@@ -14,7 +14,8 @@
["<>" parser (.only)
["<[0]>" code (.only Parser)]]]
[data
- [binary (.only Binary)]
+ [binary (.only Binary)
+ ["[0]" \\format]]
["[0]" product]
["[0]" text (.open: "[1]#[0]" equivalence)
["%" \\format (.only format)]
@@ -23,9 +24,7 @@
["[0]" list (.open: "[1]#[0]" mix monad monoid)]
["[0]" array]
["[0]" dictionary (.only Dictionary)]
- ["[0]" sequence]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" sequence]]]
[macro
["^" pattern]
["[0]" template]]
@@ -79,6 +78,8 @@
["[0]" scope]]
[///
["[0]" phase (.open: "[1]#[0]" monad)]
+ ["[0]" reference (.only)
+ ["[0]" variable]]
[meta
[archive (.only Archive)
[module
@@ -2235,6 +2236,74 @@
(/////analysis.tuple (list forced_refencing bodyA))]
(list)]}))))
+(def: (with_fake_parameter#pattern it)
+ (-> pattern.Pattern pattern.Pattern)
+ (case it
+ {pattern.#Simple _}
+ it
+
+ {pattern.#Complex it}
+ {pattern.#Complex
+ (case it
+ {complex.#Variant it}
+ {complex.#Variant (revised complex.#value with_fake_parameter#pattern it)}
+
+ {complex.#Tuple it}
+ {complex.#Tuple (list#each with_fake_parameter#pattern it)})}
+
+ {pattern.#Bind it}
+ {pattern.#Bind (++ it)}))
+
+(def: (with_fake_parameter it)
+ (-> Analysis Analysis)
+ (case it
+ {/////analysis.#Simple _}
+ it
+
+ {/////analysis.#Structure it}
+ {/////analysis.#Structure
+ (case it
+ {complex.#Variant it}
+ {complex.#Variant (revised complex.#value with_fake_parameter it)}
+
+ {complex.#Tuple it}
+ {complex.#Tuple (list#each with_fake_parameter it)})}
+
+ {/////analysis.#Reference it}
+ {/////analysis.#Reference
+ (case it
+ {reference.#Variable it}
+ {reference.#Variable
+ (case it
+ {variable.#Local it}
+ {variable.#Local (++ it)}
+
+ {variable.#Foreign _}
+ it)}
+
+ {reference.#Constant _}
+ it)}
+
+ {/////analysis.#Case value [head tail]}
+ {/////analysis.#Case (with_fake_parameter value)
+ (let [with_fake_parameter (is (-> /////analysis.Branch /////analysis.Branch)
+ (|>> (revised /////analysis.#when with_fake_parameter#pattern)
+ (revised /////analysis.#then with_fake_parameter)))]
+ [(with_fake_parameter head)
+ (list#each with_fake_parameter tail)])}
+
+ {/////analysis.#Function environment body}
+ {/////analysis.#Function (list#each with_fake_parameter environment)
+ body}
+
+ {/////analysis.#Apply parameter abstraction}
+ {/////analysis.#Apply (with_fake_parameter parameter)
+ (with_fake_parameter abstraction)}
+
+ {/////analysis.#Extension name parameters}
+ {/////analysis.#Extension name
+ (list#each with_fake_parameter parameters)}))
+
(def: .public (analyse_overriden_method analyse archive selfT mapping supers method)
(-> Phase Archive .Type Mapping (List (Type Class)) (Overriden_Method Code) (Operation Analysis))
(let [[parent_type method_name
@@ -2265,7 +2334,8 @@
list.reversed
(list#mix scope.with_local (analyse archive body))
(typeA.expecting :return:)
- scope.with)]
+ scope.with)
+ .let [arity (list.size arguments)]]
(in (/////analysis.tuple (list (/////analysis.text ..overriden_tag)
(class_analysis parent_type)
(/////analysis.text method_name)
@@ -2280,7 +2350,10 @@
{/////analysis.#Function
(list#each (|>> /////analysis.variable)
(scope.environment scope))
- (..hidden_method_body (list.size arguments) bodyA)}
+ (<| (..hidden_method_body arity)
+ (case arity
+ 0 (with_fake_parameter bodyA)
+ _ bodyA))}
))))))
(def: (matched? [sub sub_method subJT] [super super_method superJT])
@@ -2394,7 +2467,7 @@
(let [signature (signature.inheritance (list#each jvm.signature parameters)
(jvm.signature super)
(list#each jvm.signature interfaces))]
- (try#each (|>> (format.result class.writer)
+ (try#each (|>> (\\format.result class.writer)
[name])
(class.class version.v6_0
(all modifier#composite
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux
index 9198eff46..957b2339d 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux
@@ -12,8 +12,9 @@
["<[0]>" code (.only Parser)]
["<[0]>" synthesis]]]
[data
- [binary (.only Binary)]
["[0]" product]
+ [binary (.only Binary)
+ ["[0]" \\format]]
["[0]" text
["%" \\format (.only format)]
["<[1]>" \\parser]]
@@ -21,9 +22,7 @@
["[0]" list (.open: "[1]#[0]" functor mix)]
["[0]" dictionary]
["[0]" sequence]
- ["[0]" set (.only Set)]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" set (.only Set)]]]
[macro
["^" pattern]
["[0]" template]]
@@ -331,7 +330,7 @@
(<synthesis>.tuple (<>.some ..annotation_synthesis))
(<synthesis>.tuple (<>.some ..var_type_synthesis))
<synthesis>.text
- (do <>.monad
+ (do [! <>.monad]
[args (<synthesis>.tuple (<>.some ..argument_synthesis))]
(all <>.and
(in args)
@@ -533,7 +532,10 @@
(do [! phase.monad]
[.let [[super method_name strict_floating_point? annotations
method_tvars self arguments returnJ exceptionsJ
- bodyS] method]
+ bodyS] method
+ bodyS (case (list.size arguments)
+ 0 (host.without_fake_parameter bodyS)
+ _ bodyS)]
generate directive.generation]
(directive.lifted_generation
(do !
@@ -684,7 +686,7 @@
(let [signature (signature.inheritance (list#each type.signature parameters)
(type.signature super)
(list#each type.signature interfaces))]
- (try#each (|>> (format.result class.writer)
+ (try#each (|>> (\\format.result class.writer)
[name])
(class.class version.v6_0
(all modifier#composite
@@ -901,7 +903,7 @@
(the [directive.#generation directive.#phase] state)])
methods)
.let [all_dependencies (cache.all (list#each product.left methods))]
- bytecode (<| (at ! each (format.result class.writer))
+ bytecode (<| (at ! each (\\format.result class.writer))
phase.lifted
(class.class version.v6_0
(all modifier#composite
@@ -940,7 +942,7 @@
(function (_ extension_name phase archive [[name parameters] supers annotations method_declarations])
(directive.lifted_generation
(do [! phase.monad]
- [bytecode (<| (at ! each (format.result class.writer))
+ [bytecode (<| (at ! each (\\format.result class.writer))
phase.lifted
(class.class version.v6_0
(all modifier#composite
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux
index 6f5057d00..30ef58a77 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux
@@ -10,6 +10,8 @@
["<[0]>" synthesis (.only Parser)]]]
[data
["[0]" product]
+ [binary
+ ["[0]" \\format]]
["[0]" text (.open: "[1]#[0]" equivalence)
["%" \\format]
["<[1]>" \\parser]]
@@ -17,9 +19,7 @@
["[0]" list (.open: "[1]#[0]" monad mix monoid)]
["[0]" dictionary (.only Dictionary)]
["[0]" set (.only Set)]
- ["[0]" sequence]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" sequence]]]
[macro
["^" pattern]
["[0]" template]]
@@ -64,9 +64,10 @@
[analysis
["/" jvm]]]
["/[1]" //
- [analysis (.only Environment)]
["[1][0]" synthesis (.only Synthesis Path %synthesis)]
["[1][0]" generation]
+ [analysis (.only Environment)
+ ["[0]" complex]]
[///
["[1]" phase]
["[1][0]" reference (.only)
@@ -846,6 +847,129 @@
_
<oops>)))
+(def: (without_fake_parameter#path without_fake_parameter)
+ (-> (-> Synthesis Synthesis)
+ (-> Path Path))
+ (function (again it)
+ (case it
+ (^.or {//////synthesis.#Pop}
+ {//////synthesis.#Access _})
+ it
+
+ {//////synthesis.#Bind it}
+ {//////synthesis.#Bind (-- it)}
+
+ {//////synthesis.#Bit_Fork when then else}
+ {//////synthesis.#Bit_Fork when
+ (again then)
+ (maybe#each again else)}
+
+ (^.with_template [<tag>]
+ [{<tag> [head tail]}
+ {<tag> [(revised //////synthesis.#then again head)
+ (list#each (revised //////synthesis.#then again) tail)]}])
+ ([//////synthesis.#I64_Fork]
+ [//////synthesis.#F64_Fork]
+ [//////synthesis.#Text_Fork])
+
+ (^.with_template [<tag>]
+ [{<tag> left right}
+ {<tag> (again left) (again right)}])
+ ([//////synthesis.#Seq]
+ [//////synthesis.#Alt])
+
+ {//////synthesis.#Then it}
+ {//////synthesis.#Then (without_fake_parameter it)})))
+
+(def: .public (without_fake_parameter it)
+ (-> Synthesis Synthesis)
+ (case it
+ {//////synthesis.#Simple _}
+ it
+
+ {//////synthesis.#Structure it}
+ {//////synthesis.#Structure
+ (case it
+ {complex.#Variant it}
+ {complex.#Variant (revised complex.#value without_fake_parameter it)}
+
+ {complex.#Tuple it}
+ {complex.#Tuple (list#each without_fake_parameter it)})}
+
+ {//////synthesis.#Reference it}
+ {//////synthesis.#Reference
+ (case it
+ {//////reference.#Variable it}
+ {//////reference.#Variable
+ (case it
+ {//////variable.#Local it}
+ {//////variable.#Local (-- it)}
+
+ {//////variable.#Foreign _}
+ it)}
+
+ {//////reference.#Constant _}
+ it)}
+
+ {//////synthesis.#Control it}
+ {//////synthesis.#Control
+ (case it
+ {//////synthesis.#Branch it}
+ {//////synthesis.#Branch
+ (case it
+ {//////synthesis.#Exec before after}
+ {//////synthesis.#Exec (without_fake_parameter before)
+ (without_fake_parameter after)}
+
+ {//////synthesis.#Let value register body}
+ {//////synthesis.#Let (without_fake_parameter value)
+ (-- register)
+ (without_fake_parameter body)}
+
+ {//////synthesis.#If when then else}
+ {//////synthesis.#If (without_fake_parameter when)
+ (without_fake_parameter then)
+ (without_fake_parameter else)}
+
+ {//////synthesis.#Get members record}
+ {//////synthesis.#Get members
+ (without_fake_parameter record)}
+
+ {//////synthesis.#Case value path}
+ {//////synthesis.#Case (without_fake_parameter value)
+ (without_fake_parameter#path without_fake_parameter path)})}
+
+ {//////synthesis.#Loop it}
+ {//////synthesis.#Loop
+ (case it
+ {//////synthesis.#Scope [//////synthesis.#start start
+ //////synthesis.#inits inits
+ //////synthesis.#iteration iteration]}
+ {//////synthesis.#Scope [//////synthesis.#start (-- start)
+ //////synthesis.#inits (list#each without_fake_parameter inits)
+ //////synthesis.#iteration iteration]}
+
+ {//////synthesis.#Again _}
+ it)}
+
+ {//////synthesis.#Function it}
+ {//////synthesis.#Function
+ (case it
+ {//////synthesis.#Abstraction [//////synthesis.#environment environment
+ //////synthesis.#arity arity
+ //////synthesis.#body body]}
+ {//////synthesis.#Abstraction [//////synthesis.#environment (list#each without_fake_parameter environment)
+ //////synthesis.#arity arity
+ //////synthesis.#body body]}
+
+ {//////synthesis.#Apply [//////synthesis.#function function
+ //////synthesis.#arguments arguments]}
+ {//////synthesis.#Apply [//////synthesis.#function (without_fake_parameter function)
+ //////synthesis.#arguments (list#each without_fake_parameter arguments)]})})}
+
+ {//////synthesis.#Extension name parameters}
+ {//////synthesis.#Extension name (list#each without_fake_parameter parameters)}))
+
(def: overriden_method_definition
(Parser [(Environment Synthesis) (/.Overriden_Method Synthesis)])
(<synthesis>.tuple (do <>.monad
@@ -863,12 +987,16 @@
(<synthesis>.loop (<>.exactly 0 <synthesis>.any))
<synthesis>.tuple
(<>.after <synthesis>.any)
- <synthesis>.any)]
+ <synthesis>.any)
+ .let [arity (list.size arguments)]]
(in [environment
[ownerT name
strict_fp? annotations vars
self_name arguments returnT exceptionsT
- (..hidden_method_body (list.size arguments) body)]]))))
+ (<| (..hidden_method_body arity)
+ (case arity
+ 0 (without_fake_parameter body)
+ _ body))]]))))
(def: (normalize_path normalize)
(-> (-> Synthesis Synthesis)
@@ -1222,7 +1350,7 @@
methods! (|> overriden_methods
(list#each (normalized_method global_mapping))
(monad.each ! (method_definition generate archive artifact_id)))
- bytecode (<| (at ! each (format.result class.writer))
+ bytecode (<| (at ! each (\\format.result class.writer))
//////.lifted
(class.class version.v6_0 (all modifier#composite class.public class.final)
(name.internal anonymous_class_name)
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 3de519160..a87be42cc 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
@@ -5,22 +5,22 @@
["[0]" monad (.only do)]]
[data
["[0]" product]
+ [binary
+ ["[0]" \\format]]
[collection
["[0]" list (.open: "[1]#[0]" monoid functor)]
- ["[0]" sequence]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" sequence]]]
[math
[number
["n" nat]
["[0]" i32]]]
[target
[jvm
+ ["_" bytecode (.only Label Bytecode) (.open: "[1]#[0]" monad)]
["[0]" version]
["[0]" modifier (.only Modifier) (.open: "[1]#[0]" monoid)]
["[0]" field (.only Field)]
["[0]" method (.only Method)]
- ["_" bytecode (.only Label Bytecode) (.open: "[1]#[0]" monad)]
["[0]" class (.only Class)]
["[0]" type (.only Type)
[category (.only Return' Value')]
@@ -122,7 +122,7 @@
fields
methods
(sequence.sequence)))
- .let [bytecode [function_class (format.result class.writer class)]]
+ .let [bytecode [function_class (\\format.result class.writer class)]]
_ (generation.execute! bytecode)
_ (generation.save! (product.right function_context) {.#None} bytecode)]
(in instance)))
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 0a1eba71c..eb8478a41 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
@@ -12,16 +12,15 @@
[concurrency
["[0]" atom (.only Atom atom)]]]
[data
- [binary (.only Binary)]
+ [binary (.only Binary)
+ ["[0]" \\format]]
["[0]" product]
["[0]" text (.open: "[1]#[0]" hash)
["%" \\format (.only format)]]
[collection
["[0]" array]
["[0]" dictionary (.only Dictionary)]
- ["[0]" sequence]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" sequence]]]
[target
[jvm
["_" bytecode (.only Bytecode)]
@@ -132,7 +131,7 @@
_.return)}))
(sequence.sequence))]
(io.run! (do [! (try.with io.monad)]
- [bytecode (at ! each (format.result class.writer)
+ [bytecode (at ! each (\\format.result class.writer)
(io.io bytecode))
_ (loader.store eval_class bytecode library)
class (loader.load eval_class loader)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux
index 6f9aa8aa3..a81896178 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux
@@ -6,10 +6,10 @@
[control
["[0]" try]]
[data
+ [binary
+ ["[0]" \\format]]
[collection
- ["[0]" sequence]]
- ["[0]" format
- ["[1]" binary]]]
+ ["[0]" sequence]]]
[target
[jvm
["_" bytecode (.only Bytecode)]
@@ -155,7 +155,7 @@
_.return)})
class (artifact_name context)]
[class
- (<| (format.result class.writer)
+ (<| (\\format.result class.writer)
try.trusted
(class.class version.v6_0
..program::modifier
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux
index 9b61d3737..c4a772695 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux
@@ -59,8 +59,14 @@
[#locals 0
#currying? false])
+(type: .public (Road value next)
+ (Record
+ [#when value
+ #then next]))
+
(type: .public (Fork value next)
- [[value next] (List [value next])])
+ [(Road value next)
+ (List (Road value next))])
(type: .public (Path' s)
(Variant