Explorar o código

+ also allow declaring an external as 'suspending first'

Nikolay Nikolov %!s(int64=2) %!d(string=hai) anos
pai
achega
4d62764fa3
Modificáronse 3 ficheiros con 39 adicións e 1 borrados
  1. 3 1
      compiler/pdecsub.pas
  2. 2 0
      compiler/tokens.pas
  3. 34 0
      tests/test/wasm/tjspromise1a.pp

+ 3 - 1
compiler/pdecsub.pas

@@ -2406,7 +2406,9 @@ begin
              consume(_SUSPENDING);
              include(procoptions,po_wasm_suspending);
              synthetickind:=tsk_wasm_suspending;
-             if idtoken=_LAST then
+             if idtoken=_FIRST then
+               consume(_FIRST)
+             else if idtoken=_LAST then
                begin
                  consume(_LAST);
                  synthetickind:=tsk_wasm_suspending_last;

+ 2 - 0
compiler/tokens.pas

@@ -163,6 +163,7 @@ type
     _EQUAL,
     _FAR16,
     _FINAL,
+    _FIRST,
     _INDEX,
     _LABEL,
     _LOCAL,
@@ -509,6 +510,7 @@ const
       (str:'EQUAL'         ;special:false;keyword:[m_none];op:NOTOKEN), { delphi operator name }
       (str:'FAR16'         ;special:false;keyword:[m_none];op:NOTOKEN),
       (str:'FINAL'         ;special:false;keyword:[m_none];op:NOTOKEN),
+      (str:'FIRST'         ;special:false;keyword:[m_none];op:NOTOKEN),
       (str:'INDEX'         ;special:false;keyword:[m_none];op:NOTOKEN),
       (str:'LABEL'         ;special:false;keyword:alllanguagemodes;op:NOTOKEN),
       (str:'LOCAL'         ;special:false;keyword:[m_none];op:NOTOKEN),

+ 34 - 0
tests/test/wasm/tjspromise1a.pp

@@ -0,0 +1,34 @@
+{ %cpu=wasm32 }
+{ %norun }
+
+library tjspromise1;
+
+var
+  state: double;
+
+function init_state: double; external 'js';
+function compute_delta: double; external 'js' suspending first;
+
+procedure init;
+begin
+  state := init_state;
+end;
+
+function get_state: double;
+begin
+  get_state := state;
+end;
+
+function update_state: double;
+begin
+  state := state + compute_delta;
+  update_state := state;
+end;
+
+exports
+  get_state,
+  update_state promising;
+
+begin
+  init;
+end.