diff options
| author | aarne <aarne@cs.chalmers.se> | 2006-04-04 14:44:46 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2006-04-04 14:44:46 +0000 |
| commit | a42a232c5756593e0681598f940c84f555af09d8 (patch) | |
| tree | 3dfb280723073111c41469754f26c39726a10aad /src | |
| parent | c437f63404dc0a4fdb42cd6eff661b071d3fca1d (diff) | |
inherent features of Int
Diffstat (limited to 'src')
| -rw-r--r-- | src/GF/Compile/CheckGrammar.hs | 14 | ||||
| -rw-r--r-- | src/GF/Grammar/Lookup.hs | 7 | ||||
| -rw-r--r-- | src/GF/UseGrammar/Linear.hs | 6 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/GF/Compile/CheckGrammar.hs b/src/GF/Compile/CheckGrammar.hs index 21eb1fbbb..d36045158 100644 --- a/src/GF/Compile/CheckGrammar.hs +++ b/src/GF/Compile/CheckGrammar.hs @@ -287,7 +287,12 @@ computeLType gr t = do Q (IC "Predef") (IC "Float") -> return ty ---- shouldn't be needed Q m c | elem c [cPredef,cPredefAbs] -> return ty - Q m c | elem c [zIdent "Int",zIdent "Float",zIdent "String"] -> return defLinType ---- + Q m c | elem c [zIdent "Int"] -> + let ints k = App (Q (IC "Predef") (IC "Ints")) (EInt k) in + return $ + RecType [ + (LIdent "s", typeStr), (LIdent "last",ints 9),(LIdent "size",ints 1)] + Q m c | elem c [zIdent "Float",zIdent "String"] -> return defLinType ---- Q m ident -> checkIn ("module" +++ prt m) $ do ty' <- checkErr (lookupResDef gr m ident) @@ -408,9 +413,10 @@ inferLType gr trm = case trm of check trm (Table arg val) T ti pts -> do -- tries to guess: good in oper type inference let pts' = [pt | pt@(p,_) <- pts, isConstPatt p] - if null pts' - then prtFail "cannot infer table type of" trm - else do + case pts' of + [] -> prtFail "cannot infer table type of" trm +---- PInt k : _ -> return $ Ints $ max [i | PInt i <- pts'] + _ -> do (arg,val) <- checks $ map (inferCase Nothing) pts' check trm (Table arg val) V arg pts -> do diff --git a/src/GF/Grammar/Lookup.hs b/src/GF/Grammar/Lookup.hs index 6c6f13611..a80217cd6 100644 --- a/src/GF/Grammar/Lookup.hs +++ b/src/GF/Grammar/Lookup.hs @@ -158,7 +158,12 @@ lookupAbsDef gr m c = errIn ("looking up absdef of" +++ prt c) $ do lookupLincat :: SourceGrammar -> Ident -> Ident -> Err Type -lookupLincat gr m c | elem c [zIdent "String", zIdent "Int", zIdent "Float"] = +lookupLincat gr m c | elem c [zIdent "Int"] = + let ints k = App (Q (IC "Predef") (IC "Ints")) (EInt k) in + return $ + RecType [ + (LIdent "s", typeStr), (LIdent "last",ints 9),(LIdent "size",ints 1)] +lookupLincat gr m c | elem c [zIdent "String", zIdent "Float"] = return defLinType --- ad hoc; not needed? lookupLincat gr m c = do diff --git a/src/GF/UseGrammar/Linear.hs b/src/GF/UseGrammar/Linear.hs index d4483bef5..86c5fad3e 100644 --- a/src/GF/UseGrammar/Linear.hs +++ b/src/GF/UseGrammar/Linear.hs @@ -60,8 +60,8 @@ linearizeToRecord gr mk m = lin [] where r <- case at of A.AtC f -> lookf c t f >>= comp xs' + A.AtI i -> return $ recInt i A.AtL s -> return $ recS $ tK $ prt at - A.AtI i -> return $ recS $ tK $ prt at A.AtF i -> return $ recS $ tK $ prt at A.AtV x -> lookCat c >>= comp [tK (prt_ at)] A.AtM m -> lookCat c >>= comp [tK (prt_ at)] @@ -79,6 +79,10 @@ linearizeToRecord gr mk m = lin [] where recS t = R [Ass (L (identC "s")) t] ---- + recInt i = R [Ass (L (identC "s")) (tK $ show i), + Ass (L (identC "last")) (EInt (rem i 10)), + Ass (L (identC "size")) (EInt (if i > 9 then 1 else 0))] + lookCat = return . errVal defLindef . look ---- should always be given in the module |
