aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2019-08-20 23:36:11 -0400
committerEduardo Julian2019-08-20 23:36:11 -0400
commit9cbbf331a103d411ead15d57f83d3b6ed4b044d4 (patch)
tree3caa16757ed27b4a6a8f1246d046dcd2c74130b3 /stdlib/source
parent74662caf09a43bf3057f89ea9f3f7c8163e09851 (diff)
Moved signature machinery to "lux/target/jvm/type/signature".
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/target/jvm/type.lux110
-rw-r--r--stdlib/source/lux/target/jvm/type/descriptor.lux41
-rw-r--r--stdlib/source/lux/target/jvm/type/lux.lux2
-rw-r--r--stdlib/source/lux/target/jvm/type/reflection.lux2
-rw-r--r--stdlib/source/lux/target/jvm/type/signature.lux138
5 files changed, 160 insertions, 133 deletions
diff --git a/stdlib/source/lux/target/jvm/type.lux b/stdlib/source/lux/target/jvm/type.lux
index 4601003a8..a74fab40a 100644
--- a/stdlib/source/lux/target/jvm/type.lux
+++ b/stdlib/source/lux/target/jvm/type.lux
@@ -38,7 +38,6 @@
(def: lower-prefix "-")
(def: upper-prefix "+")
(def: object-suffix ";")
-(def: #export object-class "java.lang.Object")
(def: valid-var-characters/head
(format "abcdefghijklmnopqrstuvwxyz"
@@ -160,98 +159,9 @@
(type: #export Argument
[Text Type])
-(type: #export Return
- (Maybe Type))
-
-(def: #export return-equivalence
- (Equivalence Return)
- (maybe.equivalence ..type-equivalence))
-
-(type: #export Method
- {#args (List Type)
- #return Return
- #exceptions (List Generic)})
-
-(structure: #export method-equivalence
- (Equivalence Method)
- (def: (= [argsP returnP exceptionsP] [argsS returnS exceptionsS])
- (and (:: (list.equivalence ..type-equivalence) = argsP argsS)
- (:: ..return-equivalence = returnP returnS)
- (:: (list.equivalence ..generic-equivalence) = exceptionsP exceptionsS))))
-
(type: #export (Typed a)
[Type a])
-(template [<name> <primitive>]
- [(def: #export <name> Type (#Primitive <primitive>))]
-
- [boolean #Boolean]
- [byte #Byte]
- [short #Short]
- [int #Int]
- [long #Long]
- [float #Float]
- [double #Double]
- [char #Char]
- )
-
-(template: #export (class name params)
- (#..Generic (#..Class name params)))
-
-(template: #export (var name)
- (#..Generic (#..Var name)))
-
-(template: #export (wildcard bound)
- (#..Generic (#..Wildcard bound)))
-
-(def: #export (array depth elemT)
- (-> Nat Type Type)
- (case depth
- 0 elemT
- _ (#Array (array (dec depth) elemT))))
-
-(def: #export (signature type)
- (-> Type Text)
- (case type
- (#Primitive prim)
- (case prim
- #Boolean ..boolean-descriptor
- #Byte ..byte-descriptor
- #Short ..short-descriptor
- #Int ..int-descriptor
- #Long ..long-descriptor
- #Float ..float-descriptor
- #Double ..double-descriptor
- #Char ..char-descriptor)
-
- (#Array sub)
- (format ..array-prefix (signature sub))
-
- (#Generic generic)
- (case generic
- (#Class class params)
- (let [=params (if (list.empty? params)
- ""
- (format "<"
- (|> params
- (list@map (|>> #Generic signature))
- (text.join-with ""))
- ">"))]
- (format ..object-prefix (|> class //name.internal //name.read) =params ..object-suffix))
-
- (#Var name)
- (format ..var-prefix name ..object-suffix)
-
- (#Wildcard #.None)
- ..wildcard-signature
-
- (^template [<tag> <prefix>]
- (#Wildcard (#.Some [<tag> bound]))
- (format <prefix> (signature (#Generic bound))))
- ([#Lower ..lower-prefix]
- [#Upper ..upper-prefix]))
- ))
-
(template [<name> <head> <tail> <adapter>]
[(def: <name>
(Parser Text)
@@ -313,23 +223,3 @@
(<>.after (<t>.this ..array-prefix)
recur)
))))
-
-(def: #export (method args return exceptions)
- (-> (List Type) (Maybe Type) (List Generic) Method)
- {#args args #return return #exceptions exceptions})
-
-(def: #export (method-signature method)
- (-> Method Text)
- (format (|> (get@ #args method)
- (list@map signature)
- (text.join-with "")
- (text.enclose ["(" ")"]))
- (case (get@ #return method)
- #.None
- ..void-descriptor
-
- (#.Some return)
- (signature return))
- (|> (get@ #exceptions method)
- (list@map (|>> #Generic signature (format "^")))
- (text.join-with ""))))
diff --git a/stdlib/source/lux/target/jvm/type/descriptor.lux b/stdlib/source/lux/target/jvm/type/descriptor.lux
index 52b5037bc..b47f0edf3 100644
--- a/stdlib/source/lux/target/jvm/type/descriptor.lux
+++ b/stdlib/source/lux/target/jvm/type/descriptor.lux
@@ -20,40 +20,44 @@
(abstract: #export Void' {} Any)
-(abstract: #export (Value' kind) {} Any)
-(abstract: #export (Return kind) {} Any)
+(abstract: #export (Value' brand) {} Any)
+(abstract: #export (Return' brand) {} Any)
(abstract: #export Method {} Any)
-(abstract: #export (Descriptor kind)
+(abstract: #export (Descriptor brand)
{}
Text
- (type: #export Value (<| Return Value' Any))
- (type: #export Void (Return Void'))
-
- (type: #export Field Value)
+ (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))
+ (type: #export Object (<| Return' Value' Object' Any))
(template [<parents> <child>]
[(with-expansions [<raw> (template.identifier [<child> "'"])]
(abstract: #export <raw> {} Any)
(type: #export <child>
- (`` (<| Return Value' (~~ (template.splice <parents>)) <raw>))))]
+ (`` (<| Return' Value' (~~ (template.splice <parents>)) <raw>))))]
[[] Primitive]
[[Object'] Class]
[[Object'] Array]
)
- (template [<sigil> <kind> <name>]
+ (def: #export descriptor
+ (-> (Descriptor Any) Text)
+ (|>> :representation))
+
+ (template [<sigil> <brand> <name>]
[(def: #export <name>
- (Descriptor <kind>)
+ (Descriptor <brand>)
(:abstraction <sigil>))]
+ ["V" Void void]
["Z" Primitive boolean]
["B" Primitive byte]
["S" Primitive short]
@@ -62,11 +66,10 @@
["F" Primitive float]
["D" Primitive double]
["C" Primitive char]
- ["V" Void void]
)
- (def: class-prefix "L")
- (def: class-suffix ";")
+ (def: #export class-prefix "L")
+ (def: #export class-suffix ";")
(def: #export class
(-> External (Descriptor Class))
@@ -78,7 +81,7 @@
(def: #export var (..class "java.lang.Object"))
(def: #export wildcard (..class "java.lang.Object"))
- (def: array-prefix "[")
+ (def: #export array-prefix "[")
(def: #export array
(-> (Descriptor Value)
@@ -89,19 +92,15 @@
(def: #export (method [inputs output])
(-> [(List (Descriptor Value))
- (Descriptor (Return Any))]
+ (Descriptor Return)]
(Descriptor Method))
(:abstraction
(format (|> inputs
- (list@map (|>> :representation))
+ (list@map ..descriptor)
(text.join-with "")
(text.enclose ["(" ")"]))
(:representation output))))
- (def: #export descriptor
- (-> (Descriptor Any) Text)
- (|>> :representation))
-
(structure: #export equivalence
(All [brand] (Equivalence (Descriptor brand)))
diff --git a/stdlib/source/lux/target/jvm/type/lux.lux b/stdlib/source/lux/target/jvm/type/lux.lux
index 1ebf4b74e..243861bd4 100644
--- a/stdlib/source/lux/target/jvm/type/lux.lux
+++ b/stdlib/source/lux/target/jvm/type/lux.lux
@@ -106,7 +106,7 @@
(type mapping elementT)))))
(def: #export (return mapping input)
- (-> Mapping //.Return (Check Type))
+ (-> Mapping (Maybe //.Type) (Check Type))
(case input
#.None
(check@wrap Any)
diff --git a/stdlib/source/lux/target/jvm/type/reflection.lux b/stdlib/source/lux/target/jvm/type/reflection.lux
index b74a4ea30..b49205f5e 100644
--- a/stdlib/source/lux/target/jvm/type/reflection.lux
+++ b/stdlib/source/lux/target/jvm/type/reflection.lux
@@ -44,7 +44,7 @@
(^or (#//.Var name)
(#//.Wildcard #.None)
(#//.Wildcard (#.Some [#//.Lower bound])))
- //.object-class
+ "java.lang.Object"
(#//.Wildcard (#.Some [#//.Upper bound]))
(class (#//.Generic bound)))
diff --git a/stdlib/source/lux/target/jvm/type/signature.lux b/stdlib/source/lux/target/jvm/type/signature.lux
new file mode 100644
index 000000000..d19708f1e
--- /dev/null
+++ b/stdlib/source/lux/target/jvm/type/signature.lux
@@ -0,0 +1,138 @@
+(.module:
+ [lux (#- int char)
+ [abstract
+ [equivalence (#+ Equivalence)]]
+ [data
+ ["." text ("#@." equivalence)
+ ["%" format (#+ format)]]
+ [collection
+ ["." list ("#@." functor)]]]
+ [macro
+ ["." template]]
+ [type
+ abstract]]
+ ["." // #_
+ ["#." descriptor]
+ ["/#" // #_
+ [encoding
+ ["#." name]]]])
+
+(abstract: #export Void' {} Any)
+(abstract: #export (Value' kind) {} Any)
+(abstract: #export (Return' kind) {} Any)
+(abstract: #export Method {} Any)
+
+(abstract: #export (Signature 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))
+
+ (abstract: #export (Parameter' brand) {} Any)
+ (type: #export Parameter (<| Return' Value' Object' Parameter' Any))
+
+ (template [<parents> <child>]
+ [(with-expansions [<raw> (template.identifier [<child> "'"])]
+ (abstract: #export <raw> {} Any)
+ (type: #export <child>
+ (`` (<| Return' Value' (~~ (template.splice <parents>)) <raw>))))]
+
+ [[] Primitive]
+ [[Object' Parameter'] Class]
+ [[Object'] Array]
+ )
+
+ (def: #export signature
+ (-> (Signature Any) Text)
+ (|>> :representation))
+
+ (template [<brand> <name> <descriptor>]
+ [(def: #export <name>
+ (Signature <brand>)
+ (: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: #export array
+ (-> (Signature Value) (Signature Array))
+ (|>> :representation
+ (format //descriptor.array-prefix)
+ :abstraction))
+
+ (def: #export wildcard
+ (Signature Parameter)
+ (:abstraction "*"))
+
+ (def: var-prefix "T")
+
+ (def: #export var
+ (-> Text (Signature Parameter))
+ (|>> (text.enclose [..var-prefix //descriptor.class-suffix])
+ :abstraction))
+
+ (def: lower-prefix "-")
+ (def: upper-prefix "+")
+
+ (template [<name> <prefix>]
+ [(def: #export <name>
+ (-> (Signature Class) (Signature Parameter))
+ (|>> :representation (format <prefix>) :abstraction))]
+
+ [lower ..lower-prefix]
+ [upper ..upper-prefix]
+ )
+
+ (def: #export (class name parameters)
+ (-> Text (List (Signature Parameter)) (Signature Class))
+ (:abstraction
+ (format //descriptor.class-prefix
+ (|> name ///name.internal ///name.read)
+ (case parameters
+ #.Nil
+ ""
+
+ _
+ (format "<"
+ (|> parameters
+ (list@map ..signature)
+ (text.join-with ""))
+ ">"))
+ //descriptor.class-suffix)))
+
+ (def: #export (method [inputs output exceptions])
+ (-> [(List (Signature Value))
+ (Signature Return)
+ (List (Signature Class))]
+ (Signature Method))
+ (:abstraction
+ (format (|> inputs
+ (list@map ..signature)
+ (text.join-with "")
+ (text.enclose ["(" ")"]))
+ (:representation output)
+ (|> exceptions
+ (list@map (|>> :representation (format "^")))
+ (text.join-with "")))))
+
+ (structure: #export equivalence
+ (All [brand] (Equivalence (Signature brand)))
+
+ (def: (= parameter subject)
+ (text@= (:representation parameter)
+ (:representation subject))))
+ )