diff --git a/frontends/RainPasses.hs b/frontends/RainPasses.hs index f0cdc26..5b18cca 100644 --- a/frontends/RainPasses.hs +++ b/frontends/RainPasses.hs @@ -40,7 +40,11 @@ rainPasses = [ ("AST Validity check, Rain #1", excludeNonRainFeatures) ,("Resolve Int -> Int64",transformInt) ,("Uniquify variable declarations, record declared types and resolve variable names",uniquifyAndResolveVars) --depends on transformInt - ,("Record inferred name types in dictionary",recordInfNameTypes) --depends on uniquifyAndResolveVars + + ,("Fold all constant expressions",constantFoldPass) -- depends on transformInt and possibly depends on uniquifyAndResolveVars, not sure + ,("Annotate integer literal types",annnotateIntLiteralTypes) --depends on transformInt and constantFoldPass + + ,("Record inferred name types in dictionary",recordInfNameTypes) --depends on uniquifyAndResolveVars and annnotateIntLiteralTypes ,("Find and tag the main function",findMain) --depends on uniquifyAndResolveVars ,("Check parameters in process calls",matchParamPass) --depends on uniquifyAndResolveVars and recordInfNameTypes ,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",transformEachRange) diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index f916353..5854044 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -69,4 +69,25 @@ annnotateIntLiteralTypes :: Data t => t -> PassM t annnotateIntLiteralTypes = everywhereASTM doExpression where doExpression :: A.Expression -> PassM A.Expression - doExpression = return + doExpression (A.Literal m t (A.IntLiteral m' s)) + = do t' <- + if (t == A.Int64) then --it's a signed literal + (if (n >= 2^63 || n < (-(2^63))) + then dieP m $ "Signed integer literal too large to fit into 64 bits: " ++ s + else + if (n < (-(2^31)) || n >= 2^31) + then return A.Int64 + else + if (n < (-(2^15)) || n >= 2^15) + then return A.Int32 + else + if (n < (-(2^7)) || n >= 2^7) + then return A.Int16 + else return A.Int8 + ) + else + dieP m $ "Unsigned literals currently unsupported" + return $ A.Literal m t' (A.IntLiteral m' s) + where + n = read s + doExpression e = return e