| @@ -217,10 +217,14 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 216 unmodified lines |
| 217 | 217 | -- case of dependencies) |
| 218 | 218 | |
| 219 | 219 | -- 5. Elaborate the method bodies |
| 220 | | − |
| 221 | | − body' <- traverse (updateBody (map methNameUpdate fns)) body |
| 220 | + let upds = map methNameUpdate fns |
| 221 | + body' <- traverse (updateBody upds) body |
| 222 | 222 | log 10 $ "Implementation body: " ++ show body' |
| 223 | 223 | traverse (processDecl [] nest env) body' |
| 224 | + |
| 225 | + -- 6. Add transnformation rules for top level methods |
| 226 | + traverse (addTransform impName upds) (methods cdata) |
| 227 | + |
| 224 | 228 | -- Reset the open hints (remove the named implementation) |
| 225 | 229 | setOpenHints hs |
| 226 | 230 | pure ()) mbody |
| @@ -283,7 +287,8 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 56 unmodified lines |
| 283 | 287 | methName : Name -> Name |
| 284 | 288 | methName (NS _ n) = methName n |
| 285 | 289 | methName n |
| 286 | | − = DN (show n) (UN (show n ++ "_" ++ show iname ++ "_" ++ |
| 290 | + = DN (show n) |
| 291 | + (UN (show n ++ "_" ++ show iname ++ "_" ++ |
| 287 | 292 | maybe "" show impln ++ "_" ++ |
| 288 | 293 | showSep "_" (map show ps))) |
| 289 | 294 | |
| @@ -404,3 +409,24 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 114 unmodified lines |
| 404 | 409 | updateBody ns _ |
| 405 | 410 | = throw (GenericMsg fc |
| 406 | 411 | "Implementation body can only contain definitions") |
| 412 | + |
| 413 | + addTransform : Name -> List (Name, Name) -> |
| 414 | + (Name, RigCount, Bool, RawImp) -> |
| 415 | + Core () |
| 416 | + addTransform iname ns (top, _, _, ty) |
| 417 | + = do log 3 $ "Adding transform for " ++ show top ++ " : " ++ show ty ++ |
| 418 | + "\n\tfor " ++ show iname ++ " in " ++ show ns |
| 419 | + let lhs = IImplicitApp fc (IVar fc top) |
| 420 | + (Just (UN "__con")) |
| 421 | + (IVar fc iname) |
| 422 | + let Just mname = lookup (dropNS top) ns |
| 423 | + | Nothing => pure () |
| 424 | + let rhs = IVar fc mname |
| 425 | + log 5 $ show lhs ++ " ==> " ++ show rhs |
| 426 | + handleUnify |
| 427 | + (processDecl [] nest env |
| 428 | + (ITransform fc (UN (show top ++ " " ++ show iname)) lhs rhs)) |
| 429 | + (\err => |
| 430 | + log 5 $ "Can't add transform " ++ |
| 431 | + show lhs ++ " ==> " ++ show rhs ++ |
| 432 | + "\n\t" ++ show err) |