diff options
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux')
-rw-r--r-- | stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux new file mode 100644 index 000000000..2327f07b2 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/type/descriptor.lux @@ -0,0 +1,125 @@ +(.require + [library + [lux (.except Declaration int char) + [abstract + [equivalence (.only Equivalence)]] + [control + ["[0]" maybe]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format (.only format)]] + [collection + ["[0]" list (.use "[1]#[0]" functor)]]] + [math + [number + ["n" nat]]] + [meta + [type + ["[0]" nominal (.except def)]]]]] + ["[0]" // + [category (.only Void Value Return Method Primitive Object Class Array Var Parameter Declaration)] + ["/[1]" // + [encoding + ["[1][0]" name (.only Internal External)]]]]) + +(nominal.def .public (Descriptor category) + Text + + (def .public descriptor + (-> (Descriptor Any) Text) + (|>> representation)) + + (with_template [<sigil> <category> <name>] + [(def .public <name> + (Descriptor <category>) + (abstraction <sigil>))] + + ["V" Void void] + ["Z" Primitive boolean] + ["B" Primitive byte] + ["S" Primitive short] + ["I" Primitive int] + ["J" Primitive long] + ["F" Primitive float] + ["D" Primitive double] + ["C" Primitive char] + ) + + (def .public class_prefix "L") + (def .public class_suffix ";") + + (def .public class + (-> External (Descriptor Class)) + (|>> ///name.internal + ///name.read + (text.enclosed [..class_prefix ..class_suffix]) + abstraction)) + + (def .public (declaration name) + (-> External (Descriptor Declaration)) + (transmutation (..class name))) + + (def .public as_class + (-> (Descriptor Declaration) (Descriptor Class)) + (|>> transmutation)) + + (with_template [<name> <category>] + [(def .public <name> + (Descriptor <category>) + (transmutation + (..class "java.lang.Object")))] + + [var Var] + [wildcard Parameter] + ) + + (def .public (lower descriptor) + (-> (Descriptor Parameter) (Descriptor Parameter)) + ..wildcard) + + (def .public upper + (-> (Descriptor Parameter) (Descriptor Parameter)) + (|>> transmutation)) + + (def .public array_prefix "[") + + (def .public array + (-> (Descriptor Value) + (Descriptor Array)) + (|>> representation + (format ..array_prefix) + abstraction)) + + (def .public (method [inputs output]) + (-> [(List (Descriptor Value)) + (Descriptor Return)] + (Descriptor Method)) + (abstraction + (format (|> inputs + (list#each ..descriptor) + text.together + (text.enclosed ["(" ")"])) + (representation output)))) + + (def .public equivalence + (All (_ category) (Equivalence (Descriptor category))) + (implementation + (def (= parameter subject) + (text#= (representation parameter) (representation subject))))) + + (def .public class_name + (-> (Descriptor Object) Internal) + (let [prefix_size (text.size ..class_prefix) + suffix_size (text.size ..class_suffix)] + (function (_ descriptor) + (let [repr (representation descriptor)] + (if (text.starts_with? ..array_prefix repr) + (///name.internal repr) + (|> repr + (text.clip prefix_size + (|> (text.size repr) + (n.- prefix_size) + (n.- suffix_size))) + (of maybe.monad each ///name.internal) + maybe.trusted)))))) + ) |