Changeset 145
- Timestamp:
- Jan 17, 2018, 1:11:56 PM (7 years ago)
- Location:
- branches/easy compiler
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/easy compiler
- Property svn:ignore
-
old new 2 2 *.exe 3 3 *.lps 4 heaptrclog.trc
-
- Property svn:ignore
-
branches/easy compiler/UCompiler.pas
r142 r145 262 262 for Param in Funct.Parameters do 263 263 if Param.Kind = pkString then begin 264 TSourceFunctionCall(Instruction). AddParameter(ParseReference)264 TSourceFunctionCall(Instruction).Parameters.Add(ParseReference) 265 265 end else 266 266 if Param.Kind = pkVariable then begin 267 TSourceFunctionCall(Instruction). AddParameter(ParseReferenceVariable(True));267 TSourceFunctionCall(Instruction).Parameters.Add(ParseReferenceVariable(True)); 268 268 end else 269 269 raise Exception.Create('Unsupported parameter type.'); -
branches/easy compiler/UFormMain.pas
r142 r145 51 51 procedure TForm1.FormShow(Sender: TObject); 52 52 begin 53 with MemoSource.Lines do begin 53 { with MemoSource.Lines do begin 54 Add('var I Integer'); 55 Add('Assign I 10'); 56 Add('Repeat'); 57 Add('Begin'); 58 Add('Decrement I 1'); 59 Add('IfZero I'); 60 Add('Break'); 61 Add('End'); 62 end; 63 } with MemoSource.Lines do begin 54 64 Add('PrintLn ''Super Calculator'''); 55 65 Add('var Value1 Integer'); … … 63 73 Add('InputLn Value2'); 64 74 65 Add('begin');66 75 Add('Assign Result Value1'); 67 76 Add('Increment Result Value2'); 68 77 Add('Print ''Sum of two values is: '''); 69 78 Add('PrintLn Result'); 70 Add('end');71 79 end; 72 80 { with MemoSource.Lines do begin -
branches/easy compiler/USourceCode.pas
r143 r145 16 16 17 17 TSourceReference = class 18 end; 19 20 TSourceReferences = class(TObjectList) 18 21 end; 19 22 … … 74 77 end; 75 78 79 { TSourceConstant } 80 76 81 TSourceConstant = class 77 82 Name: string; 78 83 Value: TSourceValue; 84 destructor Destroy; override; 79 85 end; 80 86 … … 123 129 TSourceFunctionCall = class(TSourceInstruction) 124 130 Name: string; 125 Parameters: array of TSourceReference; 126 procedure AddParameter(Value: TSourceReference); 131 Parameters: TSourceReferences; 132 constructor Create; 133 destructor Destroy; override; 127 134 end; 128 135 … … 156 163 implementation 157 164 165 { TSourceConstant } 166 167 destructor TSourceConstant.Destroy; 168 begin 169 Value.Free; 170 inherited Destroy; 171 end; 172 173 { TSourceFunctionCall } 174 175 constructor TSourceFunctionCall.Create; 176 begin 177 Parameters := TSourceReferences.Create; 178 end; 179 180 destructor TSourceFunctionCall.Destroy; 181 begin 182 Parameters.Free; 183 inherited Destroy; 184 end; 185 158 186 { TSourceBeginEnd } 159 187 … … 324 352 325 353 { TSourceFunctionCall } 326 327 procedure TSourceFunctionCall.AddParameter(Value: TSourceReference);328 begin329 SetLength(Parameters, Length(Parameters) + 1);330 Parameters[Length(Parameters) - 1] := Value;331 end;332 354 333 355 { TSourceCode } -
branches/easy compiler/USourceExecutor.pas
r144 r145 12 12 TInputEvent = function: string of object; 13 13 14 { TExecutorVariable } 15 14 16 TExecutorVariable = class 15 17 Variable: TSourceVariable; 16 18 Value: TSourceValue; 19 destructor Destroy; override; 17 20 end; 18 21 … … 39 42 40 43 implementation 44 45 { TExecutorVariable } 46 47 destructor TExecutorVariable.Destroy; 48 begin 49 Value.Free; 50 inherited Destroy; 51 end; 41 52 42 53 … … 110 121 if Name = 'print' then begin 111 122 if Assigned(FOnOutput) then begin 112 Value := ReadValueReference( Parameters[0]);123 Value := ReadValueReference(TSourceReference(Parameters[0])); 113 124 if Value is TSourceValueString then 114 125 FOnOutput(TSourceValueString(Value).Value) … … 120 131 if Name = 'println' then begin 121 132 if Assigned(FOnOutput) then begin 122 Value := ReadValueReference( Parameters[0]);133 Value := ReadValueReference(TSourceReference(Parameters[0])); 123 134 if Value is TSourceValueString then 124 135 FOnOutput(TSourceValueString(Value).Value + LineEnding) … … 130 141 if Name = 'inputln' then begin 131 142 if Assigned(FOnInput) then begin 132 Variable := ReadVarReference( Parameters[0]);143 Variable := ReadVarReference(TSourceReference(Parameters[0])); 133 144 ExecutorVar := Variables.Search(Variable); 134 145 if ExecutorVar.Value is TSourceValueString then begin … … 147 158 end else 148 159 if Name = 'assign' then begin 149 Variable := ReadVarReference( Parameters[0]);150 Value := ReadValueReference( Parameters[1]);160 Variable := ReadVarReference(TSourceReference(Parameters[0])); 161 Value := ReadValueReference(TSourceReference(Parameters[1])); 151 162 ExecutorVar := Variables.Search(Variable); 152 163 if not Assigned(ExecutorVar) then begin … … 159 170 end else 160 171 if Name = 'increment' then begin 161 Variable := ReadVarReference( Parameters[0]);162 Value := ReadValueReference( Parameters[1]);172 Variable := ReadVarReference(TSourceReference(Parameters[0])); 173 Value := ReadValueReference(TSourceReference(Parameters[1])); 163 174 ExecutorVar := Variables.Search(Variable); 164 175 if not Assigned(ExecutorVar) then raise Exception.Create('Variable not found'); -
branches/easy compiler/USourceGenerator.pas
r143 r145 81 81 with TSourceFunctionCall(Instruction) do begin 82 82 if Name = 'print' then begin 83 Result := Result + IndentStr + 'Write(' + GenerateRef( Parameters[0]) + ');' +83 Result := Result + IndentStr + 'Write(' + GenerateRef(TSourceReference(Parameters[0])) + ');' + 84 84 LineEnding; 85 85 end else 86 86 if Name = 'println' then begin 87 Result := Result + IndentStr + 'WriteLn(' + GenerateRef( Parameters[0]) + ');' +87 Result := Result + IndentStr + 'WriteLn(' + GenerateRef(TSourceReference(Parameters[0])) + ');' + 88 88 LineEnding; 89 89 end else 90 90 if Name = 'assign' then begin 91 Result := Result + IndentStr + GenerateRef( Parameters[0]) + ' := ' +92 GenerateRef( Parameters[1]) + ';' + LineEnding;91 Result := Result + IndentStr + GenerateRef(TSourceReference(Parameters[0])) + ' := ' + 92 GenerateRef(TSourceReference(Parameters[1])) + ';' + LineEnding; 93 93 end else 94 94 if Name = 'inputln' then begin 95 Result := Result + IndentStr + 'ReadLn(' + GenerateRef( Parameters[0]) + ');' + LineEnding;95 Result := Result + IndentStr + 'ReadLn(' + GenerateRef(TSourceReference(Parameters[0])) + ');' + LineEnding; 96 96 end else 97 97 if Name = 'increment' then begin 98 Result := Result + IndentStr + 'Inc(' + GenerateRef( Parameters[0]) + ', ' +99 GenerateRef( Parameters[1]) + ');' + LineEnding;98 Result := Result + IndentStr + 'Inc(' + GenerateRef(TSourceReference(Parameters[0])) + ', ' + 99 GenerateRef(TSourceReference(Parameters[1])) + ');' + LineEnding; 100 100 end else 101 101 raise Exception.Create('Unsupported instruction name.'); -
branches/easy compiler/project1.lpi
r140 r145 12 12 <Icon Value="0"/> 13 13 </General> 14 <BuildModes Count="1"> 15 <Item1 Name="Default" Default="True"/> 14 <BuildModes Count="2"> 15 <Item1 Name="Debug" Default="True"/> 16 <Item2 Name="Release"> 17 <CompilerOptions> 18 <Version Value="11"/> 19 <PathDelim Value="\"/> 20 <Target> 21 <Filename Value="project1"/> 22 </Target> 23 <SearchPaths> 24 <IncludeFiles Value="$(ProjOutDir)"/> 25 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 26 </SearchPaths> 27 <Parsing> 28 <SyntaxOptions> 29 <SyntaxMode Value="Delphi"/> 30 <CStyleOperator Value="False"/> 31 <AllowLabel Value="False"/> 32 <CPPInline Value="False"/> 33 </SyntaxOptions> 34 </Parsing> 35 <CodeGeneration> 36 <SmartLinkUnit Value="True"/> 37 <Optimizations> 38 <OptimizationLevel Value="3"/> 39 </Optimizations> 40 </CodeGeneration> 41 <Linking> 42 <Debugging> 43 <GenerateDebugInfo Value="False"/> 44 </Debugging> 45 <LinkSmart Value="True"/> 46 <Options> 47 <Win32> 48 <GraphicApplication Value="True"/> 49 </Win32> 50 </Options> 51 </Linking> 52 <Other> 53 <CompilerMessages> 54 <IgnoredMessages idx5024="True"/> 55 </CompilerMessages> 56 </Other> 57 </CompilerOptions> 58 </Item2> 16 59 </BuildModes> 17 60 <PublishOptions> … … 75 118 <SyntaxOptions> 76 119 <SyntaxMode Value="Delphi"/> 120 <CStyleOperator Value="False"/> 77 121 <IncludeAssertionCode Value="True"/> 122 <AllowLabel Value="False"/> 123 <CPPInline Value="False"/> 78 124 </SyntaxOptions> 79 125 </Parsing> … … 88 134 </CodeGeneration> 89 135 <Linking> 136 <Debugging> 137 <UseHeaptrc Value="True"/> 138 </Debugging> 90 139 <Options> 91 140 <Win32> … … 98 147 <IgnoredMessages idx5024="True"/> 99 148 </CompilerMessages> 149 <CustomOptions Value="-dDEBUG"/> 100 150 </Other> 101 151 </CompilerOptions> -
branches/easy compiler/project1.lpr
r140 r145 9 9 Interfaces, // this includes the LCL widgetset 10 10 Forms, UFormMain, UCompiler, USourceCode, UTargetCode, USourceExecutor, USourceGenerator 11 { you can add units after this } ;12 11 { you can add units after this }, 12 SysUtils; 13 13 {$R *.res} 14 14 15 {$IFDEF DEBUG} 16 const 17 HeapTraceLog = 'heaptrclog.trc'; 18 {$ENDIF} 19 20 15 21 begin 22 {$IFDEF DEBUG} 23 // Heap trace 24 DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog); 25 SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog); 26 {$ENDIF} 27 16 28 RequireDerivedFormResource:=True; 17 29 Application.Initialize;
Note:
See TracChangeset
for help on using the changeset viewer.