Changeset 64 for trunk/Target/UTargetInterpretter.pas
- Timestamp:
- Dec 4, 2014, 2:59:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTargetInterpretter.pas
r52 r64 33 33 FThread: TTargetInterpretterThread; 34 34 FStepCount: Integer; 35 FCommandTable: array[T BrainFuckCommand] of TCommandHandler;35 FCommandTable: array[TMachineCommand] of TCommandHandler; 36 36 function GetMemorySize: Integer; 37 37 procedure SetMemorySize(AValue: Integer); … … 46 46 procedure CommandLoopStart; 47 47 procedure CommandLoopEnd; 48 procedure CommandSet; 48 49 procedure PrepareBreakPoints; 49 50 protected … … 81 82 82 83 const 83 BrainFuckCommandText: array[T BrainFuckCommand] of Char = (84 ' ', '+', '-', '>', '<', '.', ',', '[', ']', '@' );84 BrainFuckCommandText: array[TMachineCommand] of Char = ( 85 ' ', '+', '-', '>', '<', '.', ',', '[', ']', '@', '='); 85 86 86 87 … … 95 96 SMemoryCellOutOfRange = 'Memory cell %s value out of range'; 96 97 SProgramNotRunning = 'Program not running'; 98 SUnsupportedCommand = 'Unsupported command'; 97 99 98 100 { TTargetInterpretterThread } … … 111 113 SetStateSafe(rsPaused); 112 114 end else begin 113 FCommandTable[FProgram[FProgramIndex]]; 115 if Assigned(FCommandTable[FProgram[FProgramIndex].Command]) then 116 FCommandTable[FProgram[FProgramIndex].Command] 117 else raise Exception.Create(SUnsupportedCommand); 114 118 Inc(FProgramIndex); 115 119 Inc(FStepCount); … … 177 181 SetLength(Loop, 0); 178 182 for I := 0 to Length(FProgram) - 1 do begin 179 case FProgram[I] of183 case FProgram[I].Command of 180 184 cmLoopStart: begin 181 185 SetLength(Loop, Length(Loop) + 1); … … 194 198 end; 195 199 196 procedure TTargetInterpretter.CommandInc;197 begin198 Memory[MemoryPosition] := ((Memory[MemoryPosition] + 1) mod CellSize);199 end;200 201 procedure TTargetInterpretter.CommandDec;202 begin203 Memory[MemoryPosition] := ((Memory[MemoryPosition] - 1) mod CellSize);204 end;205 206 procedure TTargetInterpretter.CommandPointerInc;207 begin208 if MemoryPosition < MemorySize then Inc(MemoryPosition)209 else raise Exception.Create(SProgramUpperLimit);210 end;211 212 procedure TTargetInterpretter.CommandPointerDec;213 begin214 if MemoryPosition > 0 then Dec(MemoryPosition)215 else raise Exception.Create(SProgramLowerLimit);216 end;217 218 200 procedure TTargetInterpretter.CommandInput; 219 201 begin … … 245 227 if Memory[MemoryPosition] > 0 then 246 228 FProgramIndex := SourceJump[FProgramIndex] - 1; 229 end; 230 231 procedure TTargetInterpretter.CommandInc; 232 begin 233 Memory[MemoryPosition] := ((Memory[MemoryPosition] + FProgram[FProgramIndex].Parameter) mod CellSize); 234 end; 235 236 procedure TTargetInterpretter.CommandDec; 237 begin 238 Memory[MemoryPosition] := ((Memory[MemoryPosition] - FProgram[FProgramIndex].Parameter) mod CellSize); 239 end; 240 241 procedure TTargetInterpretter.CommandPointerInc; 242 begin 243 if MemoryPosition < MemorySize then Inc(MemoryPosition, FProgram[FProgramIndex].Parameter) 244 else raise Exception.Create(SProgramUpperLimit); 245 end; 246 247 procedure TTargetInterpretter.CommandPointerDec; 248 begin 249 if MemoryPosition > 0 then Dec(MemoryPosition, FProgram[FProgramIndex].Parameter) 250 else raise Exception.Create(SProgramLowerLimit); 251 end; 252 253 procedure TTargetInterpretter.CommandSet; 254 begin 255 Memory[MemoryPosition] := FProgram[FProgramIndex].Parameter mod CellSize; 247 256 end; 248 257 … … 286 295 I: Integer; 287 296 begin 288 SetLength(Result, Length(FProgram)); 289 for I := 0 to Length(FProgram) - 1 do 290 Result[I + 1] := BrainFuckCommandText[FProgram[I]]; 297 Result := ''; 298 for I := 0 to Length(FProgram) - 1 do begin 299 Result := Result + BrainFuckCommandText[FProgram[I].Command]; 300 if FProgram[I].Command in [cmInc, cmDec, cmSet, cmPointerInc, cmPointerDec] then begin 301 if FProgram[I].Parameter > 1 then 302 Result := Result + IntToStr(FProgram[I].Parameter); 303 end; 304 end; 291 305 end; 292 306 … … 402 416 MemorySize := 30000; 403 417 CellSize := 256; 418 // Base commands 404 419 FCommandTable[cmInc] := CommandInc; 405 420 FCommandTable[cmDec] := CommandDec; … … 410 425 FCommandTable[cmLoopStart] := CommandLoopStart; 411 426 FCommandTable[cmLoopEnd] := CommandLoopEnd; 427 // Extended commands 428 FCommandTable[cmSet] := CommandSet; 412 429 end; 413 430
Note:
See TracChangeset
for help on using the changeset viewer.