Fixes binder assigning values to static read only scope

This commit is contained in:
Deukhoofd 2018-11-23 13:18:49 +01:00
parent aae16e8b62
commit ea24695128
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 18 additions and 12 deletions

View File

@ -4,14 +4,13 @@ using System.Collections.Immutable;
using Upsilon.BaseTypes; using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number; using Upsilon.BaseTypes.Number;
using Upsilon.Parser; using Upsilon.Parser;
using Upsilon.Text;
using Type = Upsilon.BaseTypes.Type; using Type = Upsilon.BaseTypes.Type;
namespace Upsilon.Binder namespace Upsilon.Binder
{ {
internal class Binder internal class Binder
{ {
private readonly Diagnostics _diagnostics; private Diagnostics _diagnostics;
public BoundScope Scope { get; private set; } public BoundScope Scope { get; private set; }
private Dictionary<string, UnboundFunctionExpression> _unboundFunctions = private Dictionary<string, UnboundFunctionExpression> _unboundFunctions =
@ -23,6 +22,14 @@ namespace Upsilon.Binder
Scope = new BoundScope(variables, null); 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) public BoundScript BindScript(BlockStatementSyntax e)
{ {
var bound = BindStatement(e); var bound = BindStatement(e);

View File

@ -4,7 +4,6 @@ using System.Collections.Immutable;
using Upsilon.BaseTypes; using Upsilon.BaseTypes;
using Upsilon.Binder; using Upsilon.Binder;
using Upsilon.Parser; using Upsilon.Parser;
using Upsilon.StandardLibraries;
using Upsilon.Text; using Upsilon.Text;
using Upsilon.Utilities; using Upsilon.Utilities;
@ -20,16 +19,16 @@ namespace Upsilon.Evaluator
private Binder.Binder Binder { get; } private Binder.Binder Binder { get; }
private EvaluationScope Scope { get; } private EvaluationScope Scope { get; }
public Script(string scriptString, Dictionary<string, VariableSymbol> boundStaticScope, Dictionary<string, LuaType> staticScope ) public Script(string scriptString, BoundScope boundStaticScope, EvaluationScope staticScope )
{ {
ScriptString = new SourceText(scriptString); ScriptString = new SourceText(scriptString);
Diagnostics = new Diagnostics(ScriptString); Diagnostics = new Diagnostics(ScriptString);
_parsed = Parser.Parser.Parse(scriptString, Diagnostics); _parsed = Parser.Parser.Parse(scriptString, Diagnostics);
var boundScope = new BoundScope(boundStaticScope, null); var boundScope = BoundScope.WithReadOnlyScope(boundStaticScope);
Binder = new Binder.Binder(Diagnostics, boundScope.Variables); Binder = Upsilon.Binder.Binder.CreateWithSetScope(Diagnostics, boundScope);
Scope = EvaluationScope.CreateWithGetOnlyParent(new EvaluationScope(staticScope)); Scope = EvaluationScope.CreateWithGetOnlyParent(staticScope);
Evaluator = Evaluator.CreateWithSetScope(Diagnostics, Scope); Evaluator = Evaluator.CreateWithSetScope(Diagnostics, Scope);
} }

View File

@ -10,13 +10,13 @@ namespace UpsilonTests
[Collection("collection")] [Collection("collection")]
public abstract class TestClass public abstract class TestClass
{ {
public Dictionary<string, LuaType> StaticScope { get; } public EvaluationScope StaticScope { get; }
public Dictionary<string, VariableSymbol> BoundScope { get; } public BoundScope BoundScope { get; }
public TestClass(StaticScriptFixture fix) public TestClass(StaticScriptFixture fix)
{ {
StaticScope = fix.StaticScope.Variables; StaticScope = fix.StaticScope;
BoundScope = fix.BoundScope.Variables; BoundScope = fix.BoundScope;
} }
} }

View File

@ -22,7 +22,7 @@ namespace Ycicle
var input = Console.ReadLine(); var input = Console.ReadLine();
if (input == "exit") return; if (input == "exit") return;
script = script == null script = script == null
? new Script(input, boundScope.Variables, evaluationScope.Variables) ? new Script(input, boundScope, evaluationScope)
: Script.ContinueWith(script, input); : Script.ContinueWith(script, input);
if (script.Diagnostics.Messages.Count > 0) if (script.Diagnostics.Messages.Count > 0)