X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_semant.ml;h=5d5d71b2c026f567669ef47c409a86453614cbab;hb=4c550cd5b9653add413e21d06c73efe3aa657e06;hp=40407eff5856a0933c084a9229b8a80b688ff5f3;hpb=978cb41cc2a1b976d0e51e52ef76b173f1fba78f;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_semant.ml b/compiler/src/lib/tiger/tiger_semant.ml index 40407ef..5d5d71b 100644 --- a/compiler/src/lib/tiger/tiger_semant.ml +++ b/compiler/src/lib/tiger/tiger_semant.ml @@ -79,8 +79,25 @@ end = struct ) | A.OpExp {oper; left; right; pos} -> trop oper ~left ~right ~pos - | A.RecordExp {fields=_; typ=_; pos=_} -> - unimplemented () + | A.RecordExp {fields=field_exps; typ; pos} -> + let ty = env_get_typ ~sym:typ ~env ~pos in + Type.if_record + ty + ~f:(fun field_tys -> + List.iter field_exps ~f:(fun (field, exp, pos) -> + (match List.assoc_opt field field_tys with + | Some field_ty -> + check_same {exp=(); ty=field_ty} (trexp exp) ~pos + | None -> + E.raise + (E.No_such_field_in_record {field; record=ty; pos}) + ) + ) + ) + ~otherwise:(fun () -> + 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: *) @@ -118,8 +135,18 @@ end = struct return_unit | A.LetExp {decs=_; body=_; _} -> unimplemented () - | A.ArrayExp {typ=_; size=_; init=_; _} -> - unimplemented () + | A.ArrayExp {typ; size; init; pos} -> + check_int (trexp size) ~pos; + let ty = env_get_typ ~sym:typ ~env ~pos in + Type.if_array + ty + ~f:(fun ty_elements -> + check_same {exp=(); ty=ty_elements} (trexp init) ~pos + ) + ~otherwise:(fun () -> + E.raise (E.Wrong_type_used_as_array {ty_id=typ; ty; pos}) + ); + return ty | A.VarExp var -> trvar var )