RTL custom interface types as records, added callbacks (marshalled using virtual interfaces)
This commit is contained in:
@@ -54,8 +54,8 @@ type
|
||||
const Node: IFunctionDefinition;
|
||||
const ArgTypes: TArray<IStaticType> = [];
|
||||
const Log: ICompilerLog = nil
|
||||
): TCompiledFunction;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog): TCompiledFunction;
|
||||
): ILambdaExpressionNode;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog = nil): TCompiledFunction;
|
||||
|
||||
function CreateEnvironment: IEnvironment;
|
||||
|
||||
@@ -93,9 +93,9 @@ type
|
||||
const Node: IAstNode;
|
||||
const Params: TArray<IIdentifierNode> = [];
|
||||
const ArgTypes: TArray<IStaticType> = []
|
||||
): TCompiledFunction; overload;
|
||||
function Compile(const Node: IFunctionDefinition; const ArgTypes: TArray<IStaticType> = []): TCompiledFunction; overload;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog): TCompiledFunction;
|
||||
): ILambdaExpressionNode; overload;
|
||||
function Compile(const Node: IFunctionDefinition; const ArgTypes: TArray<IStaticType> = []): ILambdaExpressionNode; overload;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog = nil): TCompiledFunction;
|
||||
|
||||
function Run(const ANode: IAstNode; const Params: TArray<IIdentifierNode> = []; const Args: TArray<TDataValue> = []): TDataValue;
|
||||
|
||||
@@ -193,8 +193,8 @@ type
|
||||
const Node: IFunctionDefinition;
|
||||
const ArgTypes: TArray<IStaticType>;
|
||||
const Log: ICompilerLog = nil
|
||||
): TCompiledFunction;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog): TCompiledFunction;
|
||||
): ILambdaExpressionNode;
|
||||
function Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog = nil): TCompiledFunction;
|
||||
end;
|
||||
|
||||
{ TAstEnvironment }
|
||||
@@ -235,12 +235,12 @@ function TAstEnvironment.Compile(
|
||||
const Node: IAstNode;
|
||||
const Params: TArray<IIdentifierNode> = [];
|
||||
const ArgTypes: TArray<IStaticType> = []
|
||||
): TCompiledFunction;
|
||||
): ILambdaExpressionNode;
|
||||
begin
|
||||
Result := FEnvironment.Compile(TAst.LambdaExpr(Params, Node), ArgTypes);
|
||||
end;
|
||||
|
||||
function TAstEnvironment.Compile(const Node: IFunctionDefinition; const ArgTypes: TArray<IStaticType> = []): TCompiledFunction;
|
||||
function TAstEnvironment.Compile(const Node: IFunctionDefinition; const ArgTypes: TArray<IStaticType> = []): ILambdaExpressionNode;
|
||||
begin
|
||||
Result := FEnvironment.Compile(Node, ArgTypes);
|
||||
end;
|
||||
@@ -263,7 +263,8 @@ end;
|
||||
procedure TAstEnvironment.Define(const Name: String; const AScript: IAstNode);
|
||||
begin
|
||||
var compiled := Compile(AScript);
|
||||
RootScope.Define(Name, compiled.Func([]), compiled.StaticType);
|
||||
var linked := Link(compiled);
|
||||
RootScope.Define(Name, linked.Func([]), compiled.StaticType);
|
||||
end;
|
||||
|
||||
function TAstEnvironment.ExpandMacros(const Node: IAstNode): IAstNode;
|
||||
@@ -281,7 +282,7 @@ begin
|
||||
Result := FEnvironment.GetMacroRegistry;
|
||||
end;
|
||||
|
||||
function TAstEnvironment.Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog): TCompiledFunction;
|
||||
function TAstEnvironment.Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog = nil): TCompiledFunction;
|
||||
begin
|
||||
Result := FEnvironment.Link(Node, Log);
|
||||
end;
|
||||
@@ -292,7 +293,7 @@ function TAstEnvironment.Run(
|
||||
const Args: TArray<TDataValue> = []
|
||||
): TDataValue;
|
||||
begin
|
||||
Result := Compile(ANode, Params).Func(Args);
|
||||
Result := Link(Compile(ANode, Params)).Func(Args);
|
||||
end;
|
||||
|
||||
function TAstEnvironment.Specialize(const Node: IAstNode): IAstNode;
|
||||
@@ -404,7 +405,7 @@ function TEnvironment.Compile(
|
||||
const Node: IFunctionDefinition;
|
||||
const ArgTypes: TArray<IStaticType>;
|
||||
const Log: ICompilerLog = nil
|
||||
): TCompiledFunction;
|
||||
): ILambdaExpressionNode;
|
||||
var
|
||||
layout: IScopeLayout;
|
||||
lg: ICompilerLog;
|
||||
@@ -428,10 +429,10 @@ begin
|
||||
|
||||
var specialized := Specialize(typedNode);
|
||||
|
||||
Result := Link(specialized.AsLambdaExpression, lg);
|
||||
Result := specialized.AsLambdaExpression;
|
||||
end;
|
||||
|
||||
function TEnvironment.Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog): TCompiledFunction;
|
||||
function TEnvironment.Link(const Node: ILambdaExpressionNode; const Log: ICompilerLog = nil): TCompiledFunction;
|
||||
var
|
||||
descriptor: IScopeDescriptor;
|
||||
funcType: IStaticType;
|
||||
@@ -516,7 +517,7 @@ begin
|
||||
FFunctionRegistry,
|
||||
function(const Node: IFunctionDefinition; const ArgTypes: TArray<IStaticType>): TCompiledFunction
|
||||
begin
|
||||
Result := Compile(Node, ArgTypes);
|
||||
Result := Link(Compile(Node, ArgTypes));
|
||||
end
|
||||
);
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user