Skip to content

Commit

Permalink
More informative names for the constructors of Compiler.Symbols.entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedrot committed Jul 25, 2024
1 parent 17a4555 commit f6e85a7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ type table = {
} [@@deriving show]

type entry =
| ENeg of D.constant * string
| EPos of D.constant * D.term
| GlobalSymbol of D.constant * string
| BoundVariable of D.constant * D.term
[@@deriving show]

type pruned_table = entry array [@@deriving show]
Expand All @@ -122,17 +122,17 @@ let size t = Array.length t

let symbols table =
let map = function
| ENeg (c, s) -> Some (s ^ ":" ^ string_of_int c)
| EPos _ -> None
| GlobalSymbol (c, s) -> Some (s ^ ":" ^ string_of_int c)
| BoundVariable _ -> None
in
List.rev @@ List.filter_map map @@ Array.to_list table

let prune t ~alive =
let c2s = t.c2s in
let c2t0 = D.Constants.Map.filter (fun k _ -> D.Constants.Set.mem k alive) t.c2t in
let map k t =
if k < 0 then ENeg (k, D.Constants.Map.find k c2s)
else EPos (k, t)
if k < 0 then GlobalSymbol (k, D.Constants.Map.find k c2s)
else BoundVariable (k, t)
in
let c2t0 = D.Constants.Map.mapi map c2t0 in
Array.of_list @@ List.rev_map snd @@ D.Constants.Map.bindings c2t0
Expand Down Expand Up @@ -259,7 +259,7 @@ let build_shift ?(lock_base=false) ~flags:{ print_units } ~base symbols =
heuristic in unfolding) *)
Array.fold_left (fun (base,shift as acc) e ->
match e with
| ENeg (v, name) ->
| GlobalSymbol (v, name) ->
begin try
let c, _ = F.Map.find (F.from_string name) base.ast2ct in
if c == v then acc
Expand All @@ -273,7 +273,7 @@ let build_shift ?(lock_base=false) ~flags:{ print_units } ~base symbols =
let base, (c,_) = allocate_global_symbol_aux (Ast.Func.from_string name) base in
base, Map.add v c shift
end
| EPos (v, t) ->
| BoundVariable (v, t) ->
if Map.mem v base.c2t then acc
else
let base = { base with c2t = Map.add v t base.c2t } in
Expand Down

0 comments on commit f6e85a7

Please sign in to comment.