diff --git a/ASTPlayground/MainForm.pas b/ASTPlayground/MainForm.pas index 69b7c05..7d3c968 100644 --- a/ASTPlayground/MainForm.pas +++ b/ASTPlayground/MainForm.pas @@ -145,6 +145,7 @@ begin Memo1.Lines.Add(''); Memo1.Lines.Add(''); Memo1.Lines.Add('--- Recursive fib with AST---'); + Application.ProcessMessages; // Update UI before blocking sw.Start; root := diff --git a/Src/AST/Myc.Ast.Evaluator.pas b/Src/AST/Myc.Ast.Evaluator.pas index 0ca3c76..d644680 100644 --- a/Src/AST/Myc.Ast.Evaluator.pas +++ b/Src/AST/Myc.Ast.Evaluator.pas @@ -38,6 +38,7 @@ type procedure Indent; procedure Unindent; procedure AppendLine(const S: string); + procedure AppendMultiline(const S: string); procedure ShowScope; protected function CreateVisitorForScope(AScope: TExecutionScope): IAstVisitor; override; @@ -57,7 +58,8 @@ type implementation uses - Myc.Data.Decimal; + Myc.Data.Decimal, + Myc.Ast.Printer; type // Concrete implementation of the IEvaluatorClosure interface, private to this unit. @@ -349,6 +351,18 @@ begin FLog.Add(pad + S); end; +procedure TDebugEvaluatorVisitor.AppendMultiline(const S: string); +begin + var Str := TStringList.Create; + try + Str.Text := s; + for var i := 0 to Str.Count - 1 do + AppendLine(Str[i]); + finally + Str.Free; + end; +end; + procedure TDebugEvaluatorVisitor.ShowScope; var scopeDump: TArray; @@ -419,6 +433,11 @@ begin AppendLine('LambdaExpr{'); Indent; try + var pp: IAstVisitor := TPrettyPrintVisitor.Create(0); + pp.VisitLambdaExpression(Node); + + AppendMultiline((pp as TPrettyPrintVisitor).GetResult); + Result := inherited VisitLambdaExpression(Node); finally Unindent; diff --git a/Src/AST/Myc.Ast.Printer.pas b/Src/AST/Myc.Ast.Printer.pas index 226a7c4..f203862 100644 --- a/Src/AST/Myc.Ast.Printer.pas +++ b/Src/AST/Myc.Ast.Printer.pas @@ -17,7 +17,7 @@ type procedure Unindent; procedure AppendLine(const S: string); public - constructor Create; + constructor Create(AIndentLevel: Integer = 0); destructor Destroy; override; function GetResult: string; // IAstVisitor @@ -40,11 +40,12 @@ uses { TPrettyPrintVisitor } -constructor TPrettyPrintVisitor.Create; +constructor TPrettyPrintVisitor.Create(AIndentLevel: Integer); begin inherited Create; FBuilder := TStringBuilder.Create; FIndentLevel := 0; + FIndentLevel := AIndentLevel; end; destructor TPrettyPrintVisitor.Destroy; @@ -88,7 +89,7 @@ end; function TPrettyPrintVisitor.VisitBinaryExpression(const Node: IBinaryExpressionNode): TAstValue; begin - AppendLine(Format('BinaryExpr (%s)', [Node.Operator.ToString])); + AppendLine(Format('BinaryExpr "%s"', [Node.Operator.ToString])); Indent; Node.Left.Accept(Self); Node.Right.Accept(Self); @@ -98,7 +99,7 @@ end; function TPrettyPrintVisitor.VisitUnaryExpression(const Node: IUnaryExpressionNode): TAstValue; begin - AppendLine(Format('UnaryExpr (%s)', [Node.Operator.ToString])); + AppendLine(Format('UnaryExpr "%s"', [Node.Operator.ToString])); Indent; Node.Right.Accept(Self); Unindent;