From 30a237358ca0effc0aabca0a8fbc5ce81a91cb32 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 10 May 2019 00:14:42 -0400 Subject: Grounded some of the machinery used in analysis and generation on the types in "lux/target/jvm/type". --- .../luxc/lang/translation/jvm/procedure/host.lux | 87 +++- stdlib/source/lux/target/jvm/type.lux | 21 +- .../tool/compiler/phase/extension/analysis/jvm.lux | 465 ++++++++++++++------- 3 files changed, 399 insertions(+), 174 deletions(-) diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux b/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux index dfcbd8f84..b3d6281c8 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux @@ -1,5 +1,5 @@ (.module: - [lux (#- Type int char) + [lux (#- Type primitive int char) [abstract ["." monad (#+ do)]] [control @@ -21,7 +21,7 @@ ["." set]]] [target [jvm - ["_t" type (#+ Primitive Type Method)]]] + ["_t" type (#+ Primitive Bound Generic Class Type Method Var Typed Argument Return)]]] [tool [compiler [analysis (#+ Environment)] @@ -831,14 +831,58 @@ (#error.Failure error) (phase.throw extension.invalid-syntax [extension-name %synthesis input])))) +(def: var + (.Parser Var) + .text) + +(def: bound + (.Parser Bound) + (<>.or (.constant! ["" ">"]) + (.constant! ["" "<"]))) + +(def: (class' generic) + (-> (.Parser Generic) (.Parser Class)) + (.tuple (<>.and .text (<>.some generic)))) + +(def: generic + (.Parser Generic) + (<>.rec + (function (_ generic) + (let [wildcard (<>.or (.constant! ["" "?"]) + (.tuple (<>.and ..bound generic)))] + ($_ <>.or + ..var + wildcard + (class' generic)))))) + +(def: class + (.Parser Class) + (class' ..generic)) + +(def: primitive + (.Parser Primitive) + ($_ <>.or + (.constant! ["" "boolean"]) + (.constant! ["" "byte"]) + (.constant! ["" "short"]) + (.constant! ["" "int"]) + (.constant! ["" "long"]) + (.constant! ["" "float"]) + (.constant! ["" "double"]) + (.constant! ["" "char"]) + )) + (def: jvm-type - (.Parser /.JVM-Type) + (.Parser Type) (<>.rec (function (_ jvm-type) - (.tuple (<>.and .text (<>.some jvm-type)))))) + ($_ <>.or + ..primitive + ..generic + (.tuple jvm-type))))) (def: constructor-arg - (.Parser (/.Constructor-Argument Synthesis)) + (.Parser (Typed Synthesis)) (.tuple (<>.and ..jvm-type .any))) (def: annotation-parameter @@ -849,31 +893,32 @@ (.Parser (/.Annotation Synthesis)) (.tuple (<>.and .text (<>.some ..annotation-parameter)))) -(def: type-parameter - (.Parser /.Type-Parameter) - .text) - (def: argument - (.Parser /.Argument) + (.Parser Argument) (.tuple (<>.and .text ..jvm-type))) +(def: return + (.Parser Return) + (<>.or (.constant! ["" "void"]) + ..jvm-type)) + (def: overriden-method-definition (.Parser [Environment (/.Overriden-Method Synthesis)]) (.tuple (do <>.monad - [ownerT ..jvm-type + [ownerT ..class name .text strict-fp? .bit annotations (.tuple (<>.some ..annotation)) - type-parameters (.tuple (<>.some ..type-parameter)) + vars (.tuple (<>.some ..var)) self-name .text arguments (.tuple (<>.some ..argument)) - returnT ..jvm-type - exceptionsT (.tuple (<>.some ..jvm-type)) + returnT ..return + exceptionsT (.tuple (<>.some ..class)) [environment body] (.function 1 (.tuple .any))] (wrap [environment [ownerT name - strict-fp? annotations type-parameters + strict-fp? annotations vars self-name arguments returnT exceptionsT body]])))) @@ -955,8 +1000,8 @@ (..custom [($_ <>.and .text - ..jvm-type - (.tuple (<>.some ..jvm-type)) + ..class + (.tuple (<>.some ..class)) (.tuple (<>.some ..constructor-arg)) (.tuple (<>.some ..overriden-method-definition))) (function (_ extension-name generate [class-name @@ -979,7 +1024,7 @@ (dictionary.from-list reference.hash)) normalized-methods (list@map (function (_ [environment [ownerT name - strict-fp? annotations type-parameters + strict-fp? annotations vars self-name arguments returnT exceptionsT body]]) (let [local-mapping (|> environment @@ -991,7 +1036,7 @@ maybe.assume)])) (dictionary.from-list reference.hash))] [ownerT name - strict-fp? annotations type-parameters + strict-fp? annotations vars self-name arguments returnT exceptionsT (normalize-method-body local-mapping body)])) overriden-methods)] @@ -1004,7 +1049,7 @@ _ (phase.throw extension.invalid-syntax ["YOLO-TRON" %synthesis (list)])] (wrap _.DUP)))])) -(def: class +(def: bundle::class Bundle (<| (bundle.prefix "class") (|> (: Bundle bundle.empty) @@ -1023,5 +1068,5 @@ (dictionary.merge ..array) (dictionary.merge ..object) (dictionary.merge ..member) - (dictionary.merge ..class) + (dictionary.merge ..bundle::class) ))) diff --git a/stdlib/source/lux/target/jvm/type.lux b/stdlib/source/lux/target/jvm/type.lux index 23925e468..e6532fe0d 100644 --- a/stdlib/source/lux/target/jvm/type.lux +++ b/stdlib/source/lux/target/jvm/type.lux @@ -22,8 +22,8 @@ (def: object-class "java.lang.Object") (type: #export Bound - #Upper - #Lower) + #Lower + #Upper) (type: #export Primitive #Boolean @@ -35,10 +35,12 @@ #Double #Char) +(type: #export Var Text) + (type: #export #rec Generic - (#Var Text) + (#Var Var) (#Wildcard (Maybe [Bound Generic])) - (#Class Text (List Generic))) + (#Class [Text (List Generic)])) (type: #export Class [Text (List Generic)]) @@ -51,11 +53,20 @@ (#Generic Generic) (#Array Type)) +(type: #export Argument + [Text Type]) + +(type: #export Return + (Maybe Type)) + (type: #export Method {#args (List Type) - #return (Maybe Type) + #return Return #exceptions (List Generic)}) +(type: #export (Typed a) + [Type a]) + (template [ ] [(def: #export Type (#Primitive ))] diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux index a9417050a..69e80d89f 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux @@ -1,5 +1,5 @@ (.module: - [lux (#- char int) + [lux (#- Type primitive type char int) ["." host (#+ import:)] ["." macro] [abstract @@ -20,10 +20,10 @@ ["." array (#+ Array)] ["." dictionary (#+ Dictionary)]]] ["." type - ["." check]] + ["." check (#+ Check) ("#@." monad)]] [target [jvm - ["_." type]]]] + ["_." type (#+ Var Bound Primitive Generic Class Type Argument Return Typed)]]]] ["." // #_ ["#." common] ["/#" // @@ -39,10 +39,20 @@ (def: inheritance-relationship-type-name "_jvm_inheritance") (def: (inheritance-relationship-type class super-class super-interfaces) - (-> Type Type (List Type) Type) + (-> .Type .Type (List .Type) .Type) (#.Primitive ..inheritance-relationship-type-name (list& class super-class super-interfaces))) +(template [