Bind Variables
This commit is contained in:
parent
ac83dba77f
commit
05d0de31a0
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
using Upsilon.Parser;
|
using Upsilon.Parser;
|
||||||
using Type = Upsilon.BaseTypes.Type;
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
@ -38,7 +37,7 @@ namespace Upsilon.Binder
|
||||||
case SyntaxKind.AssignmentExpression:
|
case SyntaxKind.AssignmentExpression:
|
||||||
return BindAssignmentExpression((AssignmentExpressionSyntax) e);
|
return BindAssignmentExpression((AssignmentExpressionSyntax) e);
|
||||||
case SyntaxKind.VariableExpression:
|
case SyntaxKind.VariableExpression:
|
||||||
break;
|
return BindVariableExpression((VariableExpressionSyntax) e);
|
||||||
case SyntaxKind.BadExpression:
|
case SyntaxKind.BadExpression:
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.ScriptUnit:
|
case SyntaxKind.ScriptUnit:
|
||||||
|
@ -130,5 +129,17 @@ namespace Upsilon.Binder
|
||||||
|
|
||||||
return new BoundAssignmenExpression(variable, boundExpression);
|
return new BoundAssignmenExpression(variable, boundExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BoundExpression BindVariableExpression(VariableExpressionSyntax e)
|
||||||
|
{
|
||||||
|
var name = e.Identifier.Name;
|
||||||
|
if (!_scope.TryGetVariable(name, out var variable))
|
||||||
|
{
|
||||||
|
_diagnostics.LogUnknownVariable(e.Identifier.Span, name);
|
||||||
|
return new BoundLiteralExpression(null, Type.Nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BoundVariableExpression(variable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ namespace Upsilon.Binder
|
||||||
BoundLiteralExpression,
|
BoundLiteralExpression,
|
||||||
BoundBinaryExpression,
|
BoundBinaryExpression,
|
||||||
BoundUnaryExpression,
|
BoundUnaryExpression,
|
||||||
BoundAssignmentExpression
|
BoundAssignmentExpression,
|
||||||
|
VariableExpression
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
|
namespace Upsilon.Binder
|
||||||
|
{
|
||||||
|
public class BoundVariableExpression : BoundExpression
|
||||||
|
{
|
||||||
|
public BoundVariableExpression(VariableSymbol variable)
|
||||||
|
{
|
||||||
|
Variable = variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VariableSymbol Variable { get; }
|
||||||
|
public override BoundKind Kind => BoundKind.VariableExpression;
|
||||||
|
public override Type Type => Variable.Type;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue