@@ -49,6 +49,11 @@ TVMState = record
49
49
symbolTable : TSymbolTable;
50
50
end ;
51
51
52
+ // Only used for debugging
53
+ TStackInfo = record
54
+ stacktop : integer;
55
+ end ;
56
+
52
57
TVM = class (TObject)
53
58
private
54
59
stack: TMachineStack;
@@ -149,6 +154,7 @@ TVM = class(TObject)
149
154
procedure collectGarbage ;
150
155
function getGarbageSize : integer;
151
156
public
157
+ interactive : boolean;
152
158
constructor Create;
153
159
destructor Destroy; override;
154
160
procedure registerPrintCallBack (fcn: TVMPrintCallBack);
@@ -183,6 +189,7 @@ TVM = class(TObject)
183
189
procedure run (code: TProgram; symbolTable : TSymbolTable);
184
190
procedure runModule (module : TModule);
185
191
192
+ function getStackInfo : TStackInfo; // for debuggin purposes)
186
193
procedure setcallBack (proc: TVMCallBack);
187
194
procedure unsetcallBack ;
188
195
end ;
@@ -217,6 +224,7 @@ constructor TVM.Create;
217
224
printCallbackPtr := nil ;
218
225
printlnCallbackPtr := nil ;
219
226
assertCounter := 1 ;
227
+ interactive := False;
220
228
end ;
221
229
222
230
@@ -229,6 +237,12 @@ destructor TVM.Destroy;
229
237
end ;
230
238
231
239
240
+ function TVM.getStackInfo : TStackInfo; // for debuggin purposes)
241
+ begin
242
+ result.stacktop := stackTop;
243
+ end ;
244
+
245
+
232
246
procedure TVM.registerSetColorCallback (fcn : TVMSetColorCallBack);
233
247
begin
234
248
setColorCallBackPtr := fcn;
@@ -2084,7 +2098,14 @@ procedure TVM.run (code: TProgram; symbolTable : TSymbolTable);
2084
2098
oPushNone: push (@noneStackType);
2085
2099
oPushFunction: pushFunction (c[ip].index1);
2086
2100
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 ;
2088
2109
oDup: dupStack;
2089
2110
oIsLt: isLt;
2090
2111
oIsLte: isLte;
@@ -2132,17 +2153,7 @@ procedure TVM.run (code: TProgram; symbolTable : TSymbolTable);
2132
2153
2133
2154
oImportModule : importModule (c[ip].moduleName);
2134
2155
// 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);
2146
2157
oRet:
2147
2158
begin
2148
2159
// Note that anything that is returned isn't bound to any symbol.
0 commit comments