RTL custom interface types as records, added callbacks (marshalled using virtual interfaces)
This commit is contained in:
@@ -114,6 +114,7 @@ type
|
||||
procedure RTLListViewChange(Sender: TObject);
|
||||
private
|
||||
FCurrUnboundAst: IAstNode;
|
||||
FCurrCompiled: ILambdaExpressionNode;
|
||||
FCurrExec: TCompiledFunction;
|
||||
FEnvironment: TAstEnvironment;
|
||||
FAstEditor: TAstEditor; // Die Komponente (Facade)
|
||||
@@ -141,6 +142,7 @@ implementation
|
||||
|
||||
uses
|
||||
Myc.Data.Scalar.JSON,
|
||||
Myc.Trade.Broker,
|
||||
System.Diagnostics, // For TStopwatch
|
||||
System.TimeSpan,
|
||||
Myc.Ast.Json, // For TAstJson serialization
|
||||
@@ -306,7 +308,8 @@ begin
|
||||
try
|
||||
// Use Compile directly. Errors will be raised as ECompilationFailed.
|
||||
// We catch them to print to log, but allow flow to continue so UI can be updated.
|
||||
FCurrExec := FEnvironment.Compile(ANode);
|
||||
FCurrCompiled := FEnvironment.Compile(ANode);
|
||||
FCurrExec := FEnvironment.Link(FCurrCompiled);
|
||||
|
||||
if Assigned(FCurrExec.Func) then
|
||||
begin
|
||||
@@ -599,7 +602,8 @@ begin
|
||||
|
||||
Memo1.Lines.Add('--- Naive recursive fib with AST---');
|
||||
|
||||
var fibExec := TestEnv.Compile(TAst.FunctionCall(TAst.Identifier('fib'), [TAst.Constant(25)])).Func;
|
||||
FCurrCompiled := TestEnv.Compile(TAst.FunctionCall(TAst.Identifier('fib'), [TAst.Constant(25)]));
|
||||
var fibExec := TestEnv.Link(FCurrCompiled).Func;
|
||||
|
||||
sw := TStopwatch.StartNew;
|
||||
result := fibExec([]);
|
||||
@@ -614,7 +618,7 @@ begin
|
||||
|
||||
memoizeTest.Define('fib', TAstScript.Parse('(Memoize fib)'));
|
||||
|
||||
var memoizeExec := memoizeTest.Compile(TAstScript.Parse('(fib 25)')).Func;
|
||||
var memoizeExec := memoizeTest.Link(memoizeTest.Compile(TAstScript.Parse('(fib 25)'))).Func;
|
||||
|
||||
sw := TStopwatch.StartNew;
|
||||
result := memoizeExec([]);
|
||||
@@ -757,7 +761,8 @@ begin
|
||||
FCurrUnboundAst := converter.Deserialize(jsonObj);
|
||||
|
||||
// Run the full pipeline via environment
|
||||
FCurrExec := FEnvironment.Compile(FCurrUnboundAst);
|
||||
FCurrCompiled := FEnvironment.Compile(FCurrUnboundAst);
|
||||
FCurrExec := FEnvironment.Link(FCurrCompiled);
|
||||
|
||||
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.');
|
||||
@@ -822,7 +827,7 @@ begin
|
||||
|
||||
var seriesAddress := env.RootScope.Define('current_series', TDataValue.Void);
|
||||
|
||||
var callExec := env.Compile(TAst.FunctionCall(TAst.Identifier('maCrossStrategy'), [TAst.Identifier('current_series')])).Func;
|
||||
var callExec := env.Link(env.Compile(TAst.FunctionCall(TAst.Identifier('maCrossStrategy'), [TAst.Identifier('current_series')]))).Func;
|
||||
|
||||
// Simulation Loop
|
||||
Memo1.Lines.Clear;
|
||||
@@ -1169,7 +1174,8 @@ end;
|
||||
procedure TForm1.Test1ButtonClick(Sender: TObject);
|
||||
begin
|
||||
FCurrUnboundAst := TAstScript.Parse('(do (print txt))');
|
||||
var fn := FEnvironment.Compile(FCurrUnboundAst, [TAst.Identifier('txt')]).Func;
|
||||
FCurrCompiled := FEnvironment.Compile(FCurrUnboundAst, [TAst.Identifier('txt')]);
|
||||
var fn := FEnvironment.Link(FCurrCompiled).Func;
|
||||
fn(['Hello World']);
|
||||
FEnvironment.RootScope.Define('fn', fn);
|
||||
UpdateScript;
|
||||
@@ -1247,14 +1253,17 @@ begin
|
||||
Memo1.Lines.Clear;
|
||||
Memo1.Lines.Add('--- AST Dump ---');
|
||||
|
||||
if FCurrUnboundAst = nil then
|
||||
if FCurrCompiled = nil then
|
||||
begin
|
||||
Memo1.Lines.Add('No AST available.');
|
||||
Memo1.Lines.Add('No compiled AST available.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
// Dump the raw unbound AST first
|
||||
TAstDumper.Dump(FCurrUnboundAst, Memo1.Lines);
|
||||
TAstDumper.Dump(FCurrCompiled, Memo1.Lines);
|
||||
end;
|
||||
|
||||
initialization
|
||||
TAst.RegisterLibrary(RegisterBroker);
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user