From ea246951287dec5b7056ec628f0765c2a737c518 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 23 Nov 2018 13:18:49 +0100 Subject: [PATCH] Fixes binder assigning values to static read only scope --- Upsilon/Binder/Binder.cs | 11 +++++++++-- Upsilon/Evaluator/Script.cs | 9 ++++----- UpsilonTests/TestClass.cs | 8 ++++---- Ycicle/Program.cs | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 863f4a5..cbe5e9c 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -4,14 +4,13 @@ using System.Collections.Immutable; using Upsilon.BaseTypes; using Upsilon.BaseTypes.Number; using Upsilon.Parser; -using Upsilon.Text; using Type = Upsilon.BaseTypes.Type; namespace Upsilon.Binder { internal class Binder { - private readonly Diagnostics _diagnostics; + private Diagnostics _diagnostics; public BoundScope Scope { get; private set; } private Dictionary _unboundFunctions = @@ -23,6 +22,14 @@ namespace Upsilon.Binder Scope = new BoundScope(variables, null); } + private Binder(){} + + internal static Binder CreateWithSetScope(Diagnostics diagnostics, BoundScope scope) + { + return new Binder {_diagnostics = diagnostics, Scope = scope}; + } + + public BoundScript BindScript(BlockStatementSyntax e) { var bound = BindStatement(e); diff --git a/Upsilon/Evaluator/Script.cs b/Upsilon/Evaluator/Script.cs index 5495bb6..69ccb13 100644 --- a/Upsilon/Evaluator/Script.cs +++ b/Upsilon/Evaluator/Script.cs @@ -4,7 +4,6 @@ using System.Collections.Immutable; using Upsilon.BaseTypes; using Upsilon.Binder; using Upsilon.Parser; -using Upsilon.StandardLibraries; using Upsilon.Text; using Upsilon.Utilities; @@ -20,16 +19,16 @@ namespace Upsilon.Evaluator private Binder.Binder Binder { get; } private EvaluationScope Scope { get; } - public Script(string scriptString, Dictionary boundStaticScope, Dictionary staticScope ) + public Script(string scriptString, BoundScope boundStaticScope, EvaluationScope staticScope ) { ScriptString = new SourceText(scriptString); Diagnostics = new Diagnostics(ScriptString); _parsed = Parser.Parser.Parse(scriptString, Diagnostics); - var boundScope = new BoundScope(boundStaticScope, null); - Binder = new Binder.Binder(Diagnostics, boundScope.Variables); + var boundScope = BoundScope.WithReadOnlyScope(boundStaticScope); + Binder = Upsilon.Binder.Binder.CreateWithSetScope(Diagnostics, boundScope); - Scope = EvaluationScope.CreateWithGetOnlyParent(new EvaluationScope(staticScope)); + Scope = EvaluationScope.CreateWithGetOnlyParent(staticScope); Evaluator = Evaluator.CreateWithSetScope(Diagnostics, Scope); } diff --git a/UpsilonTests/TestClass.cs b/UpsilonTests/TestClass.cs index 22b6e79..c776f96 100644 --- a/UpsilonTests/TestClass.cs +++ b/UpsilonTests/TestClass.cs @@ -10,13 +10,13 @@ namespace UpsilonTests [Collection("collection")] public abstract class TestClass { - public Dictionary StaticScope { get; } - public Dictionary BoundScope { get; } + public EvaluationScope StaticScope { get; } + public BoundScope BoundScope { get; } public TestClass(StaticScriptFixture fix) { - StaticScope = fix.StaticScope.Variables; - BoundScope = fix.BoundScope.Variables; + StaticScope = fix.StaticScope; + BoundScope = fix.BoundScope; } } diff --git a/Ycicle/Program.cs b/Ycicle/Program.cs index bae7676..3c3ab27 100644 --- a/Ycicle/Program.cs +++ b/Ycicle/Program.cs @@ -22,7 +22,7 @@ namespace Ycicle var input = Console.ReadLine(); if (input == "exit") return; script = script == null - ? new Script(input, boundScope.Variables, evaluationScope.Variables) + ? new Script(input, boundScope, evaluationScope) : Script.ContinueWith(script, input); if (script.Diagnostics.Messages.Count > 0)