Refactoring
This commit is contained in:
@@ -245,51 +245,16 @@ begin
|
|||||||
(Node as TIdentifierNode).Address := TResolvedAddress.Create(akUpvalue, 0, upvalueIndex);
|
(Node as TIdentifierNode).Address := TResolvedAddress.Create(akUpvalue, 0, upvalueIndex);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(Node as TIdentifierNode).Address := TResolvedAddress.Create(akLocalOrParent, depth, idx);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise Exception.CreateFmt('Undefined identifier: "%s"', [identNode.Name]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
(*
|
|
||||||
function TAstBinder.VisitIdentifier(const Node: IIdentifierNode): TDataValue;
|
|
||||||
var
|
|
||||||
depth, idx: Integer;
|
|
||||||
identNode: TIdentifierNode;
|
|
||||||
upvalue: TUpvalueMapping;
|
|
||||||
originalAddress: TResolvedAddress;
|
|
||||||
upvalueIndex: Integer;
|
|
||||||
begin
|
|
||||||
identNode := Node as TIdentifierNode;
|
|
||||||
if identNode.Address.Kind <> akUnresolved then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
if FCurrentDescriptor.FindSymbol(identNode.Name, depth, idx) then
|
|
||||||
begin
|
|
||||||
if (depth > 0) and (FUpvalueStack.Count > 0) then
|
|
||||||
begin
|
begin
|
||||||
upvalue := FUpvalueStack.Peek;
|
// 1. case: depth=0 - this is a local var
|
||||||
|
// 2. case: UpvalueStack is empty - there is no surrounding lambda, we need to reference (and capture) the whole parent scope
|
||||||
// Address is relative to the lambda's parent scope.
|
(Node as TIdentifierNode).Address := TResolvedAddress.Create(akLocalOrParent, depth, idx);
|
||||||
dec(depth);
|
end;
|
||||||
originalAddress.Create(akLocalOrParent, depth, idx);
|
|
||||||
|
|
||||||
if not upvalue.Map.TryGetValue(originalAddress, upvalueIndex) then
|
|
||||||
begin
|
|
||||||
upvalueIndex := upvalue.Nodes.Count;
|
|
||||||
upvalue.Map.Add(originalAddress, upvalueIndex);
|
|
||||||
upvalue.Nodes.Add(identNode);
|
|
||||||
end;
|
|
||||||
|
|
||||||
(Node as TIdentifierNode).Address.Create(akUpvalue, 0, upvalueIndex);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
(Node as TIdentifierNode).Address.Create(akLocalOrParent, depth, idx);
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise Exception.CreateFmt('Undefined identifier: "%s"', [identNode.Name]);
|
raise Exception.CreateFmt('Undefined identifier: "%s"', [identNode.Name]);
|
||||||
end;
|
end;
|
||||||
*)
|
|
||||||
function TAstBinder.VisitIfExpression(const Node: IIfExpressionNode): TDataValue;
|
function TAstBinder.VisitIfExpression(const Node: IIfExpressionNode): TDataValue;
|
||||||
begin
|
begin
|
||||||
// The condition is never in a tail position.
|
// The condition is never in a tail position.
|
||||||
|
|||||||
Reference in New Issue
Block a user