Ver código fonte

+ support 'promising last' exports

Nikolay Nikolov 2 anos atrás
pai
commit
2f1ccd6f2a

+ 2 - 1
compiler/export.pas

@@ -38,7 +38,8 @@ type
      eo_index,
      eo_name,
      eo_no_sym_name, { don't try to use another mangled name if symbol is known }
-     eo_promising_first
+     eo_promising_first,
+     eo_promising_last
    );
    texportoptions=set of texportoption;
 

+ 8 - 1
compiler/pexports.pas

@@ -179,7 +179,14 @@ implementation
                     if try_to_consume(_PROMISING) then
                      begin
                        if target_info.system in systems_wasm then
-                         include(options,eo_promising_first);
+                         begin
+                           if try_to_consume(_FIRST) then
+                             include(options,eo_promising_first)
+                           else if try_to_consume(_LAST) then
+                             include(options,eo_promising_last)
+                           else
+                             include(options,eo_promising_first);
+                         end;
                      end;
                     if (DefString<>'') and UseDeffileForExports then
                      DefFile.AddExport(DefString);

+ 10 - 2
compiler/symcreat.pas

@@ -1009,8 +1009,16 @@ implementation
     var
       new_wrapper_pd: tprocdef;
     begin
-      new_wrapper_pd:=implement_wasm_promising_wrapper(pd,false);
-      current_asmdata.asmlists[al_exports].Concat(tai_export_name.create(pd.promising_first_export_name,new_wrapper_pd.mangledname,ie_Func));
+      if pd.promising_first_export_name<>'' then
+        begin
+          new_wrapper_pd:=implement_wasm_promising_wrapper(pd,false);
+          current_asmdata.asmlists[al_exports].Concat(tai_export_name.create(pd.promising_first_export_name,new_wrapper_pd.mangledname,ie_Func));
+        end;
+      if pd.promising_last_export_name<>'' then
+        begin
+          new_wrapper_pd:=implement_wasm_promising_wrapper(pd,true);
+          current_asmdata.asmlists[al_exports].Concat(tai_export_name.create(pd.promising_last_export_name,new_wrapper_pd.mangledname,ie_Func));
+        end;
     end;
 {$endif wasm}
 

+ 2 - 0
compiler/systems/t_wasi.pas

@@ -252,6 +252,8 @@ begin
   pd:=tcpuprocdef(tprocsym(hp.sym).ProcdefList[0]);
   if eo_promising_first in hp.options then
     pd.add_promising_export(hp.name^,false)
+  else if eo_promising_last in hp.options then
+    pd.add_promising_export(hp.name^,true)
   else
     begin
       nm := pd.mangledname;

+ 13 - 1
compiler/wasm32/symcpu.pas

@@ -118,6 +118,7 @@ type
       easily write out all methods grouped per class }
     exprasmlist  : TAsmList;
     promising_first_export_name: string;
+    promising_last_export_name: string;
     destructor destroy; override;
     function create_functype: TWasmFuncType;
     function is_pushleftright: boolean; override;
@@ -396,7 +397,18 @@ implementation
       if (synthetickind<>tsk_none) and (synthetickind<>tsk_wasm_promising) then
         internalerror(2023061301);
       synthetickind:=tsk_wasm_promising;
-      promising_first_export_name:=aextname;
+      if last then
+        begin
+          if promising_last_export_name<>'' then
+            internalerror(2023061601);
+          promising_last_export_name:=aextname;
+        end
+      else
+        begin
+          if promising_first_export_name<>'' then
+            internalerror(2023061602);
+          promising_first_export_name:=aextname;
+        end;
     end;
 
 

+ 2 - 2
tests/test/wasm/tjspromise1a.pp

@@ -1,7 +1,7 @@
 { %cpu=wasm32 }
 { %norun }
 
-library tjspromise1;
+library tjspromise1a;
 
 var
   state: double;
@@ -27,7 +27,7 @@ end;
 
 exports
   get_state,
-  update_state promising;
+  update_state promising first;
 
 begin
   init;

+ 1 - 1
tests/test/wasm/tjspromise2.pp

@@ -27,7 +27,7 @@ end;
 
 exports
   get_state,
-  update_state promising;
+  update_state promising last;
 
 begin
   init;