Changeset 54 for branches/DelphiToC/UCompiler.pas
- Timestamp:
- Aug 10, 2010, 11:54:18 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/UCompiler.pas
r53 r54 23 23 FOnErrorMessage: TOnErrorMessage; 24 24 procedure ErrorMessage(Text: string; Position: TPoint); 25 procedure InitSystem;26 25 public 27 26 ProgramCode: TProgram; 28 SourceCode: TStringList;29 27 Parser: TPascalParser; 30 28 Producer: TProducer; 31 29 ErrorMessages: TObjectList; 32 30 constructor Create; 33 procedure Compile; 31 procedure Init; 32 procedure Compile(Source: TStringList; ProducedCode: TStringList); 34 33 destructor Destroy; override; 35 34 property OnErrorMessage: TOnErrorMessage read FOnErrorMessage write FOnErrorMessage; … … 40 39 { TCompiler } 41 40 42 procedure TCompiler.Compile; 41 procedure TCompiler.Compile(Source: TStringList; ProducedCode: TStringList); 42 var 43 NewModule: TModule; 43 44 begin 44 InitSystem; 45 ErrorMessages.Clear; 45 Parser.SourceCodeText := Source; 46 46 Parser.Init; 47 Parser.ParseAll(ProgramCode); 48 Producer.Produce; 47 NewModule := TModule.Create; 48 ProgramCode.Modules.Add(NewModule); 49 Parser.ParseModule(NewModule); 50 Producer.Produce(NewModule, ProducedCode); 49 51 end; 50 52 51 53 constructor TCompiler.Create; 52 54 begin 53 SourceCode := TStringList.Create;54 55 ProgramCode := TProgram.Create; 55 56 Producer := TProducerC.Create; 56 Producer.ProgramCode := ProgramCode;57 57 Parser := TPascalParser.Create; 58 Parser.SourceCodeText := SourceCode;59 58 Parser.OnErrorMessage := ErrorMessage; 60 59 ErrorMessages := TObjectList.Create; 60 end; 61 62 procedure TCompiler.Init; 63 begin 64 ErrorMessages.Clear; 65 ProgramCode.Modules.Clear; 61 66 end; 62 67 … … 64 69 begin 65 70 ProgramCode.Free; 66 SourceCode.Free;67 71 Parser.Free; 68 72 Producer.Free; … … 81 85 end; 82 86 83 procedure TCompiler.InitSystem;84 begin85 with Parser do begin86 Log('==== Parse start ====');87 with ProgramCode do begin88 Modules.Clear;89 90 with TModule(Modules[Modules.Add(TModule.Create)]) do begin91 Name := 'Main';92 with TType(Types[Types.Add(TType.Create)]) do begin93 Name := 'Void';94 System := True;95 Size := 0;96 UsedType := nil;97 end;98 with TType(Types[Types.Add(TType.Create)]) do begin99 Name := 'Byte';100 System := True;101 Size := 1;102 UsedType := nil;103 end;104 with TType(Types[Types.Add(TType.Create)]) do begin105 Name := 'ShortInt';106 System := True;107 Size := 1;108 UsedType := nil;109 end;110 with TType(Types[Types.Add(TType.Create)]) do begin111 Name := 'Word';112 System := True;113 Size := 2;114 UsedType := nil;115 end;116 with TType(Types[Types.Add(TType.Create)]) do begin117 Name := 'SmallInt';118 System := True;119 Size := 2;120 UsedType := nil;121 end;122 with TType(Types[Types.Add(TType.Create)]) do begin123 Name := 'Cardinal';124 System := True;125 Size := 3;126 UsedType := nil;127 end;128 with TType(Types[Types.Add(TType.Create)]) do begin129 Name := 'Integer';130 System := True;131 Size := 3;132 UsedType := nil;133 end;134 with TType(Types[Types.Add(TType.Create)]) do begin135 Name := 'Char';136 System := True;137 Size := 1;138 UsedType := nil;139 end;140 with TType(Types[Types.Add(TType.Create)]) do begin141 Name := 'String';142 System := True;143 Size := 1;144 UsedType := nil;145 end;146 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin147 Name := 'Exit';148 System := True;149 ResultType := TType(TModule(Modules[0]).Types[0]);150 end;151 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin152 Name := 'Break';153 System := True;154 ResultType := TType(TModule(Modules[0]).Types[0]);155 end;156 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin157 Name := 'Continue';158 System := True;159 ResultType := TType(TModule(Modules[0]).Types[0]);160 end;161 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin162 Name := 'WriteLn';163 ResultType := TType(TModule(Modules[0]).Types[0]);164 with TParameter(Parameters[Parameters.Add(TParameter.Create)]) do begin165 Name := 'Text';166 ValueType := TType(TModule(Modules[0]).Types[1]);167 end;168 end;169 end;170 end;171 end;172 end;173 174 87 end.
Note:
See TracChangeset
for help on using the changeset viewer.