From e6162877af8246d727850b3e04d4ab23d72cfe5f Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 17 May 2008 12:47:31 +0000 Subject: [PATCH] Changed the AST to fix the different unknown/inferred types The Infer type (used by the occam frontend) is now separated from the "Unknown" types used in type unification that I'm experimenting with in Rain. --- common/ShowCode.hs | 16 ++++++++++++---- data/AST.hs | 7 +++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/common/ShowCode.hs b/common/ShowCode.hs index c3031db..ece5726 100644 --- a/common/ShowCode.hs +++ b/common/ShowCode.hs @@ -225,8 +225,12 @@ instance ShowOccam A.Type where showOccamM A.Any = tell ["ANY"] showOccamM (A.Timer _) = tell ["TIMER"] showOccamM A.Time = tell ["TIME"] - showOccamM A.Infer = tell ["(inferred type)"] - showOccamM (A.InferNum n) = tell ["(inferred numeric type: ",show n,")"] + showOccamM (A.UnknownVarType en) + = do tell ["(inferred type for: "] + either showName (const $ return ()) en + tell [")"] + showOccamM (A.UnknownNumLitType m _ n) + = tell ["(inferred numeric type: ",show m," ",show n,")"] showOccamM (A.Mobile t) = tell ["MOBILE "] >> showOccamM t showOccamM (A.Array ds t) = (sequence dims) >> showOccamM t @@ -267,8 +271,12 @@ instance ShowRain A.Type where -- Mobility is not explicit in Rain: showRainM (A.Mobile t) = showRainM t showRainM (A.List t) = tell ["["] >> showRainM t >> tell ["]"] - showRainM A.Infer = tell ["(inferred type)"] - showRainM (A.InferNum n) = tell ["(inferred numeric type: ",show n,")"] + showRainM (A.UnknownVarType en) + = do tell ["(inferred type for: "] + either showName (const $ return ()) en + tell [")"] + showRainM (A.UnknownNumLitType m _ n) + = tell ["(inferred numeric type: ",show m," ",show n,")"] showRainM x = tell [""] instance ShowOccam A.DyadicOp where diff --git a/data/AST.hs b/data/AST.hs index 4989d1e..8210380 100644 --- a/data/AST.hs +++ b/data/AST.hs @@ -144,9 +144,12 @@ data Type = | Mobile Type -- | A type that will be inferred automatically by a pass. | Infer + -- | A type that will be inferred by type unification. Either for a named + -- variable, or for an anonymous, uniquely identified, expression + | UnknownVarType (Either Name (Meta, Int)) -- | A numeric type to be inferred later, that must be able to hold the given - -- value - | InferNum Integer + -- value. The Int is a unique identifier, the Integer is the number to hold + | UnknownNumLitType Meta Int Integer deriving (Show, Eq, Typeable, Data) -- | An array dimension.