Skip to content

Commit

Permalink
rename types and functions (letrec -> let_rec)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfngfn committed Sep 15, 2024
1 parent 2df5d20 commit 5a203a8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/frontend/bytecomp/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ and compile_code_pattern_branch (irpatbr : ir_pattern_branch) : (instruction lis
IRPatternBranchWhen(irpat, compiled, compiled1)


and compile_code_letrec_binding (IRLetRecBinding(var, irpatbr) : ir_letrec_binding) : (instruction list) ir_letrec_binding_scheme =
and compile_code_let_rec_binding (IRLetRecBinding(var, irpatbr) : ir_let_rec_binding) : (instruction list) ir_let_rec_binding_scheme =
let comppatbr = compile_code_pattern_branch irpatbr in
IRLetRecBinding(var, comppatbr)

Expand Down Expand Up @@ -274,7 +274,7 @@ and compile (ir : ir) (cont : instruction list) =

| IRCodeLetRecIn(irrecbinds, ir2) ->
let instrs2 = compile ir2 [] in
OpCodeLetRec(List.map compile_code_letrec_binding irrecbinds, instrs2) :: cont
OpCodeLetRec(List.map compile_code_let_rec_binding irrecbinds, instrs2) :: cont

| IRCodeLetNonRecIn(irpat, ir1, ir2) ->
let instrs1 = compile ir1 [] in
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/bytecomp/ir.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ and find_in_environment (env : frame) (evid : EvalVarID.t) : varloc option =
| None -> None


and add_letrec_bindings_to_environment (env : frame) (recbinds : letrec_binding list) : (varloc * pattern_branch) list * frame =
and add_let_rec_bindings_to_environment (env : frame) (recbinds : let_rec_binding list) : (varloc * pattern_branch) list * frame =
recbinds @|> env @|> map_with_env (fun env recbind ->
let LetRecBinding(evid, patbr) = recbind in
let (var, env) = add_to_environment env evid in
Expand Down Expand Up @@ -628,7 +628,7 @@ and transform_0 (env : frame) (ast : abstract_tree) : ir * frame =
end

| LetRecIn(recbinds, ast2) ->
let (pairs, env) = add_letrec_bindings_to_environment env recbinds in
let (pairs, env) = add_let_rec_bindings_to_environment env recbinds in
let varir_lst =
pairs |> List.map (fun pair ->
let (var, patbr) = pair in
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/evaluator.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ and interpret_0 (env : environment) (ast : abstract_tree) : syntactic_value =
end

| LetRecIn(recbinds, ast2) ->
let env = add_letrec_bindings_to_environment env recbinds in
let env = add_let_rec_bindings_to_environment env recbinds in
interpret_0 env ast2

| LetNonRecIn(pat, ast1, ast2) ->
Expand Down Expand Up @@ -532,7 +532,7 @@ and interpret_1 (env : environment) (ast : abstract_tree) : code_value =
end

| LetRecIn(recbinds, ast2) ->
let (env, cdrecbinds) = interpret_letrec_bindings_1 env recbinds in
let (env, cdrecbinds) = interpret_let_rec_bindings_1 env recbinds in
let code2 = interpret_1 env ast2 in
CdLetRecIn(cdrecbinds, code2)

Expand Down Expand Up @@ -1194,7 +1194,7 @@ and check_pattern_matching (env : environment) (pat : pattern_tree) (value_obj :
None


and add_letrec_bindings_to_environment (env : environment) (recbinds : letrec_binding list) : environment =
and add_let_rec_bindings_to_environment (env : environment) (recbinds : let_rec_binding list) : environment =
let tris =
recbinds |> List.map (function LetRecBinding(evid, patbr) ->
let loc = ref Nil in
Expand All @@ -1212,7 +1212,7 @@ and add_letrec_bindings_to_environment (env : environment) (recbinds : letrec_bi
env


and interpret_letrec_bindings_1 (env : environment) (recbinds : letrec_binding list) : environment * code_letrec_binding list =
and interpret_let_rec_bindings_1 (env : environment) (recbinds : let_rec_binding list) : environment * code_let_rec_binding list =
(* Generate the symbols for the identifiers and add them to the environment: *)
let (env, zippedacc) =
recbinds |> List.fold_left (fun (env, zippedacc) recbind ->
Expand Down Expand Up @@ -1245,7 +1245,7 @@ let interpret_bindings_0 ~(run_tests : bool) (env : environment) (binds : bindin
add_to_environment env evid (ref value)

| Rec(recbinds) ->
add_letrec_bindings_to_environment env recbinds
add_let_rec_bindings_to_environment env recbinds

| Mutable(evid, ast_ini) ->
let value_ini = interpret_0 env ast_ini in
Expand All @@ -1263,7 +1263,7 @@ let interpret_bindings_0 ~(run_tests : bool) (env : environment) (binds : bindin
(env, CdNonRec(symb, code))

| Rec(recbinds) ->
let (env, cdrecbinds) = interpret_letrec_bindings_1 env recbinds in
let (env, cdrecbinds) = interpret_let_rec_bindings_1 env recbinds in
(env, CdRec(cdrecbinds))

| Mutable(evid, ast) ->
Expand Down
10 changes: 7 additions & 3 deletions src/frontend/moduleTypechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ and typecheck_binding (config : typecheck_config) (tyenv : Typeenv.t) (utbind :
let ty_cod = (Range.dummy "test-cod", BaseType(UnitType)) in
Poly(Range.dummy "test-func", FuncType(RowEmpty, ty_dom, ty_cod))
in
let* (test_name, pty1, evid, e1) = Typechecker.typecheck_nonrec ~always_polymorphic:true pre tyenv utletbind in
let* (test_name, pty1, evid, e1) =
Typechecker.typecheck_let_nonrec ~always_polymorphic:true pre tyenv utletbind
in
if TypeConv.poly_type_equal pty_expected pty1 then
return ([ BindTest(evid, test_name, e1) ], (OpaqueIDMap.empty, StructSig.empty))
else
Expand All @@ -731,7 +733,9 @@ and typecheck_binding (config : typecheck_config) (tyenv : Typeenv.t) (utbind :
let* (rec_or_nonrecs, ssig) =
match valbind with
| UTNonRec(utletbind) ->
let* (varnm, pty1, evid, e1) = Typechecker.typecheck_nonrec ~always_polymorphic:true pre tyenv utletbind in
let* (varnm, pty1, evid, e1) =
Typechecker.typecheck_let_nonrec ~always_polymorphic:true pre tyenv utletbind
in
let ssig =
let ventry =
{
Expand All @@ -745,7 +749,7 @@ and typecheck_binding (config : typecheck_config) (tyenv : Typeenv.t) (utbind :
return ([ NonRec(evid, e1) ], ssig)

| UTRec(utrecbinds) ->
let* quints = Typechecker.typecheck_letrec pre tyenv utrecbinds in
let* quints = Typechecker.typecheck_let_rec pre tyenv utrecbinds in
let (recbindacc, ssig) =
quints |> List.fold_left (fun (recbindacc, ssig) quint ->
let (x, pty, evid, recbind) = quint in
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ let rec typecheck (pre : pre) (tyenv : Typeenv.t) ((rng, utastmain) : untyped_ab
begin
match valbind with
| UTNonRec(utletbind) ->
let* (varnm, pty1, evid, e1) = typecheck_nonrec ~always_polymorphic:false pre tyenv utletbind in
let* (varnm, pty1, evid, e1) = typecheck_let_nonrec ~always_polymorphic:false pre tyenv utletbind in
let tyenv =
let ventry =
{
Expand All @@ -666,7 +666,7 @@ let rec typecheck (pre : pre) (tyenv : Typeenv.t) ((rng, utastmain) : untyped_ab
return (LetNonRecIn(PVariable(evid), e1, e2), ty2)

| UTRec(utrecbinds) ->
let* quints = typecheck_letrec pre tyenv utrecbinds in
let* quints = typecheck_let_rec pre tyenv utrecbinds in
let (tyenv, recbindacc) =
quints |> List.fold_left (fun (tyenv, recbindacc) quint ->
let (x, pty, evid, recbind) = quint in
Expand Down Expand Up @@ -1152,7 +1152,7 @@ and typecheck_pattern_branch_list (pre : pre) (tyenv : Typeenv.t) (utpatbrs : un
)


and typecheck_letrec (pre : pre) (tyenv : Typeenv.t) (utrecbinds : untyped_let_binding list) : ((var_name * poly_type * EvalVarID.t * letrec_binding) list) ok =
and typecheck_let_rec (pre : pre) (tyenv : Typeenv.t) (utrecbinds : untyped_let_binding list) : ((var_name * poly_type * EvalVarID.t * let_rec_binding) list) ok =
let open ResultMonad in

(* First, adds a type variable for each bound identifier. *)
Expand Down Expand Up @@ -1240,7 +1240,7 @@ and typecheck_letrec (pre : pre) (tyenv : Typeenv.t) (utrecbinds : untyped_let_b
return tuples


and typecheck_nonrec ~(always_polymorphic : bool) (pre : pre) (tyenv : Typeenv.t) (utletbind : untyped_let_binding) : (var_name * poly_type * EvalVarID.t * abstract_tree) ok =
and typecheck_let_nonrec ~(always_polymorphic : bool) (pre : pre) (tyenv : Typeenv.t) (utletbind : untyped_let_binding) : (var_name * poly_type * EvalVarID.t * abstract_tree) ok =
let open ResultMonad in
let
UTLetBinding{
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/typechecker.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ open TypeError

val typecheck : pre -> type_environment -> untyped_abstract_tree -> (abstract_tree * mono_type, type_error) result

val typecheck_letrec : pre -> type_environment -> untyped_let_binding list -> ((var_name * poly_type * EvalVarID.t * letrec_binding) list, type_error) result
val typecheck_let_rec : pre -> type_environment -> untyped_let_binding list -> ((var_name * poly_type * EvalVarID.t * let_rec_binding) list, type_error) result

val typecheck_nonrec : always_polymorphic:bool -> pre -> type_environment -> untyped_let_binding -> (var_name * poly_type * EvalVarID.t * abstract_tree, type_error) result
val typecheck_let_nonrec : always_polymorphic:bool -> pre -> type_environment -> untyped_let_binding -> (var_name * poly_type * EvalVarID.t * abstract_tree, type_error) result

val typecheck_let_mutable : pre -> type_environment -> var_name ranged -> untyped_abstract_tree -> (var_name * poly_type * EvalVarID.t * abstract_tree, type_error) result

Expand Down
34 changes: 17 additions & 17 deletions src/frontend/types.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ type untyped_envelope =
}
[@@deriving show { with_path = false }]

type untyped_letrec_pattern_branch =
type untyped_let_rec_pattern_branch =
| UTLetRecPatternBranch of untyped_pattern_tree list * untyped_abstract_tree

type 'a inline_text_element_scheme =
Expand Down Expand Up @@ -726,14 +726,14 @@ type base_constant =
[@printer (fun fmt _ -> Format.fprintf fmt "<unidata>")]
[@@deriving show { with_path = false; }]

type 'a letrec_binding_scheme =
type 'a let_rec_binding_scheme =
| LetRecBinding of EvalVarID.t * 'a pattern_branch_scheme

and letrec_binding =
abstract_tree letrec_binding_scheme
and let_rec_binding =
abstract_tree let_rec_binding_scheme

and rec_or_nonrec =
| Rec of letrec_binding list
| Rec of let_rec_binding list
| NonRec of EvalVarID.t * abstract_tree
| Mutable of EvalVarID.t * abstract_tree

Expand Down Expand Up @@ -843,18 +843,18 @@ and ir =
| IRCodeBlockText of (ir block_text_element_scheme) list
| IRCodeMathText of (ir math_text_element_scheme) list
| IRCodePatternMatch of Range.t * ir * ir_pattern_branch list
| IRCodeLetRecIn of ir_letrec_binding list * ir
| IRCodeLetRecIn of ir_let_rec_binding list * ir
| IRCodeLetNonRecIn of ir_pattern_tree * ir * ir
| IRCodeFunction of varloc LabelMap.t * ir_pattern_tree * ir
| IRCodeLetMutableIn of varloc * ir * ir
| IRCodeOverwrite of varloc * ir
| IRLift of ir

and 'a ir_letrec_binding_scheme =
and 'a ir_let_rec_binding_scheme =
| IRLetRecBinding of varloc * 'a ir_pattern_branch_scheme

and ir_letrec_binding =
ir ir_letrec_binding_scheme
and ir_let_rec_binding =
ir ir_let_rec_binding_scheme

and 'a ir_pattern_branch_scheme =
| IRPatternBranch of ir_pattern_tree * 'a
Expand Down Expand Up @@ -939,7 +939,7 @@ and instruction =
| OpCodeMakeInlineText of ((instruction list) inline_text_element_scheme) list
| OpCodeMakeBlockText of ((instruction list) block_text_element_scheme) list
| OpCodePatternMatch of Range.t * ((instruction list) ir_pattern_branch_scheme) list
| OpCodeLetRec of ((instruction list) ir_letrec_binding_scheme) list * instruction list
| OpCodeLetRec of ((instruction list) ir_let_rec_binding_scheme) list * instruction list
| OpCodeLetNonRec of ir_pattern_tree * instruction list * instruction list
| OpCodeFunction of varloc LabelMap.t * ir_pattern_tree * instruction list
| OpCodeLetMutable of varloc * instruction list * instruction list
Expand Down Expand Up @@ -1047,7 +1047,7 @@ and abstract_tree =
| UpdateField of abstract_tree * label * abstract_tree
(* Fundamentals: *)
| ASTBaseConstant of base_constant
| LetRecIn of letrec_binding list * abstract_tree
| LetRecIn of let_rec_binding list * abstract_tree
| LetNonRecIn of pattern_tree * abstract_tree * abstract_tree
| ContentOf of Range.t * EvalVarID.t
| IfThenElse of abstract_tree * abstract_tree * abstract_tree
Expand Down Expand Up @@ -1239,7 +1239,7 @@ and code_value =
| CdLambdaBlock of CodeSymbol.t * code_value
| CdLambdaMath of CodeSymbol.t * (CodeSymbol.t * CodeSymbol.t) option * code_value
| CdContentOf of Range.t * CodeSymbol.t
| CdLetRecIn of code_letrec_binding list * code_value
| CdLetRecIn of code_let_rec_binding list * code_value
| CdLetNonRecIn of code_pattern_tree * code_value * code_value
| CdFunction of CodeSymbol.t LabelMap.t * code_pattern_branch
| CdApply of code_value LabelMap.t * code_value * code_value
Expand Down Expand Up @@ -1281,7 +1281,7 @@ and code_math_text_element =
and 'a code_path_component =
('a, code_value) path_component_scheme

and code_letrec_binding =
and code_let_rec_binding =
| CdLetRecBinding of CodeSymbol.t * code_pattern_branch

and code_pattern_branch =
Expand All @@ -1303,7 +1303,7 @@ and code_pattern_tree =
[@@deriving show { with_path = false; }]

type code_rec_or_nonrec =
| CdRec of code_letrec_binding list
| CdRec of code_let_rec_binding list
| CdNonRec of CodeSymbol.t * code_value
| CdMutable of CodeSymbol.t * code_value

Expand Down Expand Up @@ -1486,7 +1486,7 @@ let rec unlift_code (code : code_value) : abstract_tree =
LambdaMath(CodeSymbol.unlift symb_ctx, evid_pair_opt, aux code0)

| CdContentOf(rng, symb) -> ContentOf(rng, CodeSymbol.unlift symb)
| CdLetRecIn(cdrecbinds, code1) -> LetRecIn(List.map unlift_letrec_binding cdrecbinds, aux code1)
| CdLetRecIn(cdrecbinds, code1) -> LetRecIn(List.map unlift_let_rec_binding cdrecbinds, aux code1)
| CdLetNonRecIn(cdpat, code1, code2) -> LetNonRecIn(unlift_pattern cdpat, aux code1, aux code2)
| CdFunction(symb_labmap, cdpatbr) -> Function(symb_labmap |> LabelMap.map CodeSymbol.unlift, unlift_pattern_branch cdpatbr)
| CdApply(code_labmap, code1, code2) -> Apply(code_labmap |> LabelMap.map aux, aux code1, aux code2)
Expand Down Expand Up @@ -1557,7 +1557,7 @@ and unlift_pattern = function
| CdPConstructor(ctor, cdpat) -> PConstructor(ctor, unlift_pattern cdpat)


and unlift_letrec_binding (CdLetRecBinding(symb, cdpatbr)) =
and unlift_let_rec_binding (CdLetRecBinding(symb, cdpatbr)) =
LetRecBinding(CodeSymbol.unlift symb, unlift_pattern_branch cdpatbr)


Expand All @@ -1569,7 +1569,7 @@ and unlift_pattern_branch = function
let unlift_rec_or_nonrec (cd_rec_or_nonrec : code_rec_or_nonrec) : rec_or_nonrec =
match cd_rec_or_nonrec with
| CdNonRec(symb, code) -> NonRec(CodeSymbol.unlift symb, unlift_code code)
| CdRec(cdrecbinds) -> Rec(List.map unlift_letrec_binding cdrecbinds)
| CdRec(cdrecbinds) -> Rec(List.map unlift_let_rec_binding cdrecbinds)
| CdMutable(symb, code) -> Mutable(CodeSymbol.unlift symb, unlift_code code)


Expand Down

0 comments on commit 5a203a8

Please sign in to comment.