AST testing
This commit is contained in:
@@ -168,6 +168,7 @@ begin
|
||||
TScalar.TKind.Ordinal: Result := AValue.AsScalar.Value.AsInt64 <> 0;
|
||||
TScalar.TKind.Float: Result := AValue.AsScalar.Value.AsDouble <> 0.0;
|
||||
TScalar.TKind.Keyword: Result := AValue.AsScalar.Value.AsInt64 <> 0;
|
||||
TScalar.TKind.Boolean: Result := AValue.AsScalar.Value.AsInt64 <> 0;
|
||||
else
|
||||
Result := false;
|
||||
end;
|
||||
@@ -392,10 +393,13 @@ end;
|
||||
|
||||
function TEvaluatorVisitor.VisitAssignment(const Node: IAssignmentNode): TDataValue;
|
||||
begin
|
||||
// Evaluate the new value.
|
||||
if Node.Target.Kind <> akIdentifier then
|
||||
raise ETypeException.Create('Runtime Error: Assignment target must be an identifier.');
|
||||
|
||||
// Evaluate value
|
||||
Result := Node.Value.Accept(Self);
|
||||
// Assign it.
|
||||
FScope[Node.Identifier.Address] := Result;
|
||||
// Assign
|
||||
FScope[Node.Target.AsIdentifier.Address] := Result;
|
||||
end;
|
||||
|
||||
function TEvaluatorVisitor.VisitConstant(const Node: IConstantNode): TDataValue;
|
||||
@@ -561,6 +565,9 @@ function TEvaluatorVisitor.VisitVariableDeclaration(const Node: IVariableDeclara
|
||||
var
|
||||
address: TResolvedAddress;
|
||||
begin
|
||||
if Node.Target.Kind <> akIdentifier then
|
||||
raise ETypeException.Create('Runtime Error: Variable declaration target must be an identifier.');
|
||||
|
||||
// 1. Evaluate Initializer
|
||||
if Assigned(Node.Initializer) then
|
||||
Result := Node.Initializer.Accept(Self)
|
||||
@@ -568,7 +575,7 @@ begin
|
||||
Result := TDataValue.Void;
|
||||
|
||||
// 2. Get Address (assigned by Binder)
|
||||
address := Node.Identifier.Address;
|
||||
address := Node.Target.AsIdentifier.Address;
|
||||
|
||||
// 3. Store Value
|
||||
if Node.IsBoxed then
|
||||
|
||||
Reference in New Issue
Block a user