Przeglądaj źródła

+ implemented methods in TWasmControlStack: Push, Pop, GetItems, SetItems

Nikolay Nikolov 1 rok temu
rodzic
commit
3f0853692c
1 zmienionych plików z 44 dodań i 0 usunięć
  1. 44 0
      compiler/wasm32/aasmcpu.pas

+ 44 - 0
compiler/wasm32/aasmcpu.pas

@@ -68,6 +68,14 @@ uses
       { TWasmControlStack }
 
       TWasmControlStack = class
+      private
+        FControlStack: array of TWasmControlFrame;
+        function GetItems(AIndex: Integer): TWasmControlFrame;
+        procedure SetItems(AIndex: Integer; const AValue: TWasmControlFrame);
+      public
+        procedure Push(const wcf: TWasmControlFrame);
+        function Pop: TWasmControlFrame;
+        property Items[AIndex: Integer]: TWasmControlFrame read GetItems write SetItems; default;
       end;
 
       { TWasmValidationStacks }
@@ -380,6 +388,42 @@ uses
         SetLength(FValStack,Length(FValStack)-1);
       end;
 
+    { TWasmControlStack }
+
+    function TWasmControlStack.GetItems(AIndex: Integer): TWasmControlFrame;
+      var
+        I: Integer;
+      begin
+        I:=High(FControlStack)-AIndex;
+        if (I<Low(FControlStack)) or (I>High(FControlStack)) then
+          internalerror(2024013101);
+        Result:=FControlStack[I];
+      end;
+
+    procedure TWasmControlStack.SetItems(AIndex: Integer; const AValue: TWasmControlFrame);
+      var
+        I: Integer;
+      begin
+        I:=High(FControlStack)-AIndex;
+        if (I<Low(FControlStack)) or (I>High(FControlStack)) then
+          internalerror(2024013102);
+        FControlStack[I]:=AValue;
+      end;
+
+    procedure TWasmControlStack.Push(const wcf: TWasmControlFrame);
+      begin
+        SetLength(FControlStack,Length(FControlStack)+1);
+        FControlStack[High(FControlStack)]:=wcf;
+      end;
+
+    function TWasmControlStack.Pop: TWasmControlFrame;
+      begin
+        if Length(FControlStack)=0 then
+          internalerror(2024013103);
+        Result:=FControlStack[High(FControlStack)];
+        SetLength(FControlStack,Length(FControlStack)-1);
+      end;
+
     { TWasmValidationStacks }
 
     constructor TWasmValidationStacks.Create;