Fix Ycicle arguments not persisting

This commit is contained in:
Deukhoofd 2018-11-16 13:55:31 +01:00
parent 7c6d847adb
commit 62f31ef0d3
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
5 changed files with 12 additions and 15 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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;

View File

@ -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;
}

View File

@ -29,7 +29,6 @@ namespace Ycicle
}
var parsed = new Script(input, variables);
Console.WriteLine(parsed.PrettyPrintSyntaxTree());
if (parsed.Diagnostics.Messages.Count > 0)
{