Skip to content

Commit 97f8f23

Browse files
committed
Array placeholder
1 parent a644f2d commit 97f8f23

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/lib-wasm/code_generation.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@ let should_make_global x st = Var.Set.mem x st.context.globalized_variables, st
565565

566566
let value_type st = st.context.value_type, st
567567

568+
let get_constant x st = Var.Hashtbl.find_opt st.context.constants x, st
569+
570+
let placeholder_value typ f =
571+
let* c = get_constant typ in
572+
match c with
573+
| None ->
574+
let x = Var.fresh () in
575+
let* () = register_constant typ (W.GlobalGet x) in
576+
let* () =
577+
register_global
578+
~constant:true
579+
x
580+
{ mut = false; typ = Ref { nullable = false; typ = Type typ } }
581+
(f typ)
582+
in
583+
return (W.GlobalGet x)
584+
| Some c -> return c
585+
586+
let array_placeholder typ = placeholder_value typ (fun typ -> ArrayNewFixed (typ, []))
587+
568588
let rec store ?(always = false) ?typ x e =
569589
let* e = e in
570590
match e with

compiler/lib-wasm/code_generation.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,9 @@ val function_body :
201201
-> (Wasm_ast.var * Wasm_ast.value_type) list * Wasm_ast.instruction list
202202

203203
val variable_type : Code.Var.t -> Wasm_ast.value_type option t
204+
205+
val array_placeholder : Code.Var.t -> expression
206+
207+
val default_value :
208+
Wasm_ast.value_type
209+
-> (Wasm_ast.expression * Wasm_ast.value_type * Wasm_ast.ref_type option) t

compiler/lib-wasm/gc_target.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ module Value = struct
428428

429429
let dummy_block =
430430
let* t = Type.block_type in
431-
return (W.ArrayNewFixed (t, []))
431+
array_placeholder t
432432

433433
let as_block e =
434434
let* t = Type.block_type in

0 commit comments

Comments
 (0)