Changeset 56


Ignore:
Timestamp:
Jul 13, 2012, 2:10:18 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Slightly enhanced unfinished interpretter.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Target/Interpretter/UTargetInterpretter.pas

    r52 r56  
    3232    procedure RunAssignment(Assignment: TAssignment);
    3333    procedure RunCaseOfEnd(CaseOfEnd: TCaseOfEnd);
    34     procedure RunFunction(FunctionCall: TFunctionCall);
     34    function RunFunction(FunctionCall: TFunctionCall): TValue;
    3535    procedure RunForToDo(ForToDo: TForToDo);
    36     function Evaluate(Expression: TExpression): Boolean;
     36    function Evaluate(Expression: TExpression): TValue;
    3737  public
    3838    Variables: TListObject;
     
    5050resourcestring
    5151  SUnknownCommandType = 'Unknown command type';
     52  SUnknownOperator = 'Unknown operator "%s"';
    5253
    5354{ TExecutorInterpretter }
     
    9495procedure TExecutorInterpretter.RunAssignment(Assignment: TAssignment);
    9596begin
    96   //Assignment.Target := Assignment.Source;
     97  Assignment.Target.Value := Evaluate(Assignment.Source);
    9798end;
    9899
     
    111112end;
    112113
    113 procedure TExecutorInterpretter.RunFunction(FunctionCall: TFunctionCall);
     114function TExecutorInterpretter.RunFunction(FunctionCall: TFunctionCall): TValue;
    114115begin
    115116  RunBeginEnd(FunctionCall.FunctionRef.Code);
     
    126127end;
    127128
    128 function TExecutorInterpretter.Evaluate(Expression: TExpression): Boolean;
     129function TExecutorInterpretter.Evaluate(Expression: TExpression): TValue;
    129130begin
    130 //  case Expression.NodeType of
    131 //    ntConstant: ;
    132 //  end;
     131  with Expression do
     132  case NodeType of
     133    ntConstant: Result := Constant.Value;
     134    ntFunction: Result := RunFunction(FunctionCall);
     135    ntOperator: begin
     136      if OperatorName = '>' then
     137        Result := Evaluate(TExpression(SubItems.First)) > Evaluate(TExpression(SubItems.Last))
     138      else if OperatorName = '<' then
     139        Result := Evaluate(TExpression(SubItems.First)) < Evaluate(TExpression(SubItems.Last))
     140      else if OperatorName = '+' then
     141        Result := Evaluate(TExpression(SubItems.First)) + Evaluate(TExpression(SubItems.Last))
     142      else if OperatorName = '-' then
     143        Result := Evaluate(TExpression(SubItems.First)) - Evaluate(TExpression(SubItems.Last))
     144      else if OperatorName = '*' then
     145        Result := Evaluate(TExpression(SubItems.First)) * Evaluate(TExpression(SubItems.Last))
     146      else if OperatorName = 'div' then
     147        Result := Evaluate(TExpression(SubItems.First)) div Evaluate(TExpression(SubItems.Last))
     148        else raise Exception.CreateFmt(SUnknownOperator, [OperatorName]);
     149    end;
     150    ntVariable: Result := Variable.Value;
     151  end;
    133152end;
    134153
  • trunk/Compiler/TranspascalCompiler.lpk

    r44 r56  
    4040      </Item3>
    4141      <Item4>
     42        <Filename Value="UAnalyzer.pas"/>
     43        <UnitName Value="UAnalyzer"/>
     44      </Item4>
     45      <Item5>
     46        <Filename Value="UTarget.pas"/>
     47        <UnitName Value="UTarget"/>
     48      </Item5>
     49      <Item6>
     50        <Filename Value="UExecutor.pas"/>
     51        <UnitName Value="UExecutor"/>
     52      </Item6>
     53      <Item7>
     54        <Filename Value="Analyze\UAnalyzerPascal.pas"/>
     55        <UnitName Value="UAnalyzerPascal"/>
     56      </Item7>
     57      <Item8>
     58        <Filename Value="Target\Dynamic C\UProducerDynamicc.pas"/>
     59        <UnitName Value="UProducerDynamicC"/>
     60      </Item8>
     61      <Item9>
    4262        <Filename Value="Target\ASM8051\UProducerASM8051.pas"/>
    4363        <UnitName Value="UProducerAsm8051"/>
    44       </Item4>
    45       <Item5>
    46         <Filename Value="Target\Dynamic C\UProducerDynamicc.pas"/>
    47         <UnitName Value="UProducerDynamicC"/>
    48       </Item5>
    49       <Item6>
     64      </Item9>
     65      <Item10>
     66        <Filename Value="Target\GCC\UProducerGCC.pas"/>
     67        <UnitName Value="UProducerGCC"/>
     68      </Item10>
     69      <Item11>
     70        <Filename Value="Target\UTargets.pas"/>
     71        <UnitName Value="UTargets"/>
     72      </Item11>
     73      <Item12>
    5074        <Filename Value="Target\Delphi\UProducerPascal.pas"/>
    5175        <UnitName Value="UProducerPascal"/>
    52       </Item6>
    53       <Item7>
    54         <Filename Value="Target\GCC\UProducerGCC.pas"/>
    55         <UnitName Value="UProducerGCC"/>
    56       </Item7>
    57       <Item8>
    58         <Filename Value="UAnalyzer.pas"/>
    59         <UnitName Value="UAnalyzer"/>
    60       </Item8>
    61       <Item9>
    62         <Filename Value="Analyze\UAnalyzerPascal.pas"/>
    63         <UnitName Value="UAnalyzerPascal"/>
    64       </Item9>
    65       <Item10>
    66         <Filename Value="UTarget.pas"/>
    67         <UnitName Value="UTarget"/>
    68       </Item10>
    69       <Item11>
    70         <Filename Value="UExecutor.pas"/>
    71         <UnitName Value="UExecutor"/>
    72       </Item11>
    73       <Item12>
    74         <Filename Value="Target\UTargets.pas"/>
    75         <UnitName Value="UTargets"/>
    7676      </Item12>
    7777      <Item13>
  • trunk/Compiler/TranspascalCompiler.pas

    r42 r56  
    88
    99uses
    10   UCompiler, USourceCode, UProducer, UProducerASM8051, UProducerDynamicc,
    11   UProducerPascal, UProducerGCC, UAnalyzer, UAnalyzerPascal, UTarget,
    12   UExecutor, UTargets, UTargetInterpretter, UTargetDelphi, UTargetPHP,
     10  UCompiler, USourceCode, UProducer, UAnalyzer, UTarget, UExecutor,
     11  UAnalyzerPascal, UProducerDynamicc, UProducerASM8051, UProducerGCC,
     12  UTargets, UProducerPascal, UTargetInterpretter, UTargetDelphi, UTargetPHP,
    1313  UTargetJava, UTargetXML, UTargetASM8051, UTargetGCC, LazarusPackageIntf;
    1414
  • trunk/Compiler/USourceCode.pas

    r51 r56  
    253253    DefaultValue: TValue;
    254254    Exported: Boolean;
     255    Value: TValue; // runtime
    255256  end;
    256257
  • trunk/IDE/Forms/UFormProject.lfm

    r55 r56  
    4747    object ADelete: TAction
    4848      Caption = 'Delete'
     49      OnExecute = ADeleteExecute
    4950    end
    5051    object ARename: TAction
    5152      Caption = 'Rename'
     53      OnExecute = ARenameExecute
    5254    end
    5355    object AShow: TAction
    5456      Caption = 'Show'
     57      OnExecute = AShowExecute
    5558    end
    5659  end
  • trunk/IDE/Forms/UFormProject.pas

    r55 r56  
    2525    TreeViewProject: TTreeView;
    2626    procedure AAddExecute(Sender: TObject);
     27    procedure ADeleteExecute(Sender: TObject);
     28    procedure ARenameExecute(Sender: TObject);
     29    procedure AShowExecute(Sender: TObject);
    2730    procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
    2831  private
     
    9093end;
    9194
     95procedure TFormProject.ADeleteExecute(Sender: TObject);
     96begin
     97
     98end;
     99
     100procedure TFormProject.ARenameExecute(Sender: TObject);
     101begin
     102
     103end;
     104
     105procedure TFormProject.AShowExecute(Sender: TObject);
     106begin
     107
     108end;
     109
    92110procedure TFormProject.UpdateProjectTree;
    93111var
Note: See TracChangeset for help on using the changeset viewer.