on master help sign in
Hook up new output; deal with exact calls
commit168278ecd74436e439d7d9809da73252bc30648d authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateWed 23 May 2012, 20:33 (14 years ago) parent0887715
5 files changed+33−12
src/Idris/AbsSyntax.hs+1 src/Main.hs+9 src/RTS/CodegenC.hs+15−7 src/RTS/PreC.hs+6−5 src/RTS/SC.hs+2
src/Idris/AbsSyntax.hs+1
@@ -415,6 +415,7 @@ data Opt = Filename String
415415 | NoREPL
416416 | OLogging Int
417417 | Output String
418+ | NewOutput String
418419 | TypeCase
419420 | TypeInType
420421 | NoCoverage
src/Main.hs+9
@@ -39,6 +39,7 @@ runIdris opts =
3939 do let inputs = opt getFile opts
4040 let runrepl = not (NoREPL `elem` opts)
4141 let output = opt getOutput opts
42+ let newoutput = opt getNewOutput opts
4243 let ibcsubdir = opt getIBCSubDir opts
4344 let importdirs = opt getImportDir opts
4445 let bcs = opt getBC opts
@@ -69,6 +70,9 @@ runIdris opts =
6970 when ok $ case output of
7071 [] -> return ()
7172 (o:_) -> process "" (Compile o)
73+ when ok $ case newoutput of
74+ [] -> return ()
75+ (o:_) -> process "" (NewCompile o)
7276 when runrepl $ repl ist inputs
7377 ok <- noErrors
7478 when (not ok) $ liftIO (exitWith (ExitFailure 1))
@@ -92,6 +96,10 @@ getOutput :: Opt -> Maybe String
9296getOutput (Output str) = Just str
9397getOutput _ = Nothing
9498
99+getNewOutput :: Opt -> Maybe String
100+getNewOutput (NewOutput str) = Just str
101+getNewOutput _ = Nothing
102+
95103getIBCSubDir :: Opt -> Maybe String
96104getIBCSubDir (IBCSubDir str) = Just str
97105getIBCSubDir _ = Nothing
@@ -123,6 +131,7 @@ parseArgs ("--log":lvl:ns) = liftM (OLogging (read lvl) : ) (parseArgs ns)
123131parseArgs ("--noprelude":ns) = liftM (NoPrelude : ) (parseArgs ns)
124132parseArgs ("--check":ns) = liftM (NoREPL : ) (parseArgs ns)
125133parseArgs ("-o":n:ns) = liftM (\x -> NoREPL : Output n : x) (parseArgs ns)
134+parseArgs ("-no":n:ns) = liftM (\x -> NoREPL : NewOutput n : x) (parseArgs ns)
126135parseArgs ("--typecase":ns) = liftM (TypeCase : ) (parseArgs ns)
127136parseArgs ("--typeintype":ns) = liftM (TypeInType : ) (parseArgs ns)
128137parseArgs ("--nocoverage":ns) = liftM (NoCoverage : ) (parseArgs ns)
src/RTS/CodegenC.hs+15−7
@@ -84,6 +84,9 @@ catom (CL l) = reg (LVar l)
8484catom (CC (I i)) = "MKINT(" ++ show i ++ ")"
8585catom (CC v) = "const(" ++ show v ++ ")"
8686catom (CP n) = cname n
87+
88+off o (CL i) = CL (i + o)
89+off o x = x
8790
8891assignCon i r tag args
8992 = indent i ++ reg r ++ " = MKCON(" ++ show tag ++ ", " ++
@@ -97,17 +100,22 @@ assignCon i r tag args
97100
98101assignFn i r f args
99102 = indent i ++ "EXTEND(" ++ show (length args) ++ ");\n" ++
100− indent i ++ setArgs 1 (reverse args) ++ "\n"
101− -- indent i ++ "CALL(" ++ reg r ++ ", " ++ cname f ++ ");\n"
103+ indent i ++ setArgs 1 (map (off (length args)) (reverse args)) ++ "\n" ++
104+ indent i ++ cname f ++ "(vm);\n" ++
105+ indent i ++ "CLEAR(" ++ show (length args) ++ ");\n" ++
106+ case r of
107+ RVal -> ""
108+ r -> indent i ++ reg r ++ " = " ++ reg RVal ++ "\n"
102109 where
103110 setArgs i [] = ""
104111 setArgs i (a : as) = reg (LVar i) ++ " = " ++ catom a ++ "; "
105112 ++ setArgs (i + 1) as
106113
107−tailCall i d f args
114+doTailCall i d f args
108115 = indent i ++ "EXTEND(" ++ show (length args) ++ ");\n" ++
109− indent i ++ setArgs 1 (reverse args) ++ "\n"
110−-- indent i ++ "TAILCALL(" ++ show d ++ ", " ++ cname f ++ ");\n"
116+ indent i ++ setArgs 1 (map (off (length args)) (reverse args)) ++ "\n" ++
117+ indent i ++ "SLIDE(" ++ show d ++ ", " ++ show (length args) ++ ");\n" ++
118+ indent i ++ cname f ++ "(vm); return;\n"
111119 where
112120 setArgs i [] = ""
113121 setArgs i (a : as) = reg (LVar i) ++ " = " ++ catom a ++ "; "
@@ -116,7 +124,7 @@ tailCall i d f args
116124cg :: Int -> CInst -> String
117125cg i (ASSIGN r (CCon t args))
118126 = assignCon i r t args
119−cg i (ASSIGN r (CApp f args))
127+cg i (ASSIGN r (CExactApp f args))
120128 = assignFn i r f args
121129cg i (ASSIGN r (CAtom e)) = indent i ++ reg r ++ " = " ++ catom e ++ ";\n"
122130cg i (RESERVE s) = indent i ++ "EXTEND(" ++ show s ++ ");\n"
@@ -137,7 +145,7 @@ cg i (SWITCH v bs def)
137145 branch (t, c) = indent i ++ "case " ++ show t ++ ":\n" ++
138146 concatMap (cg (i+1)) c ++
139147 indent (i+1) ++ "break;\n"
140−cg i (TAILCALL d f args) = tailCall i d f args
148+cg i (TAILCALLEXACT d f args) = doTailCall i d f args
141149cg i (ERROR s) = indent i ++ "ERROR(" ++ show s ++ ")\n";
142150cg i _ = indent i ++ "NOT DONE;\n"
143151
src/RTS/PreC.hs+6−5
@@ -14,7 +14,7 @@ data CAtom = CP Name | CL Local | CC Const
1414
1515data CExp = CAtom CAtom
1616 | CApp CAtom [CAtom]
17− | CExactApp CAtom [CAtom]
17+ | CExactApp Name [CAtom]
1818 | CLazy CAtom [CAtom]
1919 | CFCall String CType [(CAtom, CType)]
2020 | CPrimOp SPrim [CAtom]
@@ -38,7 +38,7 @@ data CInst = ASSIGN Reg CExp
3838 | ERROR String
3939 | TAILCALL Int -- number of stack items to clear
4040 CAtom [CAtom]
41− | TAILCALLEXACT Int CAtom [CAtom]
41+ | TAILCALLEXACT Int Name [CAtom]
4242 deriving Show
4343
4444type PreC = [CInst]
@@ -51,20 +51,21 @@ atom res (BL n) = CL (res - n)
5151atom res (BC c) = CC c
5252
5353preC :: [(Name, (Int, Bytecode))] -> Bytecode -> (Int, PreC)
54−preC all (BGetArgs ns bc) = (length ns, pc RVal (length ns) bc)
54+preC all (BGetArgs ns bc) = (length ns, pc RVal (length ns) bc)
5555 where arity n = do (i, b) <- lookup n all
5656 return i
5757 exact (BP n) as = case arity n of
5858 Just i -> i == length as
5959 Nothing -> False
6060 exact _ as = False
61+ getName (BP n) = n
6162
6263 pc loc d (BAtom b) = [ASSIGN loc (CAtom (atom d b))]
6364 pc loc d (BApp f as)
64− | exact f as = [ASSIGN loc (CExactApp (atom d f) (map (atom d) as))]
65+ | exact f as = [ASSIGN loc (CExactApp (getName f) (map (atom d) as))]
6566 | otherwise = [ASSIGN loc (CApp (atom d f) (map (atom d) as))]
6667 pc loc d (BTailApp f as)
67− | exact f as = [TAILCALLEXACT d (atom d f) (map (atom d) as)]
68+ | exact f as = [TAILCALLEXACT d (getName f) (map (atom d) as)]
6869 | otherwise = [TAILCALL d (atom d f) (map (atom d) as)]
6970 pc loc d (BLazy f as) = [ASSIGN loc (CLazy (atom d f) (map (atom d) as))]
7071 pc loc d (BLet x val sc) = pc (LVar (d - x)) d val ++ pc loc d sc
src/RTS/SC.hs+2
@@ -116,6 +116,8 @@ instance Lift Def () where
116116 add (n, SCDef (zip (env ++ args) (repeat Nothing)) 0 cases')
117117
118118instance Lift (TT Name) SCExp where
119+ sc env (P (DCon t a) _ _) = return $ SCon t []
120+ sc env (P (TCon t a) _ _) = return $ SCon t []
119121 sc env (P _ n _) = return $ SRef n
120122 sc env (V i) = return $ SRef (env!!i)
121123 sc env fn@(App _ _)