source: tags/1.3.0/Target/TargetDelphi.pas

Last change on this file was 162, checked in by chronos, 3 months ago

Merged revision(s) 161 from trunk:

  • Fixed: All targets compilation and run.
File size: 2.7 KB
Line 
1unit TargetDelphi;
2
3interface
4
5uses
6 Classes, SysUtils, Target, BFTarget;
7
8type
9
10 { TTargetDelphi }
11
12 TTargetDelphi = class(TBFTarget)
13 private
14 function GetMemoryCell: string;
15 public
16 constructor Create; override;
17 procedure Compile; override;
18 procedure Run; override;
19 end;
20
21implementation
22
23{ TTargetDelphi }
24
25constructor TTargetDelphi.Create;
26begin
27 inherited;
28 FName := 'Delphi';
29 FSourceExtension := '.pas';
30 FImageIndex := 22;
31 FCapabilities := [tcCompile];
32 {$IFDEF Windows}
33 FCapabilities := [tcCompile, tcRun];
34 CompilerPath := 'c:\Program Files\Embarcadero\RAD Studio\9.0\bin\DCC32.EXE';
35 FCompiledExtension := '.exe';
36 {$ENDIF}
37end;
38
39function TTargetDelphi.GetMemoryCell: string;
40begin
41 Result := 'Memory[Pos';
42 if FProgram[FProgramIndex].RelIndex > 0 then
43 Result := Result + ' + ' + IntToStr(FProgram[FProgramIndex].RelIndex)
44 else if FProgram[FProgramIndex].RelIndex < 0 then
45 Result := Result + ' - ' + IntToStr(Abs(FProgram[FProgramIndex].RelIndex));
46 Result := Result + ']';
47end;
48
49procedure TTargetDelphi.Compile;
50begin
51 inherited;
52 Indent := 0;
53 FTargetCode := '';
54
55 AddLine('program ' + ProgramName + ';');
56 AddLine('');
57 AddLine('{$APPTYPE CONSOLE}');
58 AddLine('');
59 AddLine('var');
60 AddLine(' Memory: array[0..' + IntToStr(MemorySize) + '] of Byte;');
61 AddLine(' Pos: Integer;');
62 AddLine(' ReadChar: Char;');
63 AddLine('begin');
64 Inc(Indent);
65 AddLine('Pos := 0;');
66 FProgramIndex := 0;
67 while FProgramIndex < FProgram.Count do begin
68 case FProgram[FProgramIndex].Command of
69 cmPointerInc: AddLine('Inc(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
70 cmPointerDec: AddLine('Dec(Pos, ' + IntToStr(FProgram[FProgramIndex].Parameter) + ');');
71 cmInc: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
72 cmDec: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' - ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
73 cmSet: AddLine(GetMemoryCell + ' := ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
74 cmMultiply: AddLine(GetMemoryCell + ' := ' + GetMemoryCell + ' + Memory[Pos] * ' + IntToStr(FProgram[FProgramIndex].Parameter) + ';');
75 cmOutput: AddLine('Write(Chr(' + GetMemoryCell + '));');
76 cmInput: AddLine('Read(ReadChar); ' + GetMemoryCell + ' := Ord(ReadChar);');
77 cmLoopStart: begin
78 AddLine('while ' + GetMemoryCell + ' <> 0 do begin');
79 Inc(Indent);
80 end;
81 cmLoopEnd: begin
82 Dec(Indent);
83 AddLine('end;');
84 end;
85 end;
86 Inc(FProgramIndex);
87 end;
88 Dec(Indent);
89 AddLine('end.');
90
91 CompileToFile;
92end;
93
94procedure TTargetDelphi.Run;
95begin
96 inherited;
97 RunFromFile;
98end;
99
100end.
101
Note: See TracBrowser for help on using the repository browser.