From 6f55815f7f237df406e72c7a723055bb6238fce5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 24 Jan 2022 04:44:32 -0400 Subject: Fixed compilation of methods for anonymous classes. --- lux-jvm/source/luxc/lang/directive/jvm.lux | 145 +++++++++++---------- .../luxc/lang/translation/jvm/extension/host.lux | 105 ++++++++++----- .../source/luxc/lang/translation/jvm/function.lux | 93 ++++++------- 3 files changed, 189 insertions(+), 154 deletions(-) (limited to 'lux-jvm') diff --git a/lux-jvm/source/luxc/lang/directive/jvm.lux b/lux-jvm/source/luxc/lang/directive/jvm.lux index 3c384b475..009bec5b4 100644 --- a/lux-jvm/source/luxc/lang/directive/jvm.lux +++ b/lux-jvm/source/luxc/lang/directive/jvm.lux @@ -1,72 +1,73 @@ (.using - [library - [lux {"-" Type Primitive static local} - ["[0]" ffi {"+" Inheritance Privacy State import:}] - [abstract - ["[0]" monad {"+" do}]] - [control - [pipe {"+" case>}] - ["[0]" try {"+" Try}] - ["<>" parser - ["<[0]>" code {"+" Parser}] - ["<[0]>" text]]] - [data - [identity {"+" Identity}] - [binary {"+" Binary}] - ["[0]" product] - [text - ["%" format {"+" format}]] - [collection - [array {"+" Array}] - ["[0]" list ("[1]#[0]" mix functor monoid)] - ["[0]" dictionary {"+" Dictionary}] - ["[0]" sequence {"+" Sequence} ("[1]#[0]" functor mix)] - ["[0]" set {"+" Set}]]] - [math - [number - ["[0]" nat]]] - [target - ["/" jvm - [encoding - ["[0]" name {"+" External}]] - ["[1][0]" type {"+" Type Typed Constraint} - [category {"+" Void Value Return Primitive Object Class Var Parameter}] - ["[0]" parser] - ["[0]T" lux] - ["[1]/[0]" signature] - ["[1]/[0]" descriptor]]]] - [tool - [compiler - ["[0]" phase] - [language - [lux - ["[0]" analysis {"+" Analysis}] - ["[0]" synthesis {"+" Synthesis}] - ["[0]" generation] - ["[0]" directive {"+" Requirements}] - [phase + [library + [lux {"-" Type Primitive static local} + ["[0]" ffi {"+" Inheritance Privacy State import:}] + [abstract + ["[0]" monad {"+" do}]] + [control + [pipe {"+" case>}] + ["[0]" try {"+" Try}] + ["<>" parser + ["<[0]>" code {"+" Parser}] + ["<[0]>" text]]] + [data + [identity {"+" Identity}] + [binary {"+" Binary}] + ["[0]" product] + [text + ["%" format {"+" format}]] + [collection + [array {"+" Array}] + ["[0]" list ("[1]#[0]" mix functor monoid)] + ["[0]" dictionary {"+" Dictionary}] + ["[0]" sequence {"+" Sequence} ("[1]#[0]" functor mix)] + ["[0]" set {"+" Set}]]] + [math + [number + ["[0]" nat]]] + [target + ["/" jvm + [encoding + ["[0]" name {"+" External}]] + ["[1][0]" type {"+" Type Typed Constraint} + [category {"+" Void Value Return Primitive Object Class Var Parameter}] + ["[0]" parser] + ["[0]T" lux] + ["[1]/[0]" signature] + ["[1]/[0]" descriptor]]]] + [tool + [compiler + ["[0]" phase] + [language + [lux + ["[0]" analysis {"+" Analysis}] + ["[0]" synthesis {"+" Synthesis}] + ["[0]" generation] + ["[0]" directive {"+" Requirements}] + [phase + [analysis + ["[0]A" scope] + ["[0]A" type]] + ["[0]" extension + ["[0]" bundle] [analysis - ["[0]A" scope] - ["[0]A" type]] - ["[0]" extension - ["[0]" bundle] - [analysis - ["//A" jvm]] - [directive - ["[0]/" lux]]]]]] - [meta - [archive {"+" Archive} - ["[0]" artifact] - ["[0]" dependency]]]]]]] - [/// - [host - ["[0]" jvm {"+" Inst} - ["_" inst] - ["[0]" def]]] - [translation - [jvm - [extension - ["//G" host]]]]]) + ["//A" jvm]] + [directive + ["[0]/" lux]]]]]] + [meta + [archive {"+" Archive} + ["[0]" artifact]] + ["[0]" cache "_" + ["[1]" artifact]]]]]]] + [/// + [host + ["[0]" jvm {"+" Inst} + ["_" inst] + ["[0]" def]]] + [translation + [jvm + [extension + ["//G" host]]]]]) (import: org/objectweb/asm/Label ["[1]::[0]" @@ -734,10 +735,10 @@ self arguments constructor_arguments body]} (do [! phase.monad] - [all_super_ctor_dependencies (monad.each ! (|>> product.right (dependency.dependencies archive)) + [all_super_ctor_dependencies (monad.each ! (|>> product.right (cache.dependencies archive)) constructor_arguments) - body_dependencies (dependency.dependencies archive body)] - (in (dependency.all (list& body_dependencies all_super_ctor_dependencies)))) + body_dependencies (cache.dependencies archive body)] + (in (cache.all (list& body_dependencies all_super_ctor_dependencies)))) (^or {#Override [[parent_name parent_variables] name strict_floating_point? annotations variables @@ -749,7 +750,7 @@ {#Static [name privacy strict_floating_point? annotations variables arguments return exceptions body]}) - (dependency.dependencies archive body) + (cache.dependencies archive body) {#Abstract _} (# phase.monad in artifact.no_dependencies))) @@ -1468,7 +1469,7 @@ methodsG (monad.each ! (method_generation archive super_class) methodsS) all_dependencies (|> methodsS (monad.each ! (method_dependencies archive)) - (# ! each dependency.all) + (# ! each cache.all) directive.lifted_generation) .let [directive [class_name (def.class {jvm.#V1_6} {jvm.#Public} jvm.noneC class_name diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux index dc806c8d0..78033cc96 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux @@ -40,8 +40,9 @@ ["[0]" variable {"+" Variable Register}]] [meta [archive {"+" Archive} - ["[0]" artifact] - ["[0]" dependency]]] + ["[0]" artifact]] + ["[0]" cache "_" + ["[1]" artifact]]] [language [lux [analysis {"+" Environment}] @@ -913,8 +914,29 @@ [synthesis.#Text_Fork]) ))) +(type: Mapping + (Dictionary Synthesis Variable)) + +(def: (local_mapping global_mapping) + (-> Mapping (Environment Synthesis) Mapping) + (|>> list.enumeration + (list#each (function (_ [foreign_id capture]) + [(synthesis.variable/foreign foreign_id) + (|> global_mapping + (dictionary.value capture) + maybe.trusted)])) + (dictionary.of_list synthesis.hash))) + +(def: (init_mapping global_mapping) + (-> Mapping (Environment Synthesis) Mapping) + (|>> list.enumeration + (list#each (function (_ [id capture]) + [(synthesis.variable/foreign id) + {variable.#Local (++ id)}])) + (dictionary.of_list synthesis.hash))) + (def: (normalize_method_body mapping) - (-> (Dictionary Synthesis Variable) Synthesis Synthesis) + (-> Mapping Synthesis Synthesis) (function (again body) (case body (^template [] @@ -980,38 +1002,51 @@ (def: $Object (type.class "java.lang.Object" (list))) -(def: (anonymous_init_method env) - (-> (Environment Synthesis) (Type Method)) +(def: (anonymous_init_method env inputsTI) + (-> (Environment Synthesis) (List (Typed Inst)) (Type Method)) (type.method [(list) - (list.repeated (list.size env) $Object) + (list.repeated (n.+ (list.size inputsTI) (list.size env)) $Object) type.void (list)])) (def: (with_anonymous_init class env super_class inputsTI) (-> (Type Class) (Environment Synthesis) (Type Class) (List (Typed Inst)) Def) - (let [store_capturedI (|> env + (let [inputs_offset (list.size inputsTI) + inputs! (|> inputsTI + list.enumeration + (list#each (function (_ [register [type term]]) + (case (type.primitive? type) + {.#Right type} + (_.ALOAD (++ register)) + + {.#Left type} + (|>> (_.ALOAD (++ register)) + (_.CHECKCAST type))))) + _.fuse) + store_capturedI (|> env list.size list.indices (list#each (.function (_ register) (|>> (_.ALOAD 0) - (_.ALOAD (++ register)) + (_.ALOAD (n.+ inputs_offset (++ register))) (_.PUTFIELD class (///reference.foreign_name register) $Object)))) _.fuse)] - (_def.method {$.#Public} $.noneM "" (anonymous_init_method env) + (_def.method {$.#Public} $.noneM "" (anonymous_init_method env inputsTI) (|>> (_.ALOAD 0) - ((_.fuse (list#each product.right inputsTI))) + inputs! (_.INVOKESPECIAL super_class "" (type.method [(list) (list#each product.left inputsTI) type.void (list)])) store_capturedI _.RETURN)))) -(def: (anonymous_instance generate archive class env) - (-> Phase Archive (Type Class) (Environment Synthesis) (Operation Inst)) +(def: (anonymous_instance generate archive class env inputsTI) + (-> Phase Archive (Type Class) (Environment Synthesis) (List (Typed Inst)) (Operation Inst)) (do [! phase.monad] [captureI+ (monad.each ! (generate archive) env)] (in (|>> (_.NEW class) _.DUP - (_.fuse captureI+) - (_.INVOKESPECIAL class "" (anonymous_init_method env)))))) + ((_.fuse (list#each product.right inputsTI))) + ((_.fuse captureI+)) + (_.INVOKESPECIAL class "" (anonymous_init_method env inputsTI)))))) (def: (prepare_argument lux_register argumentT jvm_register) (-> Register (Type Value) Register [Register Inst]) @@ -1095,7 +1130,7 @@ (let [[_super _name _strict_fp? _annotations _t_vars _this _arguments _return _exceptions bodyS] method] - (dependency.dependencies archive bodyS))) + (cache.dependencies archive bodyS))) (def: class::anonymous Handler @@ -1110,16 +1145,16 @@ inputsTS overriden_methods]) (do [! phase.monad] - [all_input_dependencies (monad.each ! (|>> product.right (dependency.dependencies archive)) inputsTS) + [all_input_dependencies (monad.each ! (|>> product.right (cache.dependencies archive)) inputsTS) all_closure_dependencies (|> overriden_methods (list#each product.left) list.together - (monad.each ! (dependency.dependencies archive))) + (monad.each ! (cache.dependencies archive))) all_method_dependencies (monad.each ! (|>> product.right (method_dependencies archive)) overriden_methods) - .let [all_dependencies (dependency.all ($_ list#composite - all_input_dependencies - all_closure_dependencies - all_method_dependencies))] + .let [all_dependencies (cache.all ($_ list#composite + all_input_dependencies + all_closure_dependencies + all_method_dependencies))] [context _] (generation.with_new_context archive all_dependencies @@ -1146,20 +1181,18 @@ strict_fp? annotations vars self_name arguments returnT exceptionsT body]]) - (let [local_mapping (|> environment - list.enumeration - (list#each (function (_ [foreign_id capture]) - [(synthesis.variable/foreign foreign_id) - (|> global_mapping - (dictionary.value capture) - maybe.trusted)])) - (dictionary.of_list synthesis.hash))] - [ownerT name - strict_fp? annotations vars - self_name arguments returnT exceptionsT - (normalize_method_body local_mapping body)])) - overriden_methods)] - inputsTI (monad.each ! (generate_input generate archive) inputsTS) + [ownerT name + strict_fp? annotations vars + self_name arguments returnT exceptionsT + (normalize_method_body (..local_mapping global_mapping environment) + body)]) + overriden_methods) + inputsTS (let [mapping (..init_mapping global_mapping total_environment)] + (list#each (function (_ [type term]) + [type (normalize_method_body mapping term)]) + inputsTS))] + inputsTI (generation.with_context artifact_id + (monad.each ! (generate_input generate archive) inputsTS)) method_definitions (|> normalized_methods (monad.each ! (function (_ [ownerT name strict_fp? annotations varsT @@ -1188,7 +1221,7 @@ method_definitions))]] _ (generation.execute! directive) _ (generation.save! artifact_id {.#None} directive)] - (..anonymous_instance generate archive class total_environment)))])) + (..anonymous_instance generate archive class total_environment inputsTI)))])) (def: class_bundle Bundle diff --git a/lux-jvm/source/luxc/lang/translation/jvm/function.lux b/lux-jvm/source/luxc/lang/translation/jvm/function.lux index 7932360a3..2eb1894da 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/function.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/function.lux @@ -1,49 +1,50 @@ (.using - [library - [lux {"-" Type Label Primitive function} - [abstract - ["[0]" monad {"+" do}] - ["[0]" enum]] - [control - [pipe {"+" when> new>}] - ["[0]" function]] - [data - ["[0]" product] - [text - ["%" format {"+" format}]] - [collection - ["[0]" list ("[1]@[0]" functor monoid)]]] - [math - [number - ["n" nat] - ["i" int]]] - [target - [jvm - ["[0]" type {"+" Type} - ["[0]" category {"+" Void Value Return Primitive Object Class Array Var Parameter Method}]]]] - [tool - [compiler - [arity {"+" Arity}] - ["[0]" phase] - [reference - [variable {"+" Register}]] - [language - [lux - [analysis {"+" Environment}] - [synthesis {"+" Synthesis Abstraction Apply}] - ["[0]" generation {"+" Context}]]] - [meta - [archive {"+" Archive} - ["[0]" dependency]]]]]]] - [luxc - [lang - [host - ["$" jvm {"+" Label Inst Def Operation Phase Generator} - ["[0]" def] - ["_" inst]]]]] - ["[0]" // - ["[1][0]" runtime] - ["[0]" reference]]) + [library + [lux {"-" Type Label Primitive function} + [abstract + ["[0]" monad {"+" do}] + ["[0]" enum]] + [control + [pipe {"+" when> new>}] + ["[0]" function]] + [data + ["[0]" product] + [text + ["%" format {"+" format}]] + [collection + ["[0]" list ("[1]@[0]" functor monoid)]]] + [math + [number + ["n" nat] + ["i" int]]] + [target + [jvm + ["[0]" type {"+" Type} + ["[0]" category {"+" Void Value Return Primitive Object Class Array Var Parameter Method}]]]] + [tool + [compiler + [arity {"+" Arity}] + ["[0]" phase] + [reference + [variable {"+" Register}]] + [language + [lux + [analysis {"+" Environment}] + [synthesis {"+" Synthesis Abstraction Apply}] + ["[0]" generation {"+" Context}]]] + [meta + [archive {"+" Archive}] + ["[0]" cache "_" + ["[1]" artifact]]]]]]] + [luxc + [lang + [host + ["$" jvm {"+" Label Inst Def Operation Phase Generator} + ["[0]" def] + ["_" inst]]]]] + ["[0]" // + ["[1][0]" runtime] + ["[0]" reference]]) (def: arity_field Text "arity") @@ -308,7 +309,7 @@ (-> (Maybe Context) (Generator Abstraction)) (do [! phase.monad] [@begin _.make_label - dependencies (dependency.dependencies archive bodyS) + dependencies (cache.dependencies archive bodyS) [function_context bodyI] (case forced_context {.#Some function_context} (do ! -- cgit v1.2.3