@@ -49,6 +49,11 @@ TVMState = record
4949 symbolTable : TSymbolTable;
5050 end ;
5151
52+ // Only used for debugging
53+ TStackInfo = record
54+ stacktop : integer;
55+ end ;
56+
5257 TVM = class (TObject)
5358 private
5459 stack: TMachineStack;
@@ -149,6 +154,7 @@ TVM = class(TObject)
149154 procedure collectGarbage ;
150155 function getGarbageSize : integer;
151156 public
157+ interactive : boolean;
152158 constructor Create;
153159 destructor Destroy; override;
154160 procedure registerPrintCallBack (fcn: TVMPrintCallBack);
@@ -183,6 +189,7 @@ TVM = class(TObject)
183189 procedure run (code: TProgram; symbolTable : TSymbolTable);
184190 procedure runModule (module : TModule);
185191
192+ function getStackInfo : TStackInfo; // for debuggin purposes)
186193 procedure setcallBack (proc: TVMCallBack);
187194 procedure unsetcallBack ;
188195 end ;
@@ -217,6 +224,7 @@ constructor TVM.Create;
217224 printCallbackPtr := nil ;
218225 printlnCallbackPtr := nil ;
219226 assertCounter := 1 ;
227+ interactive := False;
220228end ;
221229
222230
@@ -229,6 +237,12 @@ destructor TVM.Destroy;
229237end ;
230238
231239
240+ function TVM.getStackInfo : TStackInfo; // for debuggin purposes)
241+ begin
242+ result.stacktop := stackTop;
243+ end ;
244+
245+
232246procedure TVM.registerSetColorCallback (fcn : TVMSetColorCallBack);
233247begin
234248 setColorCallBackPtr := fcn;
@@ -2084,7 +2098,14 @@ procedure TVM.run (code: TProgram; symbolTable : TSymbolTable);
20842098 oPushNone: push (@noneStackType);
20852099 oPushFunction: pushFunction (c[ip].index1);
20862100 oPushLocalSymbol : pushLocalSymbol (c[ip].index1);
2087- oPop: value := pop(); // this pop just throws the data away
2101+ oPop: begin
2102+ // If the next instrction is halt, we will leave the item
2103+ // on the stack and let the caller deal with it. This is
2104+ // mainly useful when used in interactive mode so that the
2105+ // console can print the stack item to the console
2106+ if c[ip+1 ].opCode <> oHalt then
2107+ pop();
2108+ end ;
20882109 oDup: dupStack;
20892110 oIsLt: isLt;
20902111 oIsLte: isLte;
@@ -2132,17 +2153,7 @@ procedure TVM.run (code: TProgram; symbolTable : TSymbolTable);
21322153
21332154 oImportModule : importModule (c[ip].moduleName);
21342155 // Method call opcodes
2135- oCall: begin
2136- // vmstate.module := self.module;
2137- // vmstate.symbolTable := self.symbolTable;
2138- // VMStateStack.push (vmstate);
2139-
2140- callUserFunction (c[ip].index1);
2141-
2142- // vmstate := VMStateStack.Pop;
2143- // self.module := vmstate.module;
2144- // self.symbolTable := vmstate.symbolTable;
2145- end ;
2156+ oCall: callUserFunction (c[ip].index1);
21462157 oRet:
21472158 begin
21482159 // Note that anything that is returned isn't bound to any symbol.
0 commit comments