From 824482b2e8b13e42a524a5e4945ea3e172395c9e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 15 May 2017 22:19:14 -0400 Subject: WIP - Simplified the Analysis type, by removing all meta-data. - Added analysis of function calls. - Added analysis of common Lux procedures. - Lots of refactoring. --- new-luxc/source/luxc/analyser/common.lux | 67 +++++++------------------------- 1 file changed, 13 insertions(+), 54 deletions(-) (limited to 'new-luxc/source/luxc/analyser/common.lux') diff --git a/new-luxc/source/luxc/analyser/common.lux b/new-luxc/source/luxc/analyser/common.lux index ed2b6eba7..7a9e5dbf8 100644 --- a/new-luxc/source/luxc/analyser/common.lux +++ b/new-luxc/source/luxc/analyser/common.lux @@ -10,64 +10,23 @@ (luxc ["&" base] (lang analysis))) -(def: #export (replace-type replacement analysis) - (-> Type Analysis Analysis) - (let [[[_type _cursor] _analysis] analysis] - (: Analysis - [[(: Type replacement) - (: Cursor _cursor)] - (: (Analysis' Analysis) - _analysis)]))) - -(def: #export (clean type analysis) - (-> Type Analysis (Lux Analysis)) - (case type - (#;Var id) - (do Monad - [=type (&;within-type-env - (TC;clean id type))] - (wrap (replace-type =type analysis))) - - (#;Ex id) - (undefined) - - _ - (&;fail (format "Cannot clean type: " (%type type))))) - (def: #export (with-unknown-type action) - (All [a] (-> (Lux Analysis) (Lux Analysis))) + (All [a] (-> (Lux Analysis) (Lux [Type Analysis]))) (do Monad [[var-id var-type] (&;within-type-env TC;create-var) - analysis (|> (wrap action) - (%> @ - [(&;with-expected-type var-type)] - [(clean var-type)])) + analysis (&;with-expected-type var-type + action) + analysis-type (&;within-type-env + (TC;clean var-id var-type)) _ (&;within-type-env (TC;delete-var var-id))] - (wrap analysis))) - -(def: #export (realize expected) - (-> Type (TC;Check [(List Type) Type])) - (case expected - (#;Named [module name] _expected) - (realize _expected) + (wrap [analysis-type analysis]))) - (#;UnivQ env body) - (do TC;Monad - [[var-id var-type] TC;create-var - [tail =expected] (realize (default (undefined) - (type;apply-type expected var-type)))] - (wrap [(list& var-type tail) - =expected])) - - (#;ExQ env body) - (do TC;Monad - [[ex-id ex-type] TC;existential - [tail =expected] (realize (default (undefined) - (type;apply-type expected ex-type)))] - (wrap [(list& ex-type tail) - =expected])) - - _ - (:: TC;Monad wrap [(list) expected]))) +(def: #export (with-var body) + (All [a] (-> (-> [Nat Type] (Lux a)) (Lux a))) + (do Monad + [[id var] (&;within-type-env TC;create-var) + output (body [id var]) + _ (&;within-type-env (TC;delete-var id))] + (wrap output))) -- cgit v1.2.3