home *** CD-ROM | disk | FTP | other *** search
- unit Execution;
-
- interface
- uses uExecution,
- uObjVM,Code,RootValue,ProxyValue,ObjOp;
- type
- {Implementation of IExecution interface }
- TExecution=class(IExecution)
- protected
- {VM is Virtual Machine}
- VM:IObjVM;
- {BeginExec prepares internal structures for executing}
- procedure BeginExec;override;
- {EndExec - close execution}
- procedure EndExec;override;
- public
- {Creates an execution of aCode on aVM virtual machine}
- Constructor Create(aVM:IObjVM;aCode:TCode);
- {Destroys execution}
- destructor Destroy;override;
- {Step - execute one Operation }
- procedure Step;override;
- end;
- implementation
- uses ValStack,ObjVM,SysUtils,COnstValues;
- Constructor TExecution.Create;
- begin
- VM:=aVM;
- Code:=aCode;
- Root:=TRootValue.Create;
- Consts:=TConstValues.Create;
- Root.Add(Consts);
- BeginExec;
- end;
- destructor TExecution.Destroy;
- begin
- EndExec;
- Root.Free;
- Inherited Destroy;
- end;
- procedure TExecution.BeginExec;
- begin
- Inherited BeginExec;
- Data:=TValStack.Create;
- Return:=TValStack.Create;
- end;
- procedure TExecution.Step;
- Var OpCode:Integer;
- Op:TObjOp;
- begin
- OpCode:=Code.Int[IP];
- Op:=VM.Ops.Find(OpCode);
- if Op=Nil then
- Raise Exception.CreateFmt('Opcode not found - %d',[OpCode]);
- Op.Execute(Self);
- end;
- procedure TExecution.EndExec;
- begin
- Data.Free;
- Return.Free;
- end;
-
- end.
-