annotate src/reduce_local.sml @ 499:12d163bb856f

Update Crud demo to use local functions
author Adam Chlipala <adamc@hcoop.net>
date Thu, 20 Nov 2008 10:41:58 -0500
parents 9117a7bf229c
children 40b19310ea9a
rev   line source
adamc@482 1 (* Copyright (c) 2008, Adam Chlipala
adamc@482 2 * All rights reserved.
adamc@482 3 *
adamc@482 4 * Redistribution and use in source and binary forms, with or without
adamc@482 5 * modification, are permitted provided that the following conditions are met:
adamc@482 6 *
adamc@482 7 * - Redistributions of source code must retain the above copyright notice,
adamc@482 8 * this list of conditions and the following disclaimer.
adamc@482 9 * - Redistributions in binary form must reproduce the above copyright notice,
adamc@482 10 * this list of conditions and the following disclaimer in the documentation
adamc@482 11 * and/or other materials provided with the distribution.
adamc@482 12 * - The names of contributors may not be used to endorse or promote products
adamc@482 13 * derived from this software without specific prior written permission.
adamc@482 14 *
adamc@482 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@482 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@482 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@482 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@482 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
adamc@482 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@482 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@482 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@482 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@482 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@482 25 * POSSIBILITY OF SUCH DAMAGE.
adamc@482 26 *)
adamc@482 27
adamc@482 28 (* Simplify a Core program algebraically, without unfolding definitions *)
adamc@482 29
adamc@482 30 structure ReduceLocal :> REDUCE_LOCAL = struct
adamc@482 31
adamc@482 32 open Core
adamc@482 33
adamc@482 34 structure E = CoreEnv
adamc@482 35 structure U = CoreUtil
adamc@482 36
adamc@482 37 val subExpInExp = E.subExpInExp
adamc@482 38
adamc@482 39 fun default x = x
adamc@482 40
adamc@482 41 fun exp (e : exp') =
adamc@482 42 let
adamc@482 43 (*val () = Print.prefaces "exp" [("e", CorePrint.p_exp env (e, ErrorMsg.dummySpan))]*)
adamc@482 44
adamc@482 45 val r = case e of
adamc@482 46 EApp ((EAbs (x, t, _, e1), loc), e2) =>
adamc@482 47 ((*Print.prefaces "Substitute" [("x", Print.PD.string x),
adamc@482 48 ("t", CorePrint.p_con CoreEnv.empty t)];*)
adamc@482 49 #1 (reduceExp (subExpInExp (0, e2) e1)))
adamc@482 50
adamc@482 51 | EField ((ERecord xes, _), (CName x, _), _) =>
adamc@482 52 (case List.find (fn ((CName x', _), _, _) => x' = x
adamc@482 53 | _ => false) xes of
adamc@482 54 SOME (_, (e, _), _) => e
adamc@482 55 | NONE => e)
adamc@482 56
adamc@482 57 | _ => e
adamc@482 58 in
adamc@482 59 (*Print.prefaces "exp'" [("e", CorePrint.p_exp env (e, ErrorMsg.dummySpan)),
adamc@482 60 ("r", CorePrint.p_exp env (r, ErrorMsg.dummySpan))];*)
adamc@482 61
adamc@482 62 r
adamc@482 63 end
adamc@482 64
adamc@482 65 and reduceExp e = U.Exp.map {kind = default, con = default, exp = exp} e
adamc@482 66
adamc@482 67 val reduce = U.File.map {kind = default, con = default, exp = exp, decl = default}
adamc@482 68
adamc@482 69 end