diff options
author | Eduardo Julian | 2022-03-01 02:29:52 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-01 02:29:52 -0400 |
commit | 8023df0f5dae4638021fef7b8194a3d0a16b32e4 (patch) | |
tree | 8d64ad88decb0832d85b46a9ef7e734e6b816c35 /stdlib/source/library/lux/target | |
parent | 62436b809630ecd3e40bd6e2b45a8870a2866934 (diff) |
Still more fixes for JVM interop.
Diffstat (limited to 'stdlib/source/library/lux/target')
7 files changed, 117 insertions, 113 deletions
diff --git a/stdlib/source/library/lux/target/jvm/reflection.lux b/stdlib/source/library/lux/target/jvm/reflection.lux index 1462acd76..f8cce5214 100644 --- a/stdlib/source/library/lux/target/jvm/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/reflection.lux @@ -1,34 +1,34 @@ (.using - [library - [lux {"-" Primitive type} - ["[0]" ffi {"+" import:}] - ["[0]" type] - [abstract - ["[0]" monad {"+" do}]] - [control - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - [parser - ["<t>" text]]] - [data - ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" format}]] - [collection - ["[0]" list ("[1]#[0]" mix functor)] - ["[0]" array] - ["[0]" dictionary]]] - [math - [number - ["n" nat]]]]] - ["[0]" // "_" - [encoding - ["[1][0]" name {"+" External}]] - ["/" type - [category {"+" Void Value Return Method Primitive Object Class Array Parameter}] - ["[1][0]" lux {"+" Mapping}] - ["[1][0]" descriptor] - ["[1][0]" reflection] - ["[1][0]" parser]]]) + [library + [lux {"-" Primitive type} + ["[0]" ffi {"+" import:}] + ["[0]" type] + [abstract + ["[0]" monad {"+" do}]] + [control + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + [parser + ["<t>" text]]] + [data + ["[0]" text ("[1]#[0]" equivalence) + ["%" format {"+" format}]] + [collection + ["[0]" list ("[1]#[0]" mix functor)] + ["[0]" array] + ["[0]" dictionary]]] + [math + [number + ["n" nat]]]]] + ["[0]" // "_" + [encoding + ["[1][0]" name {"+" External}]] + ["/" type + [category {"+" Void Value Return Method Primitive Object Class Array Parameter}] + ["[1][0]" lux {"+" Mapping}] + ["[1][0]" descriptor] + ["[1][0]" reflection] + ["[1][0]" parser]]]) (import: java/lang/String) @@ -105,11 +105,11 @@ (def: .public (load class_loader name) (-> java/lang/ClassLoader External (Try (java/lang/Class java/lang/Object))) (case (java/lang/Class::forName name false class_loader) - {try.#Success class} - {try.#Success class} - {try.#Failure _} - (exception.except ..unknown_class [name]))) + (exception.except ..unknown_class [name]) + + success + success)) (def: .public (sub? class_loader super sub) (-> java/lang/ClassLoader External External (Try Bit)) @@ -140,7 +140,7 @@ [/reflection.double] [/reflection.char])) (text.starts_with? /descriptor.array_prefix class_name)) - (exception.except ..not_a_class reflection) + (exception.except ..not_a_class [reflection]) {try.#Success (/.class class_name (list))}))) _) (case (ffi.check java/lang/reflect/ParameterizedType reflection) @@ -148,15 +148,14 @@ (let [raw (java/lang/reflect/ParameterizedType::getRawType reflection)] (case (ffi.check java/lang/Class raw) {.#Some raw} - (do [! try.monad] - [paramsT (|> reflection - java/lang/reflect/ParameterizedType::getActualTypeArguments - (array.list {.#None}) - (monad.each ! parameter))] - (in (/.class (|> raw - (:as (java/lang/Class java/lang/Object)) - java/lang/Class::getName) - paramsT))) + (let [! try.monad] + (|> reflection + java/lang/reflect/ParameterizedType::getActualTypeArguments + (array.list {.#None}) + (monad.each ! parameter) + (# ! each (/.class (|> raw + (:as (java/lang/Class java/lang/Object)) + java/lang/Class::getName))))) _ (exception.except ..not_a_class [raw]))) @@ -164,8 +163,9 @@ ... else (exception.except ..cannot_convert_to_a_lux_type [reflection]))) -(def: .public (parameter reflection) - (-> java/lang/reflect/Type (Try (/.Type Parameter))) +(def: .public (parameter type reflection) + (-> (-> java/lang/reflect/Type (Try (/.Type Value))) + (-> java/lang/reflect/Type (Try (/.Type Parameter)))) (<| (case (ffi.check java/lang/reflect/TypeVariable reflection) {.#Some reflection} {try.#Success (/.var (java/lang/reflect/TypeVariable::getName reflection))} @@ -179,25 +179,27 @@ (^template [<pattern> <kind>] [<pattern> (case (ffi.check java/lang/reflect/GenericArrayType bound) - {.#Some _} + {.#Some it} ... TODO: Array bounds should not be "erased" as they ... are right now. {try.#Success /.wildcard} _ - (# try.monad each <kind> (..class' parameter bound)))]) + (# try.monad each <kind> (parameter type bound)))]) ([[_ {.#Some bound}] /.upper] [[{.#Some bound} _] /.lower]) _ {try.#Success /.wildcard}) _) - (..class' parameter reflection))) - -(def: .public class - (-> java/lang/reflect/Type - (Try (/.Type Class))) - (..class' ..parameter)) + (case (ffi.check java/lang/reflect/GenericArrayType reflection) + {.#Some reflection} + (|> reflection + java/lang/reflect/GenericArrayType::getGenericComponentType + type + (# try.monad each /.array)) + _) + (..class' (parameter type) reflection))) (def: .public (type reflection) (-> java/lang/reflect/Type (Try (/.Type Value))) @@ -223,15 +225,13 @@ (<t>.result /parser.value (|> class_name //name.internal //name.read)) {try.#Success (/.class class_name (list))})))) _) - (case (ffi.check java/lang/reflect/GenericArrayType reflection) - {.#Some reflection} - (|> reflection - java/lang/reflect/GenericArrayType::getGenericComponentType - type - (# try.monad each /.array)) - _) ... else - (..parameter reflection))) + (..parameter type reflection))) + +(def: .public class + (-> java/lang/reflect/Type + (Try (/.Type Class))) + (..class' (..parameter ..type))) (def: .public (return reflection) (-> java/lang/reflect/Type (Try (/.Type Return))) diff --git a/stdlib/source/library/lux/target/jvm/type.lux b/stdlib/source/library/lux/target/jvm/type.lux index 9f4e3ad06..c4de519c3 100644 --- a/stdlib/source/library/lux/target/jvm/type.lux +++ b/stdlib/source/library/lux/target/jvm/type.lux @@ -119,7 +119,7 @@ /reflection.var])) (def: .public (lower bound) - (-> (Type Class) (Type Parameter)) + (-> (Type Parameter) (Type Parameter)) (:abstraction (let [[signature descriptor reflection] (:representation bound)] [(/signature.lower signature) @@ -127,7 +127,7 @@ (/reflection.lower reflection)]))) (def: .public (upper bound) - (-> (Type Class) (Type Parameter)) + (-> (Type Parameter) (Type Parameter)) (:abstraction (let [[signature descriptor reflection] (:representation bound)] [(/signature.upper signature) diff --git a/stdlib/source/library/lux/target/jvm/type/category.lux b/stdlib/source/library/lux/target/jvm/type/category.lux index 207c304a5..45128d756 100644 --- a/stdlib/source/library/lux/target/jvm/type/category.lux +++ b/stdlib/source/library/lux/target/jvm/type/category.lux @@ -30,7 +30,7 @@ [[] Primitive] [[Object' Parameter'] Var] [[Object' Parameter'] Class] - [[Object'] Array] + [[Object' Parameter'] Array] ) (abstract: .public Declaration Any) diff --git a/stdlib/source/library/lux/target/jvm/type/descriptor.lux b/stdlib/source/library/lux/target/jvm/type/descriptor.lux index e89b8ed06..d09a5d94f 100644 --- a/stdlib/source/library/lux/target/jvm/type/descriptor.lux +++ b/stdlib/source/library/lux/target/jvm/type/descriptor.lux @@ -73,11 +73,11 @@ ) (def: .public (lower descriptor) - (-> (Descriptor Class) (Descriptor Parameter)) + (-> (Descriptor Parameter) (Descriptor Parameter)) ..wildcard) (def: .public upper - (-> (Descriptor Class) (Descriptor Parameter)) + (-> (Descriptor Parameter) (Descriptor Parameter)) (|>> :transmutation)) (def: .public array_prefix "[") diff --git a/stdlib/source/library/lux/target/jvm/type/parser.lux b/stdlib/source/library/lux/target/jvm/type/parser.lux index 76289b082..8c896e9f1 100644 --- a/stdlib/source/library/lux/target/jvm/type/parser.lux +++ b/stdlib/source/library/lux/target/jvm/type/parser.lux @@ -1,26 +1,26 @@ (.using - [library - [lux {"-" Type Primitive int char} - [abstract - [monad {"+" do}]] - [control - ["[0]" try] - ["[0]" function] - ["<>" parser ("[1]#[0]" monad) - ["<[0]>" text {"+" Parser}]]] - [data - ["[0]" product] - [text - ["%" format {"+" format}]] - [collection - ["[0]" list]]]]] - ["[0]" // {"+" Type} - [category {"+" Void Value Return Method Primitive Object Class Array Var Parameter Declaration}] - ["[1][0]" signature] - ["[1][0]" descriptor] - ["[0]" // "_" - [encoding - ["[1][0]" name {"+" External}]]]]) + [library + [lux {"-" Type Primitive int char} + [abstract + [monad {"+" do}]] + [control + ["[0]" try] + ["[0]" function] + ["<>" parser ("[1]#[0]" monad) + ["<[0]>" text {"+" Parser}]]] + [data + ["[0]" product] + [text + ["%" format {"+" format}]] + [collection + ["[0]" list]]]]] + ["[0]" // {"+" Type} + [category {"+" Void Value Return Method Primitive Object Class Array Var Parameter Declaration}] + ["[1][0]" signature] + ["[1][0]" descriptor] + ["[0]" // "_" + [encoding + ["[1][0]" name {"+" External}]]]]) (template [<category> <name> <signature> <type>] [(def: .public <name> @@ -102,7 +102,7 @@ (template [<name> <prefix> <constructor>] [(def: <name> - (-> (Parser (Type Class)) (Parser (Type Parameter))) + (-> (Parser (Type Parameter)) (Parser (Type Parameter))) (|>> (<>.after (<text>.this <prefix>)) (<>#each <constructor>)))] @@ -127,23 +127,37 @@ (|>> ..class'' (# <>.monad each (product.uncurried //.class)))) -(def: .public parameter - (Parser (Type Parameter)) +(def: .public array' + (-> (Parser (Type Value)) (Parser (Type Array))) + (|>> (<>.after (<text>.this //descriptor.array_prefix)) + (<>#each //.array))) + +(def: (parameter' value) + (-> (Parser (Type Value)) (Parser (Type Parameter))) (<>.rec (function (_ parameter) (let [class (..class' parameter)] ($_ <>.either ..var ..wildcard - (..lower class) - (..upper class) + (..lower parameter) + (..upper parameter) + (..array' value) class ))))) -(def: .public array' - (-> (Parser (Type Value)) (Parser (Type Array))) - (|>> (<>.after (<text>.this //descriptor.array_prefix)) - (<>#each //.array))) +(def: .public value + (Parser (Type Value)) + (<>.rec + (function (_ value) + ($_ <>.either + ..primitive + (..parameter' value) + )))) + +(def: .public parameter + (Parser (Type Parameter)) + (..parameter' ..value)) (def: .public class (Parser (Type Class)) @@ -151,10 +165,10 @@ (template [<name> <prefix> <constructor>] [(def: .public <name> - (-> (Type Value) (Maybe (Type Class))) + (-> (Type Value) (Maybe (Type Parameter))) (|>> //.signature //signature.signature - (<text>.result (<>.after (<text>.this <prefix>) ..class)) + (<text>.result (<>.after (<text>.this <prefix>) ..parameter)) try.maybe))] [lower? //signature.lower_prefix //.lower] @@ -168,16 +182,6 @@ (<text>.result (..class'' ..parameter)) try.trusted)) -(def: .public value - (Parser (Type Value)) - (<>.rec - (function (_ value) - ($_ <>.either - ..primitive - ..parameter - (..array' value) - )))) - (def: .public array (Parser (Type Array)) (..array' ..value)) diff --git a/stdlib/source/library/lux/target/jvm/type/reflection.lux b/stdlib/source/library/lux/target/jvm/type/reflection.lux index 8915f5375..f4df7e88b 100644 --- a/stdlib/source/library/lux/target/jvm/type/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/type/reflection.lux @@ -95,10 +95,10 @@ ) (def: .public (lower reflection) - (-> (Reflection Class) (Reflection Parameter)) + (-> (Reflection Parameter) (Reflection Parameter)) ..wildcard) (def: .public upper - (-> (Reflection Class) (Reflection Parameter)) + (-> (Reflection Parameter) (Reflection Parameter)) (|>> :transmutation)) ) diff --git a/stdlib/source/library/lux/target/jvm/type/signature.lux b/stdlib/source/library/lux/target/jvm/type/signature.lux index ee93afa32..aa733a4e9 100644 --- a/stdlib/source/library/lux/target/jvm/type/signature.lux +++ b/stdlib/source/library/lux/target/jvm/type/signature.lux @@ -71,7 +71,7 @@ (template [<name> <prefix>] [(def: .public <name> - (-> (Signature Class) (Signature Parameter)) + (-> (Signature Parameter) (Signature Parameter)) (|>> :representation (format <prefix>) :abstraction))] [lower ..lower_prefix] |