diff options
Diffstat (limited to 'stdlib/source/library/lux/meta/target/jvm/type/signature.lux')
-rw-r--r-- | stdlib/source/library/lux/meta/target/jvm/type/signature.lux | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/target/jvm/type/signature.lux b/stdlib/source/library/lux/meta/target/jvm/type/signature.lux new file mode 100644 index 000000000..6afc33607 --- /dev/null +++ b/stdlib/source/library/lux/meta/target/jvm/type/signature.lux @@ -0,0 +1,183 @@ +(.require + [library + [lux (.except Primitive int char) + [abstract + [equivalence (.only Equivalence)] + [hash (.only Hash)]] + [control + ["[0]" pipe]] + [data + ["[0]" text (.use "[1]#[0]" hash) + ["%" \\format (.only format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor)]]] + [meta + [type + [primitive (.except)]]]]] + ["[0]" // + [category (.only Void Value Return Method Primitive Object Class Array Var Parameter Declaration Inheritance)] + ["[1][0]" descriptor] + ["/[1]" // + [encoding + ["[1][0]" name (.only External)]]]]) + +(primitive .public (Signature category) + Text + + (def .public signature + (-> (Signature Any) Text) + (|>> representation)) + + (with_template [<category> <name> <descriptor>] + [(def .public <name> + (Signature <category>) + (abstraction (//descriptor.descriptor <descriptor>)))] + + [Void void //descriptor.void] + [Primitive boolean //descriptor.boolean] + [Primitive byte //descriptor.byte] + [Primitive short //descriptor.short] + [Primitive int //descriptor.int] + [Primitive long //descriptor.long] + [Primitive float //descriptor.float] + [Primitive double //descriptor.double] + [Primitive char //descriptor.char] + ) + + (def .public array + (-> (Signature Value) (Signature Array)) + (|>> representation + (format //descriptor.array_prefix) + abstraction)) + + (def .public wildcard + (Signature Parameter) + (abstraction "*")) + + (with_template [<char> <name>] + [(def .public <name> <char>)] + + ["T" var_prefix] + ["-" lower_prefix] + ["+" upper_prefix] + + ["<" parameters_start] + [">" parameters_end] + [":" format_type_parameter_infix] + + ["(" arguments_start] + [")" arguments_end] + ["^" exception_prefix] + ) + + (with_template [<name> <prefix>] + [(def .public <name> + (-> (Signature Parameter) (Signature Parameter)) + (|>> representation (format <prefix>) abstraction))] + + [lower ..lower_prefix] + [upper ..upper_prefix] + ) + + (def .public var + (-> Text (Signature Var)) + (|>> (text.enclosed [..var_prefix //descriptor.class_suffix]) + abstraction)) + + (def .public var_name + (-> (Signature Var) Text) + (|>> representation + (text.replaced ..var_prefix "") + (text.replaced //descriptor.class_suffix ""))) + + (def .public (class name parameters) + (-> External (List (Signature Parameter)) (Signature Class)) + (abstraction + (format //descriptor.class_prefix + (|> name ///name.internal ///name.read) + (case parameters + {.#End} + "" + + _ + (format ..parameters_start + (|> parameters + (list#each ..signature) + text.together) + ..parameters_end)) + //descriptor.class_suffix))) + + (def .public (declaration name variables) + (-> External (List (Signature Var)) (Signature Declaration)) + (transmutation (..class name variables))) + + (def class_bound + (|> (..class "java.lang.Object" (list)) + ..signature + (format ..format_type_parameter_infix))) + + (def var_declaration/1 + (-> (Signature Var) Text) + (|>> ..var_name + (text.suffix ..class_bound))) + + (def var_declaration/+ + (-> (List (Signature Var)) Text) + (|>> (list#each ..var_declaration/1) + text.together + (text.enclosed [..parameters_start + ..parameters_end]))) + + (def var_declaration/* + (-> (List (Signature Var)) Text) + (|>> (pipe.case + {.#End} + "" + + it + (..var_declaration/+ it)))) + + (def .public (inheritance variables super interfaces) + (-> (List (Signature Var)) (Signature Class) (List (Signature Class)) (Signature Inheritance)) + (abstraction + (format (var_declaration/* variables) + (representation super) + (|> interfaces + (list#each ..signature) + text.together)))) + + (def .public as_class + (-> (Signature Declaration) (Signature Class)) + (|>> transmutation)) + + (def .public (method [type_variables inputs output exceptions]) + (-> [(List (Signature Var)) + (List (Signature Value)) + (Signature Return) + (List (Signature Class))] + (Signature Method)) + (abstraction + (format (var_declaration/* type_variables) + (|> inputs + (list#each ..signature) + text.together + (text.enclosed [..arguments_start + ..arguments_end])) + (representation output) + (|> exceptions + (list#each (|>> representation (format ..exception_prefix))) + text.together)))) + + (def .public equivalence + (All (_ category) (Equivalence (Signature category))) + (implementation + (def (= parameter subject) + (text#= (representation parameter) + (representation subject))))) + + (def .public hash + (All (_ category) (Hash (Signature category))) + (implementation + (def equivalence ..equivalence) + (def hash (|>> representation text#hash)))) + ) |