comparison src/mono_util.sml @ 506:65d8541c130b

Fusing writes with recursive function calls
author Adam Chlipala <adamc@hcoop.net>
date Tue, 25 Nov 2008 10:05:44 -0500
parents bb27c7efcd90
children a152905c3c3b
comparison
equal deleted inserted replaced
505:e18c747dd945 506:65d8541c130b
420 exp = fn e => fn s => S.Continue (e, exp (e, s)), 420 exp = fn e => fn s => S.Continue (e, exp (e, s)),
421 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of 421 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of
422 S.Continue (_, s) => s 422 S.Continue (_, s) => s
423 | S.Return _ => raise Fail "MonoUtil.Decl.fold: Impossible" 423 | S.Return _ => raise Fail "MonoUtil.Decl.fold: Impossible"
424 424
425 fun map {typ, exp, decl} e =
426 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
427 exp = fn e => fn () => S.Continue (exp e, ()),
428 decl = fn d => fn () => S.Continue (decl d, ())} e () of
429 S.Return () => raise Fail "MonoUtil.Decl.map: Impossible"
430 | S.Continue (e, ()) => e
431
425 end 432 end
426 433
427 structure File = struct 434 structure File = struct
428 435
429 datatype binder = datatype Exp.binder 436 datatype binder = datatype Exp.binder
488 495
489 fun map {typ, exp, decl} e = 496 fun map {typ, exp, decl} e =
490 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()), 497 case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
491 exp = fn e => fn () => S.Continue (exp e, ()), 498 exp = fn e => fn () => S.Continue (exp e, ()),
492 decl = fn d => fn () => S.Continue (decl d, ())} e () of 499 decl = fn d => fn () => S.Continue (decl d, ())} e () of
493 S.Return () => raise Fail "Mono_util.File.map" 500 S.Return () => raise Fail "MonoUtil.File.map: Impossible"
494 | S.Continue (e, ()) => e 501 | S.Continue (e, ()) => e
495 502
496 fun fold {typ, exp, decl} s d = 503 fun fold {typ, exp, decl} s d =
497 case mapfold {typ = fn c => fn s => S.Continue (c, typ (c, s)), 504 case mapfold {typ = fn c => fn s => S.Continue (c, typ (c, s)),
498 exp = fn e => fn s => S.Continue (e, exp (e, s)), 505 exp = fn e => fn s => S.Continue (e, exp (e, s)),
499 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of 506 decl = fn d => fn s => S.Continue (d, decl (d, s))} d s of
500 S.Continue (_, s) => s 507 S.Continue (_, s) => s
501 | S.Return _ => raise Fail "MonoUtil.File.fold: Impossible" 508 | S.Return _ => raise Fail "MonoUtil.File.fold: Impossible"
502 509
510 val maxName = foldl (fn ((d, _) : decl, count) =>
511 case d of
512 DDatatype (_, n, ns) =>
513 foldl (fn ((_, n', _), m) => Int.max (n', m))
514 (Int.max (n, count)) ns
515 | DVal (_, n, _, _, _) => Int.max (n, count)
516 | DValRec vis => foldl (fn ((_, n, _, _, _), count) => Int.max (n, count)) count vis
517 | DExport _ => count
518 | DTable _ => count
519 | DSequence _ => count
520 | DDatabase _ => count) 0
521
503 end 522 end
504 523
505 end 524 end