paxCompiler/help/demo_debug.htm
Dalibor Marković 9d0de424e8
Init
Signed-off-by: Dalibor Marković <dalibor31@gmail.com>
2024-07-06 22:28:12 +02:00

290 lines
12 KiB
HTML

<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H2>
paxCompiler for Delphi. Debug demo.
</H2>
<hr>
<img src="debug.jpg" border="0" alt ="Debug demo" ></img>
<blockquote>
<pre>
<font color="blue"><b>unit</b></font> Unit1;
<font color="blue"><b>interface</b></font>
<font color="blue"><b>uses</b></font>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, PaxProgram, PaxCompiler, PaxCompilerDebugger,
PaxCompilerExplorer;
<font color="blue"><b>type</b></font>
TForm1 = <font color="blue"><b>class</b></font>(TForm)
Memo1: TMemo;
Memo2: TMemo;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
PaxCompiler1: TPaxCompiler;
PaxPascalLanguage1: TPaxPascalLanguage;
PaxProgram1: TPaxProgram;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
PaxCompilerDebugger1: TPaxCompilerDebugger;
PaxCompilerExplorer1: TPaxCompilerExplorer;
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> Button2Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> Button3Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> Button4Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> Button5Click(Sender: TObject);
<font color="blue"><b>private</b></font>
{ Private declarations }
<font color="blue"><b>procedure</b></font> Trace(RunMode: Integer);
<font color="blue"><b>public</b></font>
{ Public declarations }
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
Form1: TForm1;
<font color="blue"><b>implementation</b></font>
<font color="blue"><b>uses</b></font> IMPORT_Classes, Unit2;
{$R *.dfm}
<font color="blue"><b>procedure</b></font> TForm1.Button1Click(Sender: TObject);
<font color="blue"><b>var</b></font>
I: Integer;
<font color="blue"><b>begin</b></font>
PaxCompiler1.Reset;
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
PaxCompiler1.AddModule(<font color="Red">'1'</font>, PaxPascalLanguage1.LanguageName);
PaxCompiler1.AddCode(<font color="Red">'1'</font>, Memo1.Lines.Text);
PaxCompiler1.DebugMode := true;
<font color="blue"><b>if</b></font> PaxCompiler1.Compile(PaxProgram1) <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
ShowMessage(<font color="Red">'Script has been successfully recompiled.'</font>);
PaxCompilerExplorer1.RegisterCompiler(PaxCompiler1);
PaxCompilerDebugger1.RegisterCompiler(PaxCompiler1, PaxProgram1);
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font>
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> PaxCompiler1.ErrorCount - 1 <font color="blue"><b>do</b></font>
ShowMessage(PaxCompiler1.ErrorMessage[I]);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.Button2Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
Trace(_rmRUN);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.Button3Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
Trace(_rmTRACE_INTO);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.Button4Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
Trace(_rmSTEP_OVER);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.Button5Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
<font color="blue"><b>if</b></font> <font color="blue"><b>not</b></font> PaxCompilerDebugger1.Valid <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
ShowMessage(<font color="Red">'You have to compile script. Press <font color="Red">"Compile"</font> button.'</font>);
Exit;
<font color="blue"><b>end</b></font>;
Form2.ShowModal;
<font color="blue"><b>if</b></font> Form2.ModalResult = mrOK <font color="blue"><b>then</b></font>
Trace(_rmRUN_TO_CURSOR);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.Trace(RunMode: Integer);
<font color="blue"><b>procedure</b></font> AddFields(StackFrameNumber, Id: Integer);
<font color="blue"><b>var</b></font>
I, K: Integer;
OwnerName, S: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
K := PaxCompilerExplorer1.GetFieldCount(Id);
<font color="blue"><b>if</b></font> K = 0 <font color="blue"><b>then</b></font>
Exit;
OwnerName := PaxCompilerExplorer1.Names[Id];
<font color="blue"><b>if</b></font> PaxCompilerDebugger1.GetValueAsString(Id) = <font color="Red">'nil'</font> <font color="blue"><b>then</b></font>
Exit;
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> K - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
S := OwnerName + <font color="Red">'.'</font> + PaxCompilerExplorer1.GetFieldName(Id, I);
S := <font color="Red">' '</font> + S + <font color="Red">'='</font> + PaxCompilerDebugger1.GetFieldValueAsString(
StackFrameNumber, Id, I);
Memo2.Lines.Add(S);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> AddArrayElements(StackFrameNumber, Id: Integer);
<font color="blue"><b>var</b></font>
I, K1, K2: Integer;
OwnerName, S: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
<font color="blue"><b>if</b></font> <font color="blue"><b>not</b></font> PaxCompilerExplorer1.HasArrayType(Id) <font color="blue"><b>then</b></font>
Exit;
K1 := PaxCompilerExplorer1.GetArrayLowBound(Id);
K2 := PaxCompilerExplorer1.GetArrayHighBound(Id);
OwnerName := PaxCompilerExplorer1.Names[Id];
<font color="blue"><b>for</b></font> I:=K1 <font color="blue"><b>to</b></font> K2 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
S := OwnerName + <font color="Red">'['</font> + IntToStr(I) + <font color="Red">']'</font>;
S := <font color="Red">' '</font> + S + <font color="Red">'='</font> + PaxCompilerDebugger1.GetArrayItemValueAsString(
StackFrameNumber, Id, I);
Memo2.Lines.Add(S);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> AddDynArrayElements(StackFrameNumber, Id: Integer);
<font color="blue"><b>var</b></font>
I, L: Integer;
OwnerName, S: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
<font color="blue"><b>if</b></font> <font color="blue"><b>not</b></font> PaxCompilerExplorer1.HasDynArrayType(Id) <font color="blue"><b>then</b></font>
Exit;
L := PaxCompilerDebugger1.GetDynArrayLength(StackFrameNumber, Id);
OwnerName := PaxCompilerExplorer1.Names[Id];
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> L - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
S := OwnerName + <font color="Red">'['</font> + IntToStr(I) + <font color="Red">']'</font>;
S := <font color="Red">' '</font> + S + <font color="Red">'='</font> + PaxCompilerDebugger1.GetDynArrayItemValueAsString(
StackFrameNumber, Id, I);
Memo2.Lines.Add(S);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
SourceLineNumber: Integer;
ModuleName: <font color="blue"><b>String</b></font>;
StackFrameNumber, J, K, SubId, Id: Integer;
S, V: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
<font color="blue"><b>if</b></font> <font color="blue"><b>not</b></font> PaxCompilerDebugger1.Valid <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
ShowMessage(<font color="Red">'You have to compile script. Press <font color="Red">"Compile"</font> button.'</font>);
Exit;
<font color="blue"><b>end</b></font>;
PaxCompilerDebugger1.RunMode := RunMode;
PaxCompilerDebugger1.Run;
Memo2.Lines.Clear;
<font color="blue"><b>if</b></font> PaxCompilerDebugger1.IsPaused <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
ModuleName := PaxCompilerDebugger1.ModuleName;
SourceLineNumber := PaxCompilerDebugger1.SourceLineNumber;
Memo2.Lines.Add(<font color="Red">'Paused at line '</font> + IntTosTr(SourceLineNumber));
Memo2.Lines.Add(PaxCompiler1.Modules[ModuleName][SourceLineNumber]);
Memo2.Lines.Add(<font color="Red">'------------------------------------------------------'</font>);
<font color="blue"><b>if</b></font> PaxCompilerDebugger1.CallStackCount > 0 <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
Memo2.Lines.Add(<font color="Red">'Call stack:'</font>);
<font color="blue"><b>for</b></font> StackFrameNumber:=0 <font color="blue"><b>to</b></font> PaxCompilerDebugger1.CallStackCount - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
SubId := PaxCompilerDebugger1.CallStack[StackFrameNumber];
S := <font color="Red">'('</font>;
K := PaxCompilerExplorer1.GetParamCount(SubId);
<font color="blue"><b>for</b></font> J:=0 <font color="blue"><b>to</b></font> K - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
Id := PaxCompilerExplorer1.GetParamId(SubId, J);
V := PaxCompilerDebugger1.GetValueAsString(StackFrameNumber, Id);
S := S + V;
<font color="blue"><b>if</b></font> J < K - 1 <font color="blue"><b>then</b></font>
S := S + <font color="Red">','</font>;
<font color="blue"><b>end</b></font>;
S := PaxCompilerExplorer1.Names[SubId] + S + <font color="Red">')'</font>;
Memo2.Lines.Add(S);
<font color="blue"><b>end</b></font>;
Memo2.Lines.Add(<font color="Red">'------------------------------------------------------'</font>);
Memo2.Lines.Add(<font color="Red">'Local scope:'</font>);
StackFrameNumber := PaxCompilerDebugger1.CallStackCount - 1;
SubId := PaxCompilerDebugger1.CallStack[StackFrameNumber];
K := PaxCompilerExplorer1.GetLocalCount(SubId);
<font color="blue"><b>for</b></font> J:=0 <font color="blue"><b>to</b></font> K - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
Id := PaxCompilerExplorer1.GetLocalId(SubId, J);
V := PaxCompilerDebugger1.GetValueAsString(StackFrameNumber, Id);
S := PaxCompilerExplorer1.Names[Id] + <font color="Red">'='</font> + V;
Memo2.Lines.Add(S);
AddFields(StackFrameNumber, Id);
AddArrayElements(StackFrameNumber, Id);
AddDynArrayElements(StackFrameNumber, Id);
<font color="blue"><b>end</b></font>;
Memo2.Lines.Add(<font color="Red">'------------------------------------------------------'</font>);
<font color="blue"><b>end</b></font>;
Memo2.Lines.Add(<font color="Red">'Global scope:'</font>);
K := PaxCompilerExplorer1.GetGlobalCount(0);
<font color="blue"><b>for</b></font> J:=0 <font color="blue"><b>to</b></font> K - 1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
Id := PaxCompilerExplorer1.GetGlobalId(0, J);
V := PaxCompilerDebugger1.GetValueAsString(Id);
S := PaxCompilerExplorer1.Names[Id] + <font color="Red">'='</font> + V;
Memo2.Lines.Add(S);
AddFields(0, Id);
AddArrayElements(0, Id);
AddDynArrayElements(0, Id);
<font color="blue"><b>end</b></font>;
Memo2.Lines.Add(<font color="Red">'------------------------------------------------------'</font>);
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font>
Memo2.Lines.Add(<font color="Red">'Finished'</font>);
Memo2.SelStart := 0;
Memo2.SelLength := 0;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> Print(I: Integer);
<font color="blue"><b>begin</b></font>
ShowMessage(IntToStr(I));
<font color="blue"><b>end</b></font>;
<font color="blue"><b>initialization</b></font>
RegisterHeader(0, <font color="Red">'procedure Print(I: Integer);'</font>, @Print);
<font color="blue"><b>end</b></font>.
</pre>
</blockquote>
<p>
<HR>
<font size = 1 color ="gray">
Copyright &copy; 2006-2009
VIRT Laboratory. All rights reserved.
</font>
</body>
</html>