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 ++++++++++++++++------ 1 file changed, 66 insertions(+), 21 deletions(-) (limited to 'new-luxc/source') 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) ))) -- cgit v1.2.3