Browse Source

+ support WebAssembly reference types as WebAssembly globals

Nikolay Nikolov 2 years ago
parent
commit
8eea58f649
2 changed files with 16 additions and 1 deletions
  1. 5 1
      compiler/wasm32/symcpu.pas
  2. 11 0
      tests/test/wasm/twasmexternref1.pp

+ 5 - 1
compiler/wasm32/symcpu.pas

@@ -403,7 +403,11 @@ implementation
     function tcpustaticvarsym.try_get_wasm_global_vardef_type(out res: TWasmBasicType): Boolean;
       begin
         Result:=True;
-        if is_64bitint(vardef) then
+        if is_wasm_externref(vardef) then
+          res:=wbt_externref
+        else if is_wasm_funcref(vardef) then
+          res:=wbt_funcref
+        else if is_64bitint(vardef) then
           res:=wbt_i64
         else if is_pointer(vardef) then
           res:=wbt_i32

+ 11 - 0
tests/test/wasm/twasmexternref1.pp

@@ -3,6 +3,9 @@
 
 program twasmexternref1;
 
+var
+  global_externref: WasmExternRef; section 'WebAssembly.Global';
+
 procedure testproc;
 var
   p: WasmExternRef;
@@ -23,6 +26,8 @@ var
 begin
   q := d;
   testproc4 := q;
+  global_externref := d;
+  q := global_externref;
 end;
 
 function testproc5(q: WasmExternRef): WasmExternRef;
@@ -31,6 +36,7 @@ var
 begin
   w := nil;
   testproc5 := nil;
+  global_externref := nil;
 end;
 
 function testproc6: Boolean;
@@ -39,8 +45,12 @@ var
 begin
   testproc6 := q = nil;
   testproc6 := nil = q;
+  testproc6 := global_externref = nil;
+  testproc6 := nil = global_externref;
   testproc6 := q <> nil;
   testproc6 := nil <> q;
+  testproc6 := global_externref <> nil;
+  testproc6 := nil <> global_externref;
 end;
 
 procedure testproc7(const q: WasmExternRef);
@@ -49,5 +59,6 @@ end;
 
 begin
   testproc5(nil);
+  testproc5(global_externref);
   testproc7(nil);
 end.