Fix Ycicle arguments not persisting
This commit is contained in:
parent
7c6d847adb
commit
62f31ef0d3
|
@ -16,10 +16,10 @@ namespace Upsilon.Binder
|
|||
private Dictionary<FunctionVariableSymbol, UnboundFunctionStatement> _unboundFunctions =
|
||||
new Dictionary<FunctionVariableSymbol, UnboundFunctionStatement>();
|
||||
|
||||
public Binder(Diagnostics diagnostics)
|
||||
public Binder(Diagnostics diagnostics, Dictionary<VariableSymbol, LuaType> variables)
|
||||
{
|
||||
_diagnostics = diagnostics;
|
||||
_scope = new BoundScope(null);
|
||||
_scope = new BoundScope(variables, null);
|
||||
}
|
||||
|
||||
public BoundScript BindScript(BlockStatementSyntax e)
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace Upsilon.Binder
|
|||
_variables = variables.ToDictionary(x => x.Key.Name, x => x.Key);
|
||||
}
|
||||
|
||||
|
||||
public void SetVariable(VariableSymbol var)
|
||||
{
|
||||
if (_variables.ContainsKey(var.Name))
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.Binder;
|
||||
|
@ -7,17 +6,17 @@ namespace Upsilon.Evaluator
|
|||
{
|
||||
public class EvaluationScope
|
||||
{
|
||||
public readonly EvaluationScope ParentScope;
|
||||
private readonly EvaluationScope _parentScope;
|
||||
private readonly Dictionary<VariableSymbol, LuaType> _variables;
|
||||
|
||||
internal EvaluationScope(EvaluationScope parentScope)
|
||||
{
|
||||
ParentScope = parentScope;
|
||||
_parentScope = parentScope;
|
||||
_variables = new Dictionary<VariableSymbol, LuaType>();
|
||||
}
|
||||
internal EvaluationScope(Dictionary<VariableSymbol, LuaType> vars)
|
||||
{
|
||||
_variables = new Dictionary<VariableSymbol, LuaType>();
|
||||
_variables = vars;
|
||||
}
|
||||
|
||||
public void Set(VariableSymbol symbol, LuaType obj)
|
||||
|
@ -34,8 +33,8 @@ namespace Upsilon.Evaluator
|
|||
|
||||
public void SetGlobal(VariableSymbol symbol, LuaType obj)
|
||||
{
|
||||
if (ParentScope != null)
|
||||
ParentScope.SetGlobal(symbol, obj);
|
||||
if (_parentScope != null)
|
||||
_parentScope.SetGlobal(symbol, obj);
|
||||
else
|
||||
{
|
||||
Set(symbol, obj);
|
||||
|
@ -46,8 +45,8 @@ namespace Upsilon.Evaluator
|
|||
{
|
||||
if (_variables.TryGetValue(symbol, out obj))
|
||||
return true;
|
||||
if (ParentScope != null)
|
||||
if (ParentScope.TryGet(symbol, out obj))
|
||||
if (_parentScope != null)
|
||||
if (_parentScope.TryGet(symbol, out obj))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -62,8 +61,8 @@ namespace Upsilon.Evaluator
|
|||
return true;
|
||||
};
|
||||
}
|
||||
if (ParentScope != null)
|
||||
if (ParentScope.TryGet(variable, out obj))
|
||||
if (_parentScope != null)
|
||||
if (_parentScope.TryGet(variable, out obj))
|
||||
return true;
|
||||
obj = null;
|
||||
return false;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Upsilon.Evaluator
|
|||
_parsed = Parser.Parser.Parse(scriptString, Diagnostics);
|
||||
if (variables == null)
|
||||
variables = new Dictionary<VariableSymbol, LuaType>();
|
||||
Binder = new Binder.Binder(Diagnostics);
|
||||
Binder = new Binder.Binder(Diagnostics, variables);
|
||||
Evaluator = new Evaluator( Diagnostics, variables);
|
||||
Scope = Evaluator.Scope;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace Ycicle
|
|||
}
|
||||
|
||||
var parsed = new Script(input, variables);
|
||||
Console.WriteLine(parsed.PrettyPrintSyntaxTree());
|
||||
|
||||
if (parsed.Diagnostics.Messages.Count > 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue