Skip to content

Commit

Permalink
maybe deal with duplicate var declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 17, 2024
1 parent 28ecf77 commit e63ca36
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,19 @@ module HxbWriter = struct

and write_texpr writer (fctx : field_writer_context) (e : texpr) =
let declare_var v =
let index = DynArray.length fctx.vars in
DynArray.add fctx.vars (v,v.v_id);
(* Store local index in v_id so we find it easily for all the TLocal expressions.
This is set back by the var writer in start_texpr. *)
v.v_id <- index;
let index = if v.v_id < 0 then begin
(* Duplicate var declaration! Can happen when writing both cf_expr and cf_expr_unoptimized,
although it arguably shouldn't. In this case we don't add the var again and instead write
out the existing ID.*)
-v.v_id
end else begin
let index = DynArray.length fctx.vars in
DynArray.add fctx.vars (v,v.v_id);
(* Store local index in v_id so we find it easily for all the TLocal expressions.
This is set back by the var writer in start_texpr. *)
v.v_id <- -index;
index;
end in
Chunk.write_uleb128 writer.chunk index;
Chunk.write_option writer.chunk v.v_extra (fun ve ->
Chunk.write_list writer.chunk ve.v_params (fun ttp ->
Expand Down Expand Up @@ -1314,7 +1322,7 @@ module HxbWriter = struct
(* vars 20-29 *)
| TLocal v ->
Chunk.write_u8 writer.chunk 20;
Chunk.write_uleb128 writer.chunk v.v_id;
Chunk.write_uleb128 writer.chunk (-v.v_id);
| TVar(v,None) ->
Chunk.write_u8 writer.chunk 21;
declare_var v;
Expand Down

1 comment on commit e63ca36

@Simn
Copy link
Member Author

@Simn Simn commented on e63ca36 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That didn't help... and I have to go now. Will probably revert this, too messy.

Please sign in to comment.