Jelajahi Sumber

revert local changes

Simon Krajewski 1 tahun lalu
induk
melakukan
1c0c9362ff
1 mengubah file dengan 9 tambahan dan 21 penghapusan
  1. 9 21
      src/compiler/hxb/hxbWriter.ml

+ 9 - 21
src/compiler/hxb/hxbWriter.ml

@@ -456,14 +456,14 @@ type field_writer_context = {
 	t_pool : StringPool.t;
 	pos_writer : PosWriter.t;
 	mutable texpr_this : texpr option;
-	vars : (tvar * int) DynArray.t;
+	vars : (int,tvar) pool;
 }
 
 let create_field_writer_context pos_writer = {
 	t_pool = StringPool.create ();
 	pos_writer = pos_writer;
 	texpr_this = None;
-	vars = DynArray.create ();
+	vars = new pool;
 }
 
 type hxb_writer = {
@@ -1266,20 +1266,7 @@ module HxbWriter = struct
 
 	and write_texpr writer (fctx : field_writer_context) (e : texpr) =
 		let declare_var v =
-			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_uleb128 writer.chunk (fctx.vars#add v.v_id v);
 			Chunk.write_option writer.chunk v.v_extra (fun ve ->
 				Chunk.write_list writer.chunk ve.v_params (fun ttp ->
 					let index = writer.local_type_parameters#add ttp () in
@@ -1322,7 +1309,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 (fctx.vars#get v.v_id)
 			| TVar(v,None) ->
 				Chunk.write_u8 writer.chunk 21;
 				declare_var v;
@@ -1670,11 +1657,12 @@ module HxbWriter = struct
 				List.iter (fun bytes ->
 					Chunk.write_bytes writer.chunk (Bytes.unsafe_of_string bytes)
 				) items;
-				Chunk.write_uleb128 writer.chunk (DynArray.length fctx.vars);
-				DynArray.iter (fun (v,v_id) ->
-					v.v_id <- v_id;
+
+				let items = fctx.vars#items in
+				Chunk.write_uleb128 writer.chunk (DynArray.length items);
+				DynArray.iter (fun v ->
 					write_var writer fctx v;
-				) fctx.vars;
+				) items;
 				Chunk.export_data new_chunk writer.chunk;
 				restore(fun new_chunk -> new_chunk)
 			)