Mercurial > urweb
comparison src/shake.sml @ 163:80192edca30d
Datatypes through corify
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 29 Jul 2008 13:16:21 -0400 |
parents | f0d3402184d1 |
children | 9bbf4d383381 |
comparison
equal
deleted
inserted
replaced
162:06a98129b23f | 163:80192edca30d |
---|---|
45 let | 45 let |
46 val page_es = List.foldl | 46 val page_es = List.foldl |
47 (fn ((DExport (_, n), _), page_es) => n :: page_es | 47 (fn ((DExport (_, n), _), page_es) => n :: page_es |
48 | (_, page_es) => page_es) [] file | 48 | (_, page_es) => page_es) [] file |
49 | 49 |
50 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, c), edef) | 50 val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, [c]), edef) |
51 | ((DDatatype (_, n, xncs), _), (cdef, edef)) => | |
52 (IM.insert (cdef, n, List.mapPartial #3 xncs), edef) | |
51 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e))) | 53 | ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e))) |
52 | ((DValRec vis, _), (cdef, edef)) => | 54 | ((DValRec vis, _), (cdef, edef)) => |
53 (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis) | 55 (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis) |
54 | ((DExport _, _), acc) => acc) | 56 | ((DExport _, _), acc) => acc) |
55 (IM.empty, IM.empty) file | 57 (IM.empty, IM.empty) file |
66 val s' = {con = IS.add (#con s, n), | 68 val s' = {con = IS.add (#con s, n), |
67 exp = #exp s} | 69 exp = #exp s} |
68 in | 70 in |
69 case IM.find (cdef, n) of | 71 case IM.find (cdef, n) of |
70 NONE => s' | 72 NONE => s' |
71 | SOME c => shakeCon s' c | 73 | SOME cs => foldl (fn (c, s') => shakeCon s' c) s' cs |
72 end | 74 end |
73 | _ => s | 75 | _ => s |
74 | 76 |
75 and shakeCon s = U.Con.fold {kind = kind, con = con} s | 77 and shakeCon s = U.Con.fold {kind = kind, con = con} s |
76 | 78 |
98 case IM.find (edef, n) of | 100 case IM.find (edef, n) of |
99 NONE => raise Fail "Shake: Couldn't find 'val'" | 101 NONE => raise Fail "Shake: Couldn't find 'val'" |
100 | SOME (t, e) => shakeExp (shakeCon s t) e) s page_es | 102 | SOME (t, e) => shakeExp (shakeCon s t) e) s page_es |
101 in | 103 in |
102 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n) | 104 List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n) |
105 | (DDatatype (_, n, _), _) => IS.member (#con s, n) | |
103 | (DVal (_, n, _, _, _), _) => IS.member (#exp s, n) | 106 | (DVal (_, n, _, _, _), _) => IS.member (#exp s, n) |
104 | (DValRec vis, _) => List.exists (fn (_, n, _, _, _) => IS.member (#exp s, n)) vis | 107 | (DValRec vis, _) => List.exists (fn (_, n, _, _, _) => IS.member (#exp s, n)) vis |
105 | (DExport _, _) => true) file | 108 | (DExport _, _) => true) file |
106 end | 109 end |
107 | 110 |