AST function purity analysis
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -26,7 +26,8 @@ uses
|
||||
Myc.Ast.Compiler.Macros in '..\Src\AST\Myc.Ast.Compiler.Macros.pas',
|
||||
Myc.Ast.Compiler.Specializer in '..\Src\AST\Myc.Ast.Compiler.Specializer.pas',
|
||||
Myc.Ast.Environment in '..\Src\AST\Myc.Ast.Environment.pas',
|
||||
Myc.Ast.Debugger in '..\Src\AST\Myc.Ast.Debugger.pas';
|
||||
Myc.Ast.Debugger in '..\Src\AST\Myc.Ast.Debugger.pas',
|
||||
Myc.Ast.Analysis.Purity in '..\Src\AST\Myc.Ast.Analysis.Purity.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Compiler.Specializer.pas"/>
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Environment.pas"/>
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Debugger.pas"/>
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Analysis.Purity.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
@@ -212,6 +213,12 @@
|
||||
<Overwrite>true</Overwrite>
|
||||
</Platform>
|
||||
</DeployFile>
|
||||
<DeployFile LocalName="Win64\Debug\ASTPlayground.rsm" Configuration="Debug" Class="DebugSymbols">
|
||||
<Platform Name="Win64">
|
||||
<RemoteName>ASTPlayground.rsm</RemoteName>
|
||||
<Overwrite>true</Overwrite>
|
||||
</Platform>
|
||||
</DeployFile>
|
||||
<DeployFile LocalName="Win64\Release\ASTPlayground.exe" Configuration="Release" Class="ProjectOutput">
|
||||
<Platform Name="Win64">
|
||||
<RemoteName>ASTPlayground.exe</RemoteName>
|
||||
|
||||
@@ -197,7 +197,7 @@ object Form1: TForm1
|
||||
'Expanded'
|
||||
'Bound'
|
||||
'Specialized')
|
||||
ItemIndex = 0
|
||||
ItemIndex = 3
|
||||
Position.X = 672.000000000000000000
|
||||
Position.Y = 576.000000000000000000
|
||||
Size.Width = 104.000000000000000000
|
||||
|
||||
@@ -110,7 +110,7 @@ type
|
||||
procedure RTLListViewChange(Sender: TObject);
|
||||
private
|
||||
FCurrUnboundAst: IAstNode;
|
||||
FCurrExec: TDataValue.TFunc;
|
||||
FCurrExec: TCompiledFunction;
|
||||
FEnvironment: TAstEnvironment;
|
||||
FWorkspace: TAuraWorkspace;
|
||||
FScriptUpdate: Boolean;
|
||||
@@ -262,7 +262,7 @@ end;
|
||||
function TForm1.ExecuteAst(const ANode: IAstNode): TDataValue;
|
||||
begin
|
||||
FCurrUnboundAst := ANode;
|
||||
FCurrExec := nil; // Clear previous
|
||||
FCurrExec := Default(TCompiledFunction);
|
||||
|
||||
// 1. Set strategy based on UI
|
||||
if DebugBox.IsChecked then
|
||||
@@ -273,12 +273,21 @@ begin
|
||||
try
|
||||
// Wrap in Lambda to compile
|
||||
var funcDef := TAst.LambdaExpr([], ANode);
|
||||
FCurrExec := FEnvironment.Compile(funcDef).Func;
|
||||
Result := FCurrExec([]);
|
||||
FCurrExec := FEnvironment.Compile(funcDef);
|
||||
|
||||
if Assigned(FCurrExec.Func) then
|
||||
begin
|
||||
Memo1.Lines.Add(
|
||||
Format('Compiled. Signature: %s, IsPure=%s', [FCurrExec.StaticType.ToString, BoolToStr(FCurrExec.IsPure, true)])
|
||||
);
|
||||
end;
|
||||
|
||||
Result := FCurrExec.Func([]);
|
||||
|
||||
except
|
||||
on E: Exception do
|
||||
begin
|
||||
FCurrExec.Func := nil;
|
||||
Memo1.Lines.Add('--- ERROR ---');
|
||||
Memo1.Lines.Add(E.ClassName + ': ' + E.Message);
|
||||
Result := TDataValue.Void;
|
||||
@@ -645,7 +654,7 @@ begin
|
||||
FCurrUnboundAst := converter.Deserialize(jsonObj);
|
||||
|
||||
// Run the full pipeline via environment
|
||||
FCurrExec := FEnvironment.Compile(FCurrUnboundAst).Func;
|
||||
FCurrExec := FEnvironment.Compile(FCurrUnboundAst);
|
||||
|
||||
Memo1.Lines.Add('AST deserialized and bound successfully from JSON.');
|
||||
Memo1.Lines.Add('You can now visualize it (Middle Mouse Click) or pretty-print it.');
|
||||
@@ -655,7 +664,6 @@ begin
|
||||
except
|
||||
on E: Exception do
|
||||
begin
|
||||
FCurrExec := nil;
|
||||
Memo1.Lines.Add('Error deserializing AST from JSON:');
|
||||
Memo1.Lines.Add(E.Message);
|
||||
Memo1.Lines.Add('--- Original JSON ---');
|
||||
@@ -675,7 +683,7 @@ var
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
|
||||
if not Assigned(FCurrExec) then
|
||||
if not Assigned(FCurrExec.Func) then
|
||||
begin
|
||||
Memo1.Lines.Add('No AST available to serialize. Please generate one first.');
|
||||
exit;
|
||||
@@ -703,7 +711,7 @@ begin
|
||||
Memo1.Lines.Clear;
|
||||
Memo1.Lines.Add('--- AST Dump ---');
|
||||
|
||||
if not Assigned(FCurrExec) then
|
||||
if not Assigned(FCurrExec.Func) then
|
||||
begin
|
||||
Memo1.Lines.Add('No *compiled* AST has been generated yet. Click a test button first.');
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user