Skip to content

Commit

Permalink
Fixed a problem with specializing classes with >1 superclass.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenFokker committed Feb 23, 2009
1 parent 761f80a commit 050cca7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ehc/Base/HsName.chs
Expand Up @@ -206,8 +206,8 @@ hsnShowAlphanumeric (HNmNr n OrigNone) = "x" ++ show n
hsnShowAlphanumeric (HNmNr n (OrigLocal orig)) = hsnShowAlphanumeric orig
hsnShowAlphanumeric (HNmNr n (OrigGlobal orig)) = "global_" ++ hsnShowAlphanumeric orig
hsnShowAlphanumeric (HNmNr n (OrigFunc orig)) = "fun_" ++ hsnShowAlphanumeric orig
%%]
hsnShowAlphanumeric (HNmQ ns) = concat $ intersperse "_" $ map hsnShowAlphanumeric ns
%%]



Expand Down
26 changes: 23 additions & 3 deletions src/ehc/EH/ToCore.cag
Expand Up @@ -584,7 +584,7 @@ SEM Decl

%%[(9 codegen)
SEM Decl
| Val lhs . cbindL := [mkCBind1 @patExpr.topNm $ mkCExprLet' True CBindRec @chrScopeValBindL @expr.cexpr] ++ @patExpr.cbindL
| Val lhs . cbindL := [mkCBind1 @patExpr.topNm $ mkCExprLet' True CBindRec @chrScopeValBindL @expr.cexpr] ++ @patExpr.cbindL -- '
%%]

%%[(94 codegen)
Expand Down Expand Up @@ -785,10 +785,22 @@ SEM Decl
(repeat (CMeta_Dict Nothing))
superNewVars

superNameMapping2 = zip @supClsFldL
@chrSuperProveNmL
superPairs = map getBindLeftAndRightVar @chrScopeSuperBindL

doubleLookup :: HsName -> Maybe HsName
doubleLookup nm = do { nm2 <- lookup nm superNameMapping2
; nm3 <- lookup nm2 superPairs
; return nm3
}

superMbNewNames = map doubleLookup memberNames

instanceAndSuperMbNewNames = let f (Just x) _ = Just x
f _ (Just y) = Just y
f _ _ = Nothing
in zipWith f instanceMbNewNames (map getBindRightVar @chrScopeSuperBindL ++ repeat Nothing)
in zipWith f instanceMbNewNames superMbNewNames

instanceCHRBindings = cSubstOptApp @lhs.opts @cSubst
( @chrAssumeSuperBindL
Expand All @@ -808,7 +820,7 @@ SEM Decl
bind3 = mkCBind1Meta rsltNm (CMeta_Dict Nothing) dict3
contextArguments = cmetaLiftDict @chrCtxtArgNmL
in ( mkCExprLamMeta contextArguments dict4
, CMeta_DictInstance (Just (ctagTyNm @dictTag) : Just dfltNm : instanceAndSuperMbNewNames)
, CMeta_DictInstance (Just (ctagTyNm @dictTag) : Just dfltNm : instanceAndSuperMbNewNames)
)

mkDefaultD defaultBindings
Expand Down Expand Up @@ -855,6 +867,14 @@ getBindRightVar :: CBind -> Maybe HsName
getBindRightVar (CBind_Bind _ _ (CExpr_Var nm)) = Just nm
getBindRightVar _ = Nothing


getBindLeftAndRightVar :: CBind -> (HsName,HsName)

getBindLeftAndRightVar (CBind_Bind nm1 _ (CExpr_Var nm2)) = (nm1,nm2)
getBindLeftAndRightVar _ = error "getBindLeftAndRightVar: not a bind"



%%]


Expand Down

0 comments on commit 050cca7

Please sign in to comment.