forked from GitHub/gf-core
added an argument place to ResOverload for extended overloads
This commit is contained in:
@@ -231,14 +231,14 @@ checkResInfo gr mo mm (c,info) = do
|
|||||||
_ -> return (pty, pde) --- other cases are uninteresting
|
_ -> return (pty, pde) --- other cases are uninteresting
|
||||||
return (c, ResOper pty' pde')
|
return (c, ResOper pty' pde')
|
||||||
|
|
||||||
ResOverload tysts -> chIn "overloading" $ do
|
ResOverload os tysts -> chIn "overloading" $ do
|
||||||
tysts' <- mapM (uncurry $ flip check) tysts
|
tysts' <- mapM (uncurry $ flip check) tysts
|
||||||
let tysts2 = [(y,x) | (x,y) <- tysts']
|
let tysts2 = [(y,x) | (x,y) <- tysts']
|
||||||
--- this can only be a partial guarantee, since matching
|
--- this can only be a partial guarantee, since matching
|
||||||
--- with value type is only possible if expected type is given
|
--- with value type is only possible if expected type is given
|
||||||
checkUniq $
|
checkUniq $
|
||||||
sort [t : map snd xs | (x,_) <- tysts2, Ok (xs,t) <- [typeFormCnc x]]
|
sort [t : map snd xs | (x,_) <- tysts2, Ok (xs,t) <- [typeFormCnc x]]
|
||||||
return (c,ResOverload tysts2)
|
return (c,ResOverload os tysts2)
|
||||||
|
|
||||||
ResParam (Yes (pcs,_)) -> chIn "parameter type" $ do
|
ResParam (Yes (pcs,_)) -> chIn "parameter type" $ do
|
||||||
---- mapM ((mapM (computeLType gr . snd)) . snd) pcs
|
---- mapM ((mapM (computeLType gr . snd)) . snd) pcs
|
||||||
|
|||||||
@@ -119,10 +119,10 @@ refreshModule (k,ms) mi@(i,m) = case m of
|
|||||||
ResOper ptyp (Yes trm) -> do ---- refresh ptyp
|
ResOper ptyp (Yes trm) -> do ---- refresh ptyp
|
||||||
(k',trm') <- refreshTermKN k trm
|
(k',trm') <- refreshTermKN k trm
|
||||||
return $ (k', (c, ResOper ptyp (Yes trm')):cs)
|
return $ (k', (c, ResOper ptyp (Yes trm')):cs)
|
||||||
ResOverload tyts -> do
|
ResOverload os tyts -> do
|
||||||
(k',tyts') <- liftM (\ (t,(_,i)) -> (i,t)) $
|
(k',tyts') <- liftM (\ (t,(_,i)) -> (i,t)) $
|
||||||
appSTM (mapPairsM refresh tyts) (initIdStateN k)
|
appSTM (mapPairsM refresh tyts) (initIdStateN k)
|
||||||
return $ (k', (c, ResOverload tyts'):cs)
|
return $ (k', (c, ResOverload os tyts'):cs)
|
||||||
CncCat mt (Yes trm) pn -> do ---- refresh mt, pn
|
CncCat mt (Yes trm) pn -> do ---- refresh mt, pn
|
||||||
(k',trm') <- refreshTermKN k trm
|
(k',trm') <- refreshTermKN k trm
|
||||||
return $ (k', (c, CncCat mt (Yes trm') pn):cs)
|
return $ (k', (c, CncCat mt (Yes trm') pn):cs)
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ renameInfo mo status (i,info) = errIn
|
|||||||
AbsTrans f -> liftM AbsTrans (rent f)
|
AbsTrans f -> liftM AbsTrans (rent f)
|
||||||
|
|
||||||
ResOper pty ptr -> liftM2 ResOper (ren pty) (ren ptr)
|
ResOper pty ptr -> liftM2 ResOper (ren pty) (ren ptr)
|
||||||
ResOverload tysts -> liftM ResOverload $ mapM (pairM rent) tysts
|
ResOverload os tysts ->
|
||||||
|
liftM2 ResOverload (mapM rent os) (mapM (pairM rent) tysts)
|
||||||
|
|
||||||
ResParam (Yes (pp,m)) -> do
|
ResParam (Yes (pp,m)) -> do
|
||||||
pp' <- mapM (renameParam status) pp
|
pp' <- mapM (renameParam status) pp
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ data Info =
|
|||||||
| ResValue (Perh (Type,Maybe Int)) -- ^ (/RES/) to mark parameter constructors for lookup
|
| ResValue (Perh (Type,Maybe Int)) -- ^ (/RES/) to mark parameter constructors for lookup
|
||||||
| ResOper (Perh Type) (Perh Term) -- ^ (/RES/)
|
| ResOper (Perh Type) (Perh Term) -- ^ (/RES/)
|
||||||
|
|
||||||
| ResOverload [(Type,Term)] -- ^ (/RES/)
|
| ResOverload [Term] [(Type,Term)] -- ^ (/RES/)
|
||||||
|
|
||||||
-- judgements in concrete syntax
|
-- judgements in concrete syntax
|
||||||
| CncCat (Perh Type) (Perh Term) MPr -- ^ (/CNC/) lindef ini'zed,
|
| CncCat (Perh Type) (Perh Term) MPr -- ^ (/CNC/) lindef ini'zed,
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ lookupOverload gr m c = do
|
|||||||
ModMod mo -> do
|
ModMod mo -> do
|
||||||
info <- lookupIdentInfo mo c
|
info <- lookupIdentInfo mo c
|
||||||
case info of
|
case info of
|
||||||
ResOverload tysts ->
|
ResOverload os tysts ->
|
||||||
return [(map snd args,(val,tr)) |
|
return [(map snd args,(val,tr)) |
|
||||||
(ty,tr) <- tysts, Ok (args,val) <- [typeFormCnc ty]]
|
(ty,tr) <- tysts, Ok (args,val) <- [typeFormCnc ty]]
|
||||||
|
|
||||||
|
|||||||
@@ -96,10 +96,12 @@ trAnyDef (i,info) = let i' = tri i in case info of
|
|||||||
May b -> P.ParDefIndir i' $ tri b
|
May b -> P.ParDefIndir i' $ tri b
|
||||||
_ -> P.ParDefAbs i']]
|
_ -> P.ParDefAbs i']]
|
||||||
|
|
||||||
ResOverload tysts ->
|
ResOverload os tysts ->
|
||||||
[P.DefOper [P.DDef [mkName i'] (
|
[P.DefOper [P.DDef [mkName i'] (
|
||||||
P.EApp (P.EIdent $ tri $ cOverload)
|
foldl P.EApp
|
||||||
(P.ERecord [P.LDFull [i'] (trt ty) (trt fu) | (ty,fu) <- tysts]))]]
|
(P.EIdent $ tri $ cOverload)
|
||||||
|
(map trt os ++
|
||||||
|
[P.ERecord [P.LDFull [i'] (trt ty) (trt fu) | (ty,fu) <- tysts]]))]]
|
||||||
|
|
||||||
CncCat (Yes ty) Nope _ ->
|
CncCat (Yes ty) Nope _ ->
|
||||||
[P.DefLincat [P.PrintDef [mkName i'] (trt ty)]]
|
[P.DefLincat [P.PrintDef [mkName i'] (trt ty)]]
|
||||||
|
|||||||
@@ -353,18 +353,26 @@ transResDef x = case x of
|
|||||||
DefFlag defs -> liftM (Right . concatModuleOptions) $ mapM transFlagDef defs
|
DefFlag defs -> liftM (Right . concatModuleOptions) $ mapM transFlagDef defs
|
||||||
_ -> Bad $ "illegal definition form in resource" +++ printTree x
|
_ -> Bad $ "illegal definition form in resource" +++ printTree x
|
||||||
where
|
where
|
||||||
mkOverload (c,p,j) = case j of
|
mkOverload op@(c,p,j) = case j of
|
||||||
G.ResOper _ (Yes (G.App keyw (G.R fs@(_:_:_)))) |
|
G.ResOper _ (Yes df) -> case M.appForm df of
|
||||||
isOverloading keyw c fs ->
|
(keyw, ts@(_:_)) | isOverloading keyw -> case last ts of
|
||||||
[(c,p,G.ResOverload [(ty,fu) | (_,(Just ty,fu)) <- fs])]
|
G.R fs ->
|
||||||
|
[(c,p,G.ResOverload (init ts) [(ty,fu) | (_,(Just ty,fu)) <- fs])]
|
||||||
|
_ -> [op]
|
||||||
|
_ -> [op]
|
||||||
|
|
||||||
-- to enable separare type signature --- not type-checked
|
-- to enable separare type signature --- not type-checked
|
||||||
G.ResOper (Yes (G.App keyw (G.RecType fs@(_:_:_)))) _ |
|
G.ResOper (Yes df) _ -> case M.appForm df of
|
||||||
isOverloading keyw c fs -> []
|
(keyw, ts@(_:_)) | isOverloading keyw -> case last ts of
|
||||||
|
G.RecType _ -> []
|
||||||
|
_ -> [op]
|
||||||
|
_ -> [op]
|
||||||
_ -> [(c,p,j)]
|
_ -> [(c,p,j)]
|
||||||
isOverloading keyw c fs =
|
isOverloading keyw =
|
||||||
GP.prt keyw == "overload" && -- overload is a "soft keyword"
|
GP.prt keyw == "overload" -- overload is a "soft keyword"
|
||||||
all (== GP.prt c) (map (GP.prt . fst) fs)
|
isRec t = case t of
|
||||||
|
G.R _ -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
transParDef :: ParDef -> Err (Ident, [G.Param])
|
transParDef :: ParDef -> Err (Ident, [G.Param])
|
||||||
transParDef x = case x of
|
transParDef x = case x of
|
||||||
|
|||||||
Reference in New Issue
Block a user