General fixes for Tests

This commit is contained in:
2018-11-23 12:55:28 +01:00
parent 1e9b0e0166
commit aae16e8b62
19 changed files with 185 additions and 106 deletions

View File

@@ -258,7 +258,10 @@ namespace Upsilon.Binder
}
else if (assignment.Type == Type.Unknown && assignment is BoundVariableExpression v)
{
v.Variable.Type = v.Type;
v.Variable.Type = variable.Type;
}
else if (assignment.Type == Type.Unknown)
{
}
else
{

View File

@@ -2,11 +2,11 @@ using System.Collections.Generic;
namespace Upsilon.Binder
{
internal class BoundScope
public class BoundScope
{
public readonly BoundScope ParentScope;
private BoundScope _readOnlyScope;
internal readonly Dictionary<string, VariableSymbol> Variables;
public readonly Dictionary<string, VariableSymbol> Variables;
internal readonly Dictionary<string, VariableSymbol> LocalVariables;

View File

@@ -4,26 +4,26 @@ using Upsilon.Binder;
namespace Upsilon.Evaluator
{
internal class EvaluationScope
public class EvaluationScope
{
private readonly EvaluationScope _parentScope;
private EvaluationScope _getOnlyParentScope;
internal readonly Dictionary<string, LuaType> Variables;
internal readonly Dictionary<string, LuaType> LocalVariables;
public readonly Dictionary<string, LuaType> Variables;
private readonly Dictionary<string, LuaType> _localVariables;
internal EvaluationScope(EvaluationScope parentScope)
{
_parentScope = parentScope;
Variables = new Dictionary<string, LuaType>();
LocalVariables = new Dictionary<string, LuaType>();
_localVariables = new Dictionary<string, LuaType>();
}
internal EvaluationScope(Dictionary<string, LuaType> vars)
{
Variables = vars;
LocalVariables = new Dictionary<string, LuaType>();
_localVariables = new Dictionary<string, LuaType>();
}
internal static EvaluationScope CreateWithGetOnlyParent(EvaluationScope parent)
@@ -36,13 +36,13 @@ namespace Upsilon.Evaluator
{
if (symbol.Local)
{
if (LocalVariables.ContainsKey(symbol.Name))
if (_localVariables.ContainsKey(symbol.Name))
{
LocalVariables[symbol.Name] = obj;
_localVariables[symbol.Name] = obj;
}
else
{
LocalVariables.Add(symbol.Name, obj);
_localVariables.Add(symbol.Name, obj);
}
}
else
@@ -71,7 +71,7 @@ namespace Upsilon.Evaluator
public bool TryGet(VariableSymbol symbol, out LuaType obj)
{
if (LocalVariables.TryGetValue(symbol.Name, out obj))
if (_localVariables.TryGetValue(symbol.Name, out obj))
return true;
if (Variables.TryGetValue(symbol.Name, out obj))
return true;
@@ -86,7 +86,7 @@ namespace Upsilon.Evaluator
public bool TryGet(string variable, out LuaType obj)
{
if (LocalVariables.TryGetValue(variable, out obj))
if (_localVariables.TryGetValue(variable, out obj))
return true;
if (Variables.TryGetValue(variable, out obj))
return true;

View File

@@ -13,43 +13,24 @@ namespace Upsilon.Evaluator
public class Script
{
private SourceText ScriptString { get; }
private Evaluator Evaluator { get; set; }
private Evaluator Evaluator { get; }
private readonly BlockStatementSyntax _parsed;
private BoundScript _bound;
public Diagnostics Diagnostics { get; private set; }
private Binder.Binder Binder { get; set; }
public Diagnostics Diagnostics { get; }
private Binder.Binder Binder { get; }
private EvaluationScope Scope { get; }
private static BoundScope _staticBoundScope;
private static EvaluationScope _staticScope;
private static EvaluationScope StaticScope
{
get
{
var scope = _staticScope;
if (scope != null)
{
return scope;
}
var (evaluationScope, boundScope) = StandardLibrary.Create();
_staticBoundScope = boundScope;
return (_staticScope = evaluationScope);
}
}
public Script(string scriptString)
public Script(string scriptString, Dictionary<string, VariableSymbol> boundStaticScope, Dictionary<string, LuaType> staticScope )
{
ScriptString = new SourceText(scriptString);
Diagnostics = new Diagnostics(ScriptString);
_parsed = Parser.Parser.Parse(scriptString, Diagnostics);
Scope = EvaluationScope.CreateWithGetOnlyParent(StaticScope);
Binder = new Binder.Binder(Diagnostics, _staticBoundScope.Variables);
var boundScope = new BoundScope(boundStaticScope, null);
Binder = new Binder.Binder(Diagnostics, boundScope.Variables);
Scope = EvaluationScope.CreateWithGetOnlyParent(new EvaluationScope(staticScope));
Evaluator = Evaluator.CreateWithSetScope(Diagnostics, Scope);
Scope = Evaluator.Scope;
}
private Script(string scriptString, Binder.Binder binder, Evaluator evaluator)

View File

@@ -6,7 +6,7 @@ using Upsilon.Evaluator;
namespace Upsilon.StandardLibraries
{
internal class StandardLibrary
public class StandardLibrary
{
public static (EvaluationScope, BoundScope) Create()
{