Commit 0ecf0d21 authored by Axel Simon's avatar Axel Simon
Browse files

fixes in pushNested and popNested

parent 9edac840
......@@ -282,12 +282,12 @@ fun typeInferencePass (errStrm, ti : TI.type_info, ast) = let
fun checkUsage sym s =
let
val fid = E.getContextOfUsage (sym, s, env)
val env = E.enterFunction (fid,env)
val (n1,env) = E.pushNested (sym, env)
val (n2,env) = E.pushNested (fid, env)
val _ = TextIO.print ("subset, about to push " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ "\n")
val _ = TextIO.print ("subset, in context of " ^ SymbolTable.getString(!SymbolTables.varTable, fid) ^ ":\n" ^ E.toString env ^ "\n")
val (n,envFun) = E.pushSymbolNested (sym, s, env)
val env = E.popKappa envFun
val envFun = E.pushSymbol (sym, s, false, env)
val _ = TextIO.print ("pushed instance " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ " symbol:\n" ^ E.topToString envFun)
val envCall = E.pushUsage (sym, s, env)
val _ = TextIO.print ("pushed usage:\n" ^ E.topToString envCall)
......@@ -347,15 +347,13 @@ fun typeInferencePass (errStrm, ti : TI.type_info, ast) = let
fun checkUsage (s, env) =
let
val fid = E.getContextOfUsage (sym, s, env)
val env = E.enterFunction (fid,env)
val (n1,env) = E.pushNested (sym, env)
val (n2,env) = E.pushNested (fid, env)
val (n,envFun) = E.pushSymbolNested (sym, s, env)
val env = E.popKappa envFun
(*val _ = if SymbolTable.toInt sym = 95 then TextIO.print ("pushed instance " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ " symbol:\n" ^ E.kappaToString envFun)
else ()*)
val envFun = E.pushSymbol (sym, s, false, env)
val _ = TextIO.print ("pushed instance " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ " symbol:\n" ^ E.kappaToString envFun)
val envCall = E.pushUsage (sym, s, env)
(*val _ = if SymbolTable.toInt sym = 95 then TextIO.print ("pushed usage:\n" ^ E.kappaToString envCall)
else ()*)
val _ = TextIO.print ("pushed usage:\n" ^ E.kappaToString envCall)
(*inform about a unification failure when checking call site
with definition*)
fun raiseError str =
......@@ -373,15 +371,14 @@ fun typeInferencePass (errStrm, ti : TI.type_info, ast) = let
val env = E.meetFlow (envCall, envFun)
handle (S.UnificationFailure str) =>
(raiseError str; envFun)
(*val _ = TextIO.print ("popping to usage of " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ ":\n" ^ E.topToString env)*)
val env = E.popToUsage (sym, s, env)
val env = E.return (n,env)
val env = E.leaveFunction (fid,env)
val _ = TextIO.print ("popping to usage of " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ ":\n" ^ E.toString env)
val env = E.popNested (n1+n2,env)
in
env
end
val usages = E.getUsages (sym, env)
(*val _ = TextIO.print ("***** re-eval of " ^ Int.toString (List.length usages) ^ " usages of " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ "\n")*)
val _ = TextIO.print ("***** re-eval of " ^ Int.toString (List.length usages) ^ " usages of " ^ SymbolTable.getString(!SymbolTables.varTable, sym) ^ "\n")
in
List.foldl checkUsage env usages
end
......
......@@ -50,11 +50,14 @@ structure Environment : sig
existing type should be used (False) *)
val pushSymbol : VarInfo.symid * Error.span * bool * environment -> environment
(*like pushSymbol, but also checks nested definitions that have already
been type checked, a usage is never recorded; returns the number of
frames that have been pushed before the symbol was pushed*)
val pushSymbolNested : VarInfo.symid * Error.span * environment ->
(int * environment)
(*in case the given symbol is not in the top-most group, search in the
nested definitions of the current function for definitions of the symbol
and push them onto the stack, returns the new stack and the number of
nested groups that had to be pushed*)
val pushNested : VarInfo.symid * environment -> (int * environment)
(*pops the nested groups that were pushed by pushNested*)
val popNested : int * environment -> environment
val getUsages : VarInfo.symid * environment -> Error.span list
......@@ -98,7 +101,7 @@ structure Environment : sig
determines in which function calls to unknown functions are recorded)*)
val enterFunction : VarInfo.symid * environment -> environment
(*pop the name of the given function from the current context*)
(*pop the last function from the current context*)
val leaveFunction : VarInfo.symid * environment -> environment
(*unset the type of function f, if the function type was set, return an
......@@ -910,37 +913,6 @@ end = struct
)
)
fun pushSymbolNested (sym, span, env as (scs, state)) =
case Scope.getCtxt state of
[] => (0,pushSymbol (sym, span, false, env))
| (curFun :: _) =>
let
val nested = case Scope.lookup (curFun, env) of
(_, COMPOUND {ty, width, uses, nested}) => nested
| _ => raise InferenceBug
val _ = TextIO.print ("checking " ^ Int.toString (List.length nested) ^ " nested groups\n")
fun findSymInGroups (n, ns, env) =
List.foldl
(fn (g,res) => case res of
SOME r => SOME r
| NONE => findSymInGroup (n+1,g,Scope.wrap (g, env)))
NONE ns
and findSymInGroup (n,GROUP bs,env) =
if List.exists (fn {name, ty, width, uses, nested} =>
SymbolTable.eq_symid (sym,name)) bs
then SOME
(n, pushSymbol (sym, span, false, env))
else List.foldl (fn (b,res) => case res of
SOME r => SOME r
| NONE => findSymInGroups (n, #nested b, env)
) NONE bs
| findSymInGroup (n,_,env) = raise InferenceBug
in
case findSymInGroups (0, nested, env) of
NONE => (0,pushSymbol (sym, span, false, env))
| SOME r => r
end
fun getUsages (sym, env) = (case Scope.lookup (sym, env) of
(_, SIMPLE {ty}) => []
| (_, COMPOUND {ty, width, uses = us, nested}) => SpanMap.listKeys us
......@@ -1314,6 +1286,63 @@ in () end;*)
else raise InferenceBug
| [] => raise InferenceBug
fun inScope (sym,([],_)) = false
| inScope (sym,env) = case Scope.unwrap env of
(GROUP bs,env) =>
if List.exists (fn {name, ty, width, uses, nested} =>
SymbolTable.eq_symid (sym,name)) bs then true
else inScope (sym,env)
| (_,env) => inScope (sym,env)
fun pushNested (sym, env) = if inScope (sym,env) then (0,env) else
let
val (sc,_) = Scope.unwrap env
fun findSymInGroups (n, ns, env) =
List.foldl
(fn (g,res) => case res of
SOME r => SOME r
| NONE => findSymInGroup (n+1,g,Scope.wrap (g, env))
) NONE ns
and findSymInGroup (n,GROUP bs,env) =
(case List.find (fn {name, ty, width, uses, nested} =>
SymbolTable.eq_symid (sym,name)) bs of
SOME {name, ty, width, uses, nested} =>
SOME (n, enterFunction (name,env))
| NONE =>
List.foldl (fn ({name, ty, width, uses, nested=ns},res) =>
case res of
SOME r => SOME r
| NONE => findSymInGroups (n, ns, enterFunction (name,env))
) NONE bs
)
| findSymInGroup (n,_,env) = raise InferenceBug
in
case findSymInGroup (0, sc, env) of
NONE => (0,env)
| SOME r => r
end
fun popNested (n, env) =
(TextIO.print ("popping further " ^ Int.toString n ^ " scopes:\n" ^ topToString env);
if n<=0 then env else case Scope.unwrap env of
(GROUP bs, (scs,state)) =>
let
val (curFun, remFuns) = case Scope.getCtxt state of
(curFun :: remFuns) => (curFun, remFuns)
| _ => raise InferenceBug
val state = Scope.setCtxt remFuns state
fun action (COMPOUND {ty, width, uses, nested},cons) =
(COMPOUND {ty = ty, width = width,
uses = uses, nested = (GROUP bs) :: nested}, cons)
| action _ = raise InferenceBug
val env = Scope.update (curFun, action, (scs,state))
in
popNested (n-1,env)
end
| (_, env) => raise InferenceBug
)
fun clearFunction (sym, env) =
let
val tOptRef = ref (NONE : (texp * BD.bfun) option)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment