Fixes for require

This commit is contained in:
Deukhoofd 2018-12-06 15:32:07 +01:00
parent 520cd1ffcc
commit 7996420ee5
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
7 changed files with 39 additions and 9 deletions

View File

@ -62,18 +62,20 @@ namespace Upsilon.BaseTypes.ScriptFunction
}
}
object result;
try
{
var result = method.Invoke(_object, objects.ToArray());
if (_directTypeManipulation)
return (ScriptType)result;
return result.ToScriptType();
result = method.Invoke(_object, objects.ToArray());
}
catch (TargetInvocationException e)
{
if (e.InnerException != null) throw e.InnerException;
throw;
}
if (_directTypeManipulation)
return (ScriptType)result;
return result.ToScriptType();
}
}
}

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Upsilon.Evaluator;
namespace Upsilon.BaseTypes.UserData
{
@ -11,7 +12,17 @@ namespace Upsilon.BaseTypes.UserData
public UserDataMethodPart(MethodInfo method)
{
Method = method;
Parameters = method.GetParameters().Select(x => new UserDataMethodParameter(x)).ToArray();
var pars = method.GetParameters();
var ls = new List<UserDataMethodParameter>();
foreach (var parameter in pars)
{
if (parameter.ParameterType == typeof(Script))
continue;
if (parameter.ParameterType == typeof(EvaluationScope))
continue;
ls.Add(new UserDataMethodParameter(parameter));
}
Parameters = ls.ToArray();
}
public MethodInfo Method { get; }

View File

@ -13,7 +13,9 @@ namespace Upsilon.Binder
GreaterEquals,
Greater,
LessEquals,
Less
Less,
And,
Or
}
private Type LeftType { get; }
@ -59,6 +61,10 @@ namespace Upsilon.Binder
new BoundBinaryOperator(OperatorKind.Equality, Type.Boolean),
new BoundBinaryOperator(OperatorKind.Inequality, Type.Boolean),
// Boolean chaining
new BoundBinaryOperator(OperatorKind.And, Type.Boolean),
new BoundBinaryOperator(OperatorKind.Or, Type.Boolean),
// String operators
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.String, Type.String),
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.Number, Type.String),
@ -114,6 +120,12 @@ namespace Upsilon.Binder
case SyntaxKind.GreaterEquals:
kind = OperatorKind.GreaterEquals;
break;
case SyntaxKind.AndKeyword:
kind = OperatorKind.And;
break;
case SyntaxKind.OrKeyword:
kind = OperatorKind.Or;
break;
default:
throw new Exception("Unknown binary operator token: " + operatorToken);
}

View File

@ -50,7 +50,7 @@ namespace Upsilon.Binder.VariableSymbols
if (!functionParameter.ValidTypes.HasFlag(callingParameter.Type))
{
return (false,
$"Unexpected variable passed to internal function at position {i + 1}. " +
$"Unexpected variable passed to internal function at variable {i + 1}. " +
$"Expected one of the following: {functionParameter.ValidTypes.ToString()}, got: '{callingParameter.Type}'",
callingParameter);
}

View File

@ -359,6 +359,10 @@ namespace Upsilon.Evaluator
ThrowException($"Can't find operator for types '{left.Type}' and '{right.Type}'", e.Span);
return new ScriptNull();
case BoundBinaryOperator.OperatorKind.And:
return new ScriptBoolean((ScriptBoolean) left && (ScriptBoolean) right);
case BoundBinaryOperator.OperatorKind.Or:
return new ScriptBoolean((ScriptBoolean) left || (ScriptBoolean) right);
default:
throw new Exception("Invalid Binary Operator: " + e.Operator);
}

View File

@ -53,7 +53,7 @@ namespace Upsilon
public static Script ContinueWith(Script script, BoundScript bound)
{
var s = Script.ContinueWith(script, bound);
s.Parse();
s.Evaluate();
return s;
}

View File

@ -45,8 +45,9 @@ namespace Upsilon.StandardLibraries
[StandardLibraryScriptFunction("require", "Loads a module from the module path, using the given script loader.",
true)]
public ScriptType Require(Script script, string file)
public ScriptType Require(Script script, ScriptString fileName)
{
var file = fileName.Value;
var loader = script.Options.ScriptLoader;
if (loader != null)
{