Fixes binder assigning values to static read only scope
This commit is contained in:
parent
aae16e8b62
commit
ea24695128
|
@ -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<string, UnboundFunctionExpression> _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);
|
||||
|
|
|
@ -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<string, VariableSymbol> boundStaticScope, Dictionary<string, LuaType> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ namespace UpsilonTests
|
|||
[Collection("collection")]
|
||||
public abstract class TestClass
|
||||
{
|
||||
public Dictionary<string, LuaType> StaticScope { get; }
|
||||
public Dictionary<string, VariableSymbol> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue