From 8dcbdff13bf679ead63a4c29e7f63d7cc0d86480 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 20 Aug 2019 23:56:58 -0400 Subject: Improved machinery in "lux/target/jvm/type/reflection". --- stdlib/source/lux/target/jvm/type/descriptor.lux | 4 +- stdlib/source/lux/target/jvm/type/reflection.lux | 116 ++++++++++++++--------- stdlib/source/lux/target/jvm/type/signature.lux | 4 +- 3 files changed, 74 insertions(+), 50 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux/target/jvm/type/descriptor.lux b/stdlib/source/lux/target/jvm/type/descriptor.lux index b47f0edf3..75b6d4284 100644 --- a/stdlib/source/lux/target/jvm/type/descriptor.lux +++ b/stdlib/source/lux/target/jvm/type/descriptor.lux @@ -127,7 +127,7 @@ (def: binary-name (|>> ///name.internal ///name.external)) (def: #export (class? descriptor) - (-> (Descriptor Value) (Maybe Text)) + (-> (Descriptor Value) (Maybe External)) (let [repr (:representation descriptor)] (if (and (text.starts-with? ..class-prefix repr) (text.ends-with? ..class-suffix repr)) @@ -139,7 +139,7 @@ #.None))) (def: #export class-name - (-> (Descriptor Object) Text) + (-> (Descriptor Object) External) (let [prefix-size (text.size ..class-prefix) suffix-size (text.size ..class-suffix)] (function (_ descriptor) diff --git a/stdlib/source/lux/target/jvm/type/reflection.lux b/stdlib/source/lux/target/jvm/type/reflection.lux index b49205f5e..a80106e7a 100644 --- a/stdlib/source/lux/target/jvm/type/reflection.lux +++ b/stdlib/source/lux/target/jvm/type/reflection.lux @@ -2,50 +2,74 @@ [lux (#- int char) [data [text - ["%" format (#+ format)]]]] - ["." //]) - -(template [ ] - [(def: #export )] - - [void "void"] - [boolean "boolean"] - [byte "byte"] - [short "short"] - [int "int"] - [long "long"] - [float "float"] - [double "double"] - [char "char"] - ) + ["%" format (#+ format)]]] + [macro + ["." template]] + [type + abstract]] + ["." // + ["#." descriptor] + [// + [encoding + ["#." name (#+ External)]]]]) + +(abstract: #export Void' {} Any) + +(abstract: #export (Value' brand) {} Any) +(abstract: #export (Return' brand) {} Any) + +(abstract: #export Method {} Any) + +(abstract: #export (Reflection brand) + {} + + Text + + (type: #export Return (<| Return' Any)) + (type: #export Value (<| Return' Value' Any)) + (type: #export Void (<| Return' Void')) + + (abstract: #export (Object' brand) {} Any) + (type: #export Object (<| Return' Value' Object' Any)) -(def: #export (class type) - (-> //.Type Text) - (case type - (#//.Primitive prim) - (case prim - #//.Boolean ..boolean - #//.Byte ..byte - #//.Short ..short - #//.Int ..int - #//.Long ..long - #//.Float ..float - #//.Double ..double - #//.Char ..char) - - (#//.Array sub) - (|> sub class (format //.array-prefix)) - - (#//.Generic generic) - (case generic - (#//.Class name params) - name - - (^or (#//.Var name) - (#//.Wildcard #.None) - (#//.Wildcard (#.Some [#//.Lower bound]))) - "java.lang.Object" - - (#//.Wildcard (#.Some [#//.Upper bound])) - (class (#//.Generic bound))) - )) + (template [ ] + [(with-expansions [ (template.identifier [ "'"])] + (abstract: #export {} Any) + (type: #export + (`` (<| Return' Value' (~~ (template.splice )) ))))] + + [[] Primitive] + [[Object'] Class] + [[Object'] Array] + ) + + (def: #export reflection + (-> (Reflection Any) Text) + (|>> :representation)) + + (template [ ] + [(def: #export + (Reflection ) + (:abstraction ))] + + [Void void "void"] + [Primitive boolean "boolean"] + [Primitive byte "byte"] + [Primitive short "short"] + [Primitive int "int"] + [Primitive long "long"] + [Primitive float "float"] + [Primitive double "double"] + [Primitive char "char"] + ) + + (def: #export class + (-> External (Reflection Class)) + (|>> :abstraction)) + + (def: #export array + (-> (Reflection Class) (Reflection Array)) + (|>> :representation + (format //descriptor.array-prefix) + :abstraction)) + ) diff --git a/stdlib/source/lux/target/jvm/type/signature.lux b/stdlib/source/lux/target/jvm/type/signature.lux index d19708f1e..5af06d0ef 100644 --- a/stdlib/source/lux/target/jvm/type/signature.lux +++ b/stdlib/source/lux/target/jvm/type/signature.lux @@ -15,7 +15,7 @@ ["#." descriptor] ["/#" // #_ [encoding - ["#." name]]]]) + ["#." name (#+ External)]]]]) (abstract: #export Void' {} Any) (abstract: #export (Value' kind) {} Any) @@ -98,7 +98,7 @@ ) (def: #export (class name parameters) - (-> Text (List (Signature Parameter)) (Signature Class)) + (-> External (List (Signature Parameter)) (Signature Class)) (:abstraction (format //descriptor.class-prefix (|> name ///name.internal ///name.read) -- cgit v1.2.3