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 = private Dictionary<FunctionVariableSymbol, UnboundFunctionStatement> _unboundFunctions =
new Dictionary<FunctionVariableSymbol, UnboundFunctionStatement>(); new Dictionary<FunctionVariableSymbol, UnboundFunctionStatement>();
public Binder(Diagnostics diagnostics) public Binder(Diagnostics diagnostics, Dictionary<VariableSymbol, LuaType> variables)
{ {
_diagnostics = diagnostics; _diagnostics = diagnostics;
_scope = new BoundScope(null); _scope = new BoundScope(variables, null);
} }
public BoundScript BindScript(BlockStatementSyntax e) public BoundScript BindScript(BlockStatementSyntax e)

View File

@ -20,7 +20,6 @@ namespace Upsilon.Binder
_variables = variables.ToDictionary(x => x.Key.Name, x => x.Key); _variables = variables.ToDictionary(x => x.Key.Name, x => x.Key);
} }
public void SetVariable(VariableSymbol var) public void SetVariable(VariableSymbol var)
{ {
if (_variables.ContainsKey(var.Name)) if (_variables.ContainsKey(var.Name))

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Upsilon.BaseTypes; using Upsilon.BaseTypes;
using Upsilon.Binder; using Upsilon.Binder;
@ -7,17 +6,17 @@ namespace Upsilon.Evaluator
{ {
public class EvaluationScope public class EvaluationScope
{ {
public readonly EvaluationScope ParentScope; private readonly EvaluationScope _parentScope;
private readonly Dictionary<VariableSymbol, LuaType> _variables; private readonly Dictionary<VariableSymbol, LuaType> _variables;
internal EvaluationScope(EvaluationScope parentScope) internal EvaluationScope(EvaluationScope parentScope)
{ {
ParentScope = parentScope; _parentScope = parentScope;
_variables = new Dictionary<VariableSymbol, LuaType>(); _variables = new Dictionary<VariableSymbol, LuaType>();
} }
internal EvaluationScope(Dictionary<VariableSymbol, LuaType> vars) internal EvaluationScope(Dictionary<VariableSymbol, LuaType> vars)
{ {
_variables = new Dictionary<VariableSymbol, LuaType>(); _variables = vars;
} }
public void Set(VariableSymbol symbol, LuaType obj) public void Set(VariableSymbol symbol, LuaType obj)
@ -34,8 +33,8 @@ namespace Upsilon.Evaluator
public void SetGlobal(VariableSymbol symbol, LuaType obj) public void SetGlobal(VariableSymbol symbol, LuaType obj)
{ {
if (ParentScope != null) if (_parentScope != null)
ParentScope.SetGlobal(symbol, obj); _parentScope.SetGlobal(symbol, obj);
else else
{ {
Set(symbol, obj); Set(symbol, obj);
@ -46,8 +45,8 @@ namespace Upsilon.Evaluator
{ {
if (_variables.TryGetValue(symbol, out obj)) if (_variables.TryGetValue(symbol, out obj))
return true; return true;
if (ParentScope != null) if (_parentScope != null)
if (ParentScope.TryGet(symbol, out obj)) if (_parentScope.TryGet(symbol, out obj))
return true; return true;
return false; return false;
} }
@ -62,8 +61,8 @@ namespace Upsilon.Evaluator
return true; return true;
}; };
} }
if (ParentScope != null) if (_parentScope != null)
if (ParentScope.TryGet(variable, out obj)) if (_parentScope.TryGet(variable, out obj))
return true; return true;
obj = null; obj = null;
return false; return false;

View File

@ -23,7 +23,7 @@ namespace Upsilon.Evaluator
_parsed = Parser.Parser.Parse(scriptString, Diagnostics); _parsed = Parser.Parser.Parse(scriptString, Diagnostics);
if (variables == null) if (variables == null)
variables = new Dictionary<VariableSymbol, LuaType>(); variables = new Dictionary<VariableSymbol, LuaType>();
Binder = new Binder.Binder(Diagnostics); Binder = new Binder.Binder(Diagnostics, variables);
Evaluator = new Evaluator( Diagnostics, variables); Evaluator = new Evaluator( Diagnostics, variables);
Scope = Evaluator.Scope; Scope = Evaluator.Scope;
} }

View File

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