|
@@ -469,6 +469,7 @@ type hxb_writer = {
|
|
mutable local_type_parameters : (typed_type_param,unit) IdentityPool.t;
|
|
mutable local_type_parameters : (typed_type_param,unit) IdentityPool.t;
|
|
mutable field_stack : unit list;
|
|
mutable field_stack : unit list;
|
|
mutable wrote_local_type_param : bool;
|
|
mutable wrote_local_type_param : bool;
|
|
|
|
+ mutable needs_local_context : bool;
|
|
unbound_ttp : (typed_type_param,unit) IdentityPool.t;
|
|
unbound_ttp : (typed_type_param,unit) IdentityPool.t;
|
|
t_instance_chunk : Chunk.t;
|
|
t_instance_chunk : Chunk.t;
|
|
}
|
|
}
|
|
@@ -1006,12 +1007,11 @@ module HxbWriter = struct
|
|
write_pos writer v.v_pos
|
|
write_pos writer v.v_pos
|
|
|
|
|
|
let rec write_anon writer (an : tanon) =
|
|
let rec write_anon writer (an : tanon) =
|
|
- let needs_local_context = ref false in
|
|
|
|
let write_fields () =
|
|
let write_fields () =
|
|
let restore = start_temporary_chunk writer 256 in
|
|
let restore = start_temporary_chunk writer 256 in
|
|
let i = ref 0 in
|
|
let i = ref 0 in
|
|
PMap.iter (fun _ cf ->
|
|
PMap.iter (fun _ cf ->
|
|
- write_anon_field_ref writer needs_local_context cf;
|
|
|
|
|
|
+ write_anon_field_ref writer cf;
|
|
incr i;
|
|
incr i;
|
|
) an.a_fields;
|
|
) an.a_fields;
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
@@ -1035,8 +1035,7 @@ module HxbWriter = struct
|
|
assert false
|
|
assert false
|
|
| AbstractStatics _ ->
|
|
| AbstractStatics _ ->
|
|
assert false
|
|
assert false
|
|
- end;
|
|
|
|
- !needs_local_context
|
|
|
|
|
|
+ end
|
|
|
|
|
|
and write_anon_ref writer (an : tanon) =
|
|
and write_anon_ref writer (an : tanon) =
|
|
let pfm = Option.get (writer.anon_id#identify_anon ~strict:true an) in
|
|
let pfm = Option.get (writer.anon_id#identify_anon ~strict:true an) in
|
|
@@ -1046,9 +1045,10 @@ module HxbWriter = struct
|
|
Chunk.write_uleb128 writer.chunk index
|
|
Chunk.write_uleb128 writer.chunk index
|
|
with Not_found ->
|
|
with Not_found ->
|
|
let restore = start_temporary_chunk writer 256 in
|
|
let restore = start_temporary_chunk writer 256 in
|
|
- let needs_local_context = write_anon writer an in
|
|
|
|
|
|
+ writer.needs_local_context <- false;
|
|
|
|
+ write_anon writer an;
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
- if needs_local_context then begin
|
|
|
|
|
|
+ if writer.needs_local_context then begin
|
|
let index = Pool.add writer.anons pfm.pfm_path None in
|
|
let index = Pool.add writer.anons pfm.pfm_path None in
|
|
Chunk.write_u8 writer.chunk 1;
|
|
Chunk.write_u8 writer.chunk 1;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
@@ -1059,7 +1059,7 @@ module HxbWriter = struct
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
end
|
|
end
|
|
|
|
|
|
- and write_anon_field_ref writer needs_local_context cf =
|
|
|
|
|
|
+ and write_anon_field_ref writer cf =
|
|
try
|
|
try
|
|
let index = HashedIdentityPool.get writer.anon_fields cf.cf_name cf in
|
|
let index = HashedIdentityPool.get writer.anon_fields cf.cf_name cf in
|
|
Chunk.write_u8 writer.chunk 0;
|
|
Chunk.write_u8 writer.chunk 0;
|
|
@@ -1067,15 +1067,14 @@ module HxbWriter = struct
|
|
with Not_found ->
|
|
with Not_found ->
|
|
let restore = start_temporary_chunk writer 256 in
|
|
let restore = start_temporary_chunk writer 256 in
|
|
let old = writer.wrote_local_type_param in
|
|
let old = writer.wrote_local_type_param in
|
|
|
|
+ writer.wrote_local_type_param <- false;
|
|
ignore(write_class_field_and_overloads_data writer true cf);
|
|
ignore(write_class_field_and_overloads_data writer true cf);
|
|
- let wrote_local_type_param = writer.wrote_local_type_param in
|
|
|
|
- writer.wrote_local_type_param <- old;
|
|
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
|
|
- if wrote_local_type_param then begin
|
|
|
|
|
|
+ if writer.needs_local_context || writer.wrote_local_type_param then begin
|
|
(* If we access something from the method scope, we have to write the anon field immediately.
|
|
(* If we access something from the method scope, we have to write the anon field immediately.
|
|
This should be fine because in such cases the field cannot be referenced elsewhere. *)
|
|
This should be fine because in such cases the field cannot be referenced elsewhere. *)
|
|
let index = HashedIdentityPool.add writer.anon_fields cf.cf_name cf None in
|
|
let index = HashedIdentityPool.add writer.anon_fields cf.cf_name cf None in
|
|
- needs_local_context := true;
|
|
|
|
|
|
+ writer.needs_local_context <- true;
|
|
Chunk.write_u8 writer.chunk 1;
|
|
Chunk.write_u8 writer.chunk 1;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
Chunk.write_bytes writer.chunk bytes
|
|
Chunk.write_bytes writer.chunk bytes
|
|
@@ -1083,7 +1082,8 @@ module HxbWriter = struct
|
|
let index = HashedIdentityPool.add writer.anon_fields cf.cf_name cf (Some bytes) in
|
|
let index = HashedIdentityPool.add writer.anon_fields cf.cf_name cf (Some bytes) in
|
|
Chunk.write_u8 writer.chunk 0;
|
|
Chunk.write_u8 writer.chunk 0;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
Chunk.write_uleb128 writer.chunk index;
|
|
- end
|
|
|
|
|
|
+ end;
|
|
|
|
+ writer.wrote_local_type_param <- old
|
|
|
|
|
|
(* Type instances *)
|
|
(* Type instances *)
|
|
|
|
|
|
@@ -1565,7 +1565,7 @@ module HxbWriter = struct
|
|
| TField(e1,FAnon cf) ->
|
|
| TField(e1,FAnon cf) ->
|
|
Chunk.write_u8 writer.chunk 104;
|
|
Chunk.write_u8 writer.chunk 104;
|
|
loop e1;
|
|
loop e1;
|
|
- write_anon_field_ref writer (ref false) cf;
|
|
|
|
|
|
+ write_anon_field_ref writer cf;
|
|
true;
|
|
true;
|
|
| TField(e1,FClosure(Some(c,tl),cf)) ->
|
|
| TField(e1,FClosure(Some(c,tl),cf)) ->
|
|
Chunk.write_u8 writer.chunk 105;
|
|
Chunk.write_u8 writer.chunk 105;
|
|
@@ -1577,7 +1577,7 @@ module HxbWriter = struct
|
|
| TField(e1,FClosure(None,cf)) ->
|
|
| TField(e1,FClosure(None,cf)) ->
|
|
Chunk.write_u8 writer.chunk 106;
|
|
Chunk.write_u8 writer.chunk 106;
|
|
loop e1;
|
|
loop e1;
|
|
- write_anon_field_ref writer (ref false) cf;
|
|
|
|
|
|
+ write_anon_field_ref writer cf;
|
|
true;
|
|
true;
|
|
| TField(e1,FEnum(en,ef)) ->
|
|
| TField(e1,FEnum(en,ef)) ->
|
|
Chunk.write_u8 writer.chunk 107;
|
|
Chunk.write_u8 writer.chunk 107;
|
|
@@ -2312,6 +2312,7 @@ let create config warn anon_id =
|
|
local_type_parameters = IdentityPool.create ();
|
|
local_type_parameters = IdentityPool.create ();
|
|
field_stack = [];
|
|
field_stack = [];
|
|
wrote_local_type_param = false;
|
|
wrote_local_type_param = false;
|
|
|
|
+ needs_local_context = false;
|
|
unbound_ttp = IdentityPool.create ();
|
|
unbound_ttp = IdentityPool.create ();
|
|
t_instance_chunk = Chunk.create EOM cp 32;
|
|
t_instance_chunk = Chunk.create EOM cp 32;
|
|
}
|
|
}
|