X-Git-Url: https://git.xandkar.net/?p=tiger.ml.git;a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_semant.ml;fp=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_semant.ml;h=19e8c8b661b5e719b8fcba3d06b2f6cca7ae48ef;hp=6bb45fd515a5fb3fe1788417118c5b4b2c144b5a;hb=35dccbd3999a8c3bb1dc9e96e21b69a39f44fc6f;hpb=e6e82c0866db4eb08f956b2582e5c2ed5399e986 diff --git a/compiler/src/lib/tiger/tiger_semant.ml b/compiler/src/lib/tiger/tiger_semant.ml index 6bb45fd..19e8c8b 100644 --- a/compiler/src/lib/tiger/tiger_semant.ml +++ b/compiler/src/lib/tiger/tiger_semant.ml @@ -192,16 +192,25 @@ end = struct | A.WhileExp {test; body; pos} -> (* test : must be int, because we have no bool *) check_int (trexp test) ~pos; - ignore (trexp body); (* Only care if a type-error is raised *) + let (loop, env) = Env.loop_begin env in + (* Only care if an error is raised *) + ignore (transExp ~env body); + ignore (Env.loop_end env loop); return_unit | A.ForExp {var; lo; hi; body; pos; escape=_} -> check_int (trexp lo) ~pos; check_int (trexp hi) ~pos; - (* Only care if a type-error is raised *) + let (loop, env) = Env.loop_begin env in let env = Env.set_val env var (Value.Var {ty = Type.Int}) in + (* Only care if an error is raised *) ignore (transExp ~env body); + ignore (Env.loop_end env loop); return_unit - | A.BreakExp _ -> + | A.BreakExp pos -> + (match Env.loop_current env with + | Some _ -> () + | None -> E.raise (E.Break_outside_loop pos) + ); return_unit | A.LetExp {decs; body; pos=_} -> (* (1) decs augment env *)