184 |
[], le)) |
[], le)) |
185 |
|
|
186 |
(* process each fun *) |
(* process each fun *) |
187 |
fun ffun (fdec as (fk,f,args,body):F.fundec,(s,fv,funs,m)) = |
fun ffun (fdec as (fk as {isrec,...},f,args,body):F.fundec, |
188 |
|
(s,fv,funs,m)) = |
189 |
case curry (true,false,!maxargs) (F.FIX([fdec], F.RET[F.VAR f])) |
case curry (true,false,!maxargs) (F.FIX([fdec], F.RET[F.VAR f])) |
190 |
of (args as _::_::_,body) => (* curried function *) |
of (args as _::_::_,body) => (* curried function *) |
191 |
let val ((fk,f,fargs,fbody),(fk',f',fargs',fbody')) = |
let val ((fk,f,fargs,fbody),(fk',f',fargs',fbody')) = |
200 |
let val (fs,ffv,body) = fexp(S.empty, body) |
let val (fs,ffv,body) = fexp(S.empty, body) |
201 |
val ffv = rmvs(ffv, map #1 args) (* fun's freevars *) |
val ffv = rmvs(ffv, map #1 args) (* fun's freevars *) |
202 |
val ifv = S.inter(ffv, funs) (* set of rec funs ref'ed *) |
val ifv = S.inter(ffv, funs) (* set of rec funs ref'ed *) |
203 |
|
val fs = fs div (case isrec of SOME(_,F.LK_TAIL) => 3 |
204 |
|
| SOME(_,F.LK_LOOP) => 1 |
205 |
|
| _ => 1) |
206 |
in |
in |
207 |
(fs + s, S.union(ffv, fv), funs, |
(fs + s, S.union(ffv, fv), funs, |
208 |
M.add(m, f, (S.members ifv, fs, fk, args, body))) |
M.add(m, f, (S.members ifv, fs, fk, args, body))) |
239 |
* This heuristic is pretty bad since it doesn't |
* This heuristic is pretty bad since it doesn't |
240 |
* take the number of rec-calls into account *) |
* take the number of rec-calls into account *) |
241 |
case (isrec,inline) |
case (isrec,inline) |
242 |
of (SOME(_,(F.LK_LOOP|F.LK_WHILE)),F.IH_SAFE) => |
of (SOME(_,(F.LK_LOOP|F.LK_TAIL)),F.IH_SAFE) => |
243 |
if s < !CTRL.unrollThreshold then |
if s < !CTRL.unrollThreshold then |
244 |
{inline=F.IH_UNROLL, isrec=isrec, |
{inline=F.IH_UNROLL, isrec=isrec, |
245 |
cconv=cconv, known=known} |
cconv=cconv, known=known} |