From 62f31ef0d3006b47789a2af4497592e4e340a1bb Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 16 Nov 2018 13:55:31 +0100 Subject: [PATCH] Fix Ycicle arguments not persisting --- Upsilon/Binder/Binder.cs | 4 ++-- Upsilon/Binder/BoundScope.cs | 1 - Upsilon/Evaluator/EvaluationScope.cs | 19 +++++++++---------- Upsilon/Evaluator/Script.cs | 2 +- Ycicle/Program.cs | 1 - 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 5f441cf..6668987 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -16,10 +16,10 @@ namespace Upsilon.Binder private Dictionary _unboundFunctions = new Dictionary(); - public Binder(Diagnostics diagnostics) + public Binder(Diagnostics diagnostics, Dictionary variables) { _diagnostics = diagnostics; - _scope = new BoundScope(null); + _scope = new BoundScope(variables, null); } public BoundScript BindScript(BlockStatementSyntax e) diff --git a/Upsilon/Binder/BoundScope.cs b/Upsilon/Binder/BoundScope.cs index 0756bfc..5eab156 100644 --- a/Upsilon/Binder/BoundScope.cs +++ b/Upsilon/Binder/BoundScope.cs @@ -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)) diff --git a/Upsilon/Evaluator/EvaluationScope.cs b/Upsilon/Evaluator/EvaluationScope.cs index b89e021..2c2943c 100644 --- a/Upsilon/Evaluator/EvaluationScope.cs +++ b/Upsilon/Evaluator/EvaluationScope.cs @@ -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 _variables; internal EvaluationScope(EvaluationScope parentScope) { - ParentScope = parentScope; + _parentScope = parentScope; _variables = new Dictionary(); } internal EvaluationScope(Dictionary vars) { - _variables = new Dictionary(); + _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; diff --git a/Upsilon/Evaluator/Script.cs b/Upsilon/Evaluator/Script.cs index 95721da..b80cff7 100644 --- a/Upsilon/Evaluator/Script.cs +++ b/Upsilon/Evaluator/Script.cs @@ -23,7 +23,7 @@ namespace Upsilon.Evaluator _parsed = Parser.Parser.Parse(scriptString, Diagnostics); if (variables == null) variables = new Dictionary(); - Binder = new Binder.Binder(Diagnostics); + Binder = new Binder.Binder(Diagnostics, variables); Evaluator = new Evaluator( Diagnostics, variables); Scope = Evaluator.Scope; } diff --git a/Ycicle/Program.cs b/Ycicle/Program.cs index 57f23c4..92c9704 100644 --- a/Ycicle/Program.cs +++ b/Ycicle/Program.cs @@ -29,7 +29,6 @@ namespace Ycicle } var parsed = new Script(input, variables); - Console.WriteLine(parsed.PrettyPrintSyntaxTree()); if (parsed.Diagnostics.Messages.Count > 0) {