home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / Chip_2000-02_cd.bin / zkuste / Delphi / navody / tt / objvm.exe / UNITS / Execution.pas < prev    next >
Pascal/Delphi Source File  |  1998-06-26  |  2KB  |  64 lines

  1. unit Execution;
  2.  
  3. interface
  4. uses uExecution,
  5.      uObjVM,Code,RootValue,ProxyValue,ObjOp;
  6. type
  7.      {Implementation of IExecution interface }
  8.    TExecution=class(IExecution)
  9.      protected
  10.        {VM is Virtual Machine}
  11.        VM:IObjVM;
  12.        {BeginExec prepares internal structures for executing}
  13.        procedure BeginExec;override;
  14.          {EndExec - close execution}
  15.        procedure EndExec;override;
  16.      public
  17.          {Creates an execution of aCode on aVM virtual machine}
  18.        Constructor Create(aVM:IObjVM;aCode:TCode);
  19.          {Destroys execution}
  20.        destructor  Destroy;override;
  21.          {Step - execute one Operation }
  22.        procedure Step;override;
  23.      end;
  24. implementation
  25. uses ValStack,ObjVM,SysUtils,COnstValues;
  26. Constructor TExecution.Create;
  27.             begin
  28.               VM:=aVM;
  29.               Code:=aCode;
  30.               Root:=TRootValue.Create;
  31.               Consts:=TConstValues.Create;
  32.               Root.Add(Consts);
  33.               BeginExec;
  34.             end;
  35. destructor  TExecution.Destroy;
  36.             begin
  37.               EndExec;
  38.               Root.Free;
  39.               Inherited Destroy;
  40.             end;
  41. procedure TExecution.BeginExec;
  42.           begin
  43.             Inherited BeginExec;
  44.             Data:=TValStack.Create;
  45.             Return:=TValStack.Create;
  46.           end;
  47. procedure TExecution.Step;
  48.           Var OpCode:Integer;
  49.               Op:TObjOp;
  50.           begin
  51.             OpCode:=Code.Int[IP];
  52.             Op:=VM.Ops.Find(OpCode);
  53.             if Op=Nil then
  54.               Raise Exception.CreateFmt('Opcode not found - %d',[OpCode]);
  55.             Op.Execute(Self);
  56.           end;
  57. procedure TExecution.EndExec;
  58.           begin
  59.             Data.Free;
  60.             Return.Free;
  61.           end;
  62.  
  63. end.
  64.