From 74662caf09a43bf3057f89ea9f3f7c8163e09851 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 20 Aug 2019 22:26:23 -0400 Subject: Renamed "lux/target/jvm/descriptor" to "lux/target/jvm/type/descriptor". --- stdlib/source/lux/target/jvm/descriptor.lux | 154 ---------------------- stdlib/source/lux/target/jvm/type/descriptor.lux | 156 +++++++++++++++++++++++ 2 files changed, 156 insertions(+), 154 deletions(-) delete mode 100644 stdlib/source/lux/target/jvm/descriptor.lux create mode 100644 stdlib/source/lux/target/jvm/type/descriptor.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/target/jvm/descriptor.lux b/stdlib/source/lux/target/jvm/descriptor.lux deleted file mode 100644 index 5452c16c7..000000000 --- a/stdlib/source/lux/target/jvm/descriptor.lux +++ /dev/null @@ -1,154 +0,0 @@ -(.module: - [lux (#- int char) - [abstract - [equivalence (#+ Equivalence)]] - [data - ["." maybe] - [number - ["n" nat]] - ["." text ("#@." equivalence) - ["%" format (#+ format)]] - [collection - ["." list ("#@." functor)]]] - [macro - ["." template]] - [type - abstract]] - ["." // #_ - [encoding - ["#." name (#+ External)]]]) - -(abstract: #export Void' {} Any) - -(abstract: #export (Value' kind) {} Any) -(abstract: #export (Return kind) {} Any) - -(abstract: #export Method {} Any) - -(abstract: #export (Descriptor kind) - {} - - Text - - (type: #export Value (<| Return Value' Any)) - (type: #export Void (Return Void')) - - (type: #export Field Value) - - (abstract: #export (Object' brand) {} Any) - (type: #export Object (<| Return Value' Object' Any)) - - (template [ ] - [(with-expansions [ (template.identifier [ "'"])] - (abstract: #export {} Any) - (type: #export - (`` (<| Return Value' (~~ (template.splice )) ))))] - - [[] Primitive] - [[Object'] Class] - [[Object'] Array] - ) - - (template [ ] - [(def: #export - (Descriptor ) - (:abstraction ))] - - ["Z" Primitive boolean] - ["B" Primitive byte] - ["S" Primitive short] - ["I" Primitive int] - ["J" Primitive long] - ["F" Primitive float] - ["D" Primitive double] - ["C" Primitive char] - ["V" Void void] - ) - - (def: class-prefix "L") - (def: class-suffix ";") - - (def: #export class - (-> External (Descriptor Class)) - (|>> //name.internal - //name.read - (text.enclose [..class-prefix ..class-suffix]) - :abstraction)) - - (def: #export var (..class "java.lang.Object")) - (def: #export wildcard (..class "java.lang.Object")) - - (def: array-prefix "[") - - (def: #export array - (-> (Descriptor Value) - (Descriptor Array)) - (|>> :representation - (format ..array-prefix) - :abstraction)) - - (def: #export (method [inputs output]) - (-> [(List (Descriptor Value)) - (Descriptor (Return Any))] - (Descriptor Method)) - (:abstraction - (format (|> inputs - (list@map (|>> :representation)) - (text.join-with "") - (text.enclose ["(" ")"])) - (:representation output)))) - - (def: #export descriptor - (-> (Descriptor Any) Text) - (|>> :representation)) - - (structure: #export equivalence (All [brand] (Equivalence (Descriptor brand))) - (def: (= parameter subject) - (text@= (:representation parameter) (:representation subject)))) - - (def: #export (primitive? descriptor) - (-> (Descriptor Value) (Either (Descriptor Object) - (Descriptor Primitive))) - (if (`` (or (~~ (template [] - [(:: ..equivalence = descriptor)] - - [..boolean] - [..byte] - [..short] - [..int] - [..long] - [..float] - [..double] - [..char])))) - (|> descriptor :transmutation #.Right) - (|> descriptor :transmutation #.Left))) - - (def: #export (class? descriptor) - (-> (Descriptor Value) (Maybe Text)) - (let [repr (:representation descriptor)] - (if (and (text.starts-with? ..class-prefix repr) - (text.ends-with? ..class-suffix repr)) - (:: maybe.monad map - (|>> //name.internal //name.external) - (text.clip (text.size ..class-prefix) - (n.- (text.size ..class-suffix) - (text.size repr)) - repr)) - #.None))) - - (def: #export class-name - (-> (Descriptor Object) Text) - (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) - repr - (|> repr - (text.clip prefix-size - (n.- suffix-size - (text.size repr))) - (:: maybe.monad map - (|>> //name.internal //name.external)) - maybe.assume)))))) - ) diff --git a/stdlib/source/lux/target/jvm/type/descriptor.lux b/stdlib/source/lux/target/jvm/type/descriptor.lux new file mode 100644 index 000000000..52b5037bc --- /dev/null +++ b/stdlib/source/lux/target/jvm/type/descriptor.lux @@ -0,0 +1,156 @@ +(.module: + [lux (#- int char) + [abstract + [equivalence (#+ Equivalence)]] + [data + ["." maybe] + [number + ["n" nat]] + ["." text ("#@." equivalence) + ["%" format (#+ format)]] + [collection + ["." list ("#@." functor)]]] + [macro + ["." template]] + [type + abstract]] + ["." /// #_ + [encoding + ["#." name (#+ External)]]]) + +(abstract: #export Void' {} Any) + +(abstract: #export (Value' kind) {} Any) +(abstract: #export (Return kind) {} Any) + +(abstract: #export Method {} Any) + +(abstract: #export (Descriptor kind) + {} + + Text + + (type: #export Value (<| Return Value' Any)) + (type: #export Void (Return Void')) + + (type: #export Field Value) + + (abstract: #export (Object' brand) {} Any) + (type: #export Object (<| Return Value' Object' Any)) + + (template [ ] + [(with-expansions [ (template.identifier [ "'"])] + (abstract: #export {} Any) + (type: #export + (`` (<| Return Value' (~~ (template.splice )) ))))] + + [[] Primitive] + [[Object'] Class] + [[Object'] Array] + ) + + (template [ ] + [(def: #export + (Descriptor ) + (:abstraction ))] + + ["Z" Primitive boolean] + ["B" Primitive byte] + ["S" Primitive short] + ["I" Primitive int] + ["J" Primitive long] + ["F" Primitive float] + ["D" Primitive double] + ["C" Primitive char] + ["V" Void void] + ) + + (def: class-prefix "L") + (def: class-suffix ";") + + (def: #export class + (-> External (Descriptor Class)) + (|>> ///name.internal + ///name.read + (text.enclose [..class-prefix ..class-suffix]) + :abstraction)) + + (def: #export var (..class "java.lang.Object")) + (def: #export wildcard (..class "java.lang.Object")) + + (def: array-prefix "[") + + (def: #export array + (-> (Descriptor Value) + (Descriptor Array)) + (|>> :representation + (format ..array-prefix) + :abstraction)) + + (def: #export (method [inputs output]) + (-> [(List (Descriptor Value)) + (Descriptor (Return Any))] + (Descriptor Method)) + (:abstraction + (format (|> inputs + (list@map (|>> :representation)) + (text.join-with "") + (text.enclose ["(" ")"])) + (:representation output)))) + + (def: #export descriptor + (-> (Descriptor Any) Text) + (|>> :representation)) + + (structure: #export equivalence + (All [brand] (Equivalence (Descriptor brand))) + + (def: (= parameter subject) + (text@= (:representation parameter) (:representation subject)))) + + (def: #export (primitive? descriptor) + (-> (Descriptor Value) (Either (Descriptor Object) + (Descriptor Primitive))) + (if (`` (or (~~ (template [] + [(:: ..equivalence = descriptor)] + + [..boolean] + [..byte] + [..short] + [..int] + [..long] + [..float] + [..double] + [..char])))) + (|> descriptor :transmutation #.Right) + (|> descriptor :transmutation #.Left))) + + (def: binary-name (|>> ///name.internal ///name.external)) + + (def: #export (class? descriptor) + (-> (Descriptor Value) (Maybe Text)) + (let [repr (:representation descriptor)] + (if (and (text.starts-with? ..class-prefix repr) + (text.ends-with? ..class-suffix repr)) + (|> repr + (text.clip (text.size ..class-prefix) + (n.- (text.size ..class-suffix) + (text.size repr))) + (:: maybe.monad map ..binary-name)) + #.None))) + + (def: #export class-name + (-> (Descriptor Object) Text) + (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) + repr + (|> repr + (text.clip prefix-size + (n.- suffix-size + (text.size repr))) + (:: maybe.monad map ..binary-name) + maybe.assume)))))) + ) -- cgit v1.2.3