X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_semant.ml;h=70639e93704d54d47d2f287a99ff8f66e906a1ef;hb=9d8471b2ec67822e00009c05a5b5ce9cba57b317;hp=f653e162997edbf72841a880ec30170bcaacc1a1;hpb=862e5c05ffb0ec1ea8973af0c3c4384f70790ea3;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_semant.ml b/compiler/src/lib/tiger/tiger_semant.ml index f653e16..70639e9 100644 --- a/compiler/src/lib/tiger/tiger_semant.ml +++ b/compiler/src/lib/tiger/tiger_semant.ml @@ -100,12 +100,18 @@ end = struct E.raise (E.Wrong_type_used_as_record {ty_id=typ; ty; pos}) ); return ty - | A.SeqExp exps -> - (* Ignoring value because we only care if a type-checking exception - * is raised in one of trexp calls: *) - List.iter exps ~f:(fun (exp, _) -> ignore (trexp exp)); - (* FIXME: Return type of last expression, not unit. *) + | A.SeqExp [] -> return_unit + | A.SeqExp exps -> + let last xs = + xs + |> List.rev (* Yes, redundant, but clean-looking ;-P *) + |> List.hd (* Empty is matched in above SeqExp match case *) + in + exps + |> List.map ~f:(fun (exp, _) -> let {ty; _} = trexp exp in ty) + |> last + |> return | A.AssignExp {var; exp; pos} -> check_same (trvar var) (trexp exp) ~pos; (* TODO: Add var->exp to val env? *) @@ -132,7 +138,8 @@ end = struct check_int (trexp lo) ~pos; check_int (trexp hi) ~pos; (* Only care if a type-error is raised *) - ignore (transExp ~env:(Env.set_typ env var Type.Int) body); + let env = Env.set_val env var (Value.Var {ty = Type.Int}) in + ignore (transExp ~env body); return_unit | A.BreakExp _ -> return_unit