Mercurial > urweb
changeset 419:cb5897276abf
Fix bug with bringing functor argument instances into scope; Ref demo, minus prose
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 23 Oct 2008 17:35:10 -0400 |
parents | ad7e854a518c |
children | 9119a5920106 |
files | demo/prose demo/ref.ur demo/ref.urp demo/ref.urs demo/refFun.ur demo/refFun.urs src/elab_env.sml |
diffstat | 7 files changed, 144 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/demo/prose Thu Oct 23 14:03:12 2008 -0400 +++ b/demo/prose Thu Oct 23 17:35:10 2008 -0400 @@ -108,3 +108,5 @@ metaform1.urp metaform2.urp + +ref.urp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/ref.ur Thu Oct 23 17:35:10 2008 -0400 @@ -0,0 +1,28 @@ +structure IR = RefFun.Make(struct + type t = int + val inj = _ + end) + +structure SR = RefFun.Make(struct + type t = string + val inj = _ + end) + +fun main () = + ir <- IR.new 3; + ir' <- IR.new 7; + sr <- SR.new "hi"; + + () <- IR.write ir' 10; + + iv <- IR.read ir; + iv' <- IR.read ir'; + sv <- SR.read sr; + + () <- IR.delete ir; + () <- IR.delete ir'; + () <- SR.delete sr; + + return <xml><body> + {[iv]}, {[iv']}, {[sv]} + </body></xml>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/ref.urp Thu Oct 23 17:35:10 2008 -0400 @@ -0,0 +1,4 @@ +database dbname=test + +refFun +ref
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/ref.urs Thu Oct 23 17:35:10 2008 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/refFun.ur Thu Oct 23 17:35:10 2008 -0400 @@ -0,0 +1,27 @@ +functor Make(M : sig + type data + val inj : sql_injectable data + end) = struct + + type ref = int + + sequence s + table t : { Id : int, Data : M.data } + + fun new d = + id <- nextval s; + () <- dml (INSERT INTO t (Id, Data) VALUES ({id}, {d})); + return id + + fun read r = + o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r}); + return (case o of + None => error <xml>You already deleted that ref!</xml> + | Some r => r.T.Data) + + fun write r d = + dml (UPDATE t SET Data = {d} WHERE Id = {r}) + + fun delete r = + dml (DELETE FROM t WHERE Id = {r}) +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/refFun.urs Thu Oct 23 17:35:10 2008 -0400 @@ -0,0 +1,10 @@ +functor Make(M : sig + type data + val inj : sql_injectable data + end) : sig + type ref + val new : M.data -> transaction ref + val read : ref -> transaction M.data + val write : ref -> M.data -> transaction unit + val delete : ref -> transaction unit +end
--- a/src/elab_env.sml Thu Oct 23 14:03:12 2008 -0400 +++ b/src/elab_env.sml Thu Oct 23 17:35:10 2008 -0400 @@ -159,10 +159,11 @@ ground = KM.empty } -fun printClasses cs = CM.appi (fn (cn, {ground = km}) => - (print (cn2s cn ^ ":"); - KM.appi (fn (ck, _) => print (" " ^ ck2s ck)) km; - print "\n")) cs +fun printClasses cs = (print "Classes:\n"; + CM.appi (fn (cn, {ground = km}) => + (print (cn2s cn ^ ":"); + KM.appi (fn (ck, _) => print (" " ^ ck2s ck)) km; + print "\n")) cs) type env = { renameC : kind var' SM.map, @@ -743,34 +744,74 @@ | SgiClassAbs xn => found xn | SgiClass (x, n, _) => found (x, n) - | SgiVal (x, n, (CApp ((CNamed f, _), a), _)) => - (case IM.find (newClasses, f) of - NONE => default () - | SOME fx => - case class_key_in (sgnS_con' (m1, ms, fmap) (#1 a), #2 a) of - NONE => default () - | SOME ck => - let - val cn = ClProj (m1, ms, fx) + | SgiVal (x, n, (CApp (f, a), _)) => + let + fun unravel c = + case #1 c of + CUnif (_, _, _, ref (SOME c)) => unravel c + | CNamed n => + ((case lookupCNamed env n of + (_, _, SOME c) => unravel c + | _ => c) + handle UnboundNamed _ => c) + | _ => c - val classes = - case CM.find (classes, cn) of - NONE => classes - | SOME class => - let - val class = { - ground = KM.insert (#ground class, ck, - (EModProj (m1, ms, x), #2 sgn)) - } - in - CM.insert (classes, cn, class) - end - in - (classes, - newClasses, - fmap, - env) - end) + val nc = + case f of + (CNamed f, _) => IM.find (newClasses, f) + | _ => NONE + in + case nc of + NONE => + (case (class_name_in (unravel f), + class_key_in (sgnS_con' (m1, ms, fmap) (#1 a), #2 a)) of + (SOME cn, SOME ck) => + let + val classes = + case CM.find (classes, cn) of + NONE => classes + | SOME class => + let + val class = { + ground = KM.insert (#ground class, ck, + (EModProj (m1, ms, x), #2 sgn)) + } + in + CM.insert (classes, cn, class) + end + in + (classes, + newClasses, + fmap, + env) + end + | _ => default ()) + | SOME fx => + case class_key_in (sgnS_con' (m1, ms, fmap) (#1 a), #2 a) of + NONE => default () + | SOME ck => + let + val cn = ClProj (m1, ms, fx) + + val classes = + case CM.find (classes, cn) of + NONE => classes + | SOME class => + let + val class = { + ground = KM.insert (#ground class, ck, + (EModProj (m1, ms, x), #2 sgn)) + } + in + CM.insert (classes, cn, class) + end + in + (classes, + newClasses, + fmap, + env) + end + end | SgiVal _ => default () | _ => default () end)