Fixes for require
This commit is contained in:
parent
520cd1ffcc
commit
7996420ee5
|
@ -62,18 +62,20 @@ namespace Upsilon.BaseTypes.ScriptFunction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = method.Invoke(_object, objects.ToArray());
|
result = method.Invoke(_object, objects.ToArray());
|
||||||
if (_directTypeManipulation)
|
|
||||||
return (ScriptType)result;
|
|
||||||
return result.ToScriptType();
|
|
||||||
}
|
}
|
||||||
catch (TargetInvocationException e)
|
catch (TargetInvocationException e)
|
||||||
{
|
{
|
||||||
if (e.InnerException != null) throw e.InnerException;
|
if (e.InnerException != null) throw e.InnerException;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
if (_directTypeManipulation)
|
||||||
|
return (ScriptType)result;
|
||||||
|
return result.ToScriptType();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Upsilon.Evaluator;
|
||||||
|
|
||||||
namespace Upsilon.BaseTypes.UserData
|
namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
|
@ -11,7 +12,17 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
public UserDataMethodPart(MethodInfo method)
|
public UserDataMethodPart(MethodInfo method)
|
||||||
{
|
{
|
||||||
Method = 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; }
|
public MethodInfo Method { get; }
|
||||||
|
|
|
@ -13,7 +13,9 @@ namespace Upsilon.Binder
|
||||||
GreaterEquals,
|
GreaterEquals,
|
||||||
Greater,
|
Greater,
|
||||||
LessEquals,
|
LessEquals,
|
||||||
Less
|
Less,
|
||||||
|
And,
|
||||||
|
Or
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type LeftType { get; }
|
private Type LeftType { get; }
|
||||||
|
@ -59,6 +61,10 @@ namespace Upsilon.Binder
|
||||||
new BoundBinaryOperator(OperatorKind.Equality, Type.Boolean),
|
new BoundBinaryOperator(OperatorKind.Equality, Type.Boolean),
|
||||||
new BoundBinaryOperator(OperatorKind.Inequality, Type.Boolean),
|
new BoundBinaryOperator(OperatorKind.Inequality, Type.Boolean),
|
||||||
|
|
||||||
|
// Boolean chaining
|
||||||
|
new BoundBinaryOperator(OperatorKind.And, Type.Boolean),
|
||||||
|
new BoundBinaryOperator(OperatorKind.Or, Type.Boolean),
|
||||||
|
|
||||||
// String operators
|
// String operators
|
||||||
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.String, Type.String),
|
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.String, Type.String),
|
||||||
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.Number, Type.String),
|
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.Number, Type.String),
|
||||||
|
@ -114,6 +120,12 @@ namespace Upsilon.Binder
|
||||||
case SyntaxKind.GreaterEquals:
|
case SyntaxKind.GreaterEquals:
|
||||||
kind = OperatorKind.GreaterEquals;
|
kind = OperatorKind.GreaterEquals;
|
||||||
break;
|
break;
|
||||||
|
case SyntaxKind.AndKeyword:
|
||||||
|
kind = OperatorKind.And;
|
||||||
|
break;
|
||||||
|
case SyntaxKind.OrKeyword:
|
||||||
|
kind = OperatorKind.Or;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Unknown binary operator token: " + operatorToken);
|
throw new Exception("Unknown binary operator token: " + operatorToken);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
if (!functionParameter.ValidTypes.HasFlag(callingParameter.Type))
|
if (!functionParameter.ValidTypes.HasFlag(callingParameter.Type))
|
||||||
{
|
{
|
||||||
return (false,
|
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}'",
|
$"Expected one of the following: {functionParameter.ValidTypes.ToString()}, got: '{callingParameter.Type}'",
|
||||||
callingParameter);
|
callingParameter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,6 +359,10 @@ namespace Upsilon.Evaluator
|
||||||
ThrowException($"Can't find operator for types '{left.Type}' and '{right.Type}'", e.Span);
|
ThrowException($"Can't find operator for types '{left.Type}' and '{right.Type}'", e.Span);
|
||||||
return new ScriptNull();
|
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:
|
default:
|
||||||
throw new Exception("Invalid Binary Operator: " + e.Operator);
|
throw new Exception("Invalid Binary Operator: " + e.Operator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace Upsilon
|
||||||
public static Script ContinueWith(Script script, BoundScript bound)
|
public static Script ContinueWith(Script script, BoundScript bound)
|
||||||
{
|
{
|
||||||
var s = Script.ContinueWith(script, bound);
|
var s = Script.ContinueWith(script, bound);
|
||||||
s.Parse();
|
s.Evaluate();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,9 @@ namespace Upsilon.StandardLibraries
|
||||||
|
|
||||||
[StandardLibraryScriptFunction("require", "Loads a module from the module path, using the given script loader.",
|
[StandardLibraryScriptFunction("require", "Loads a module from the module path, using the given script loader.",
|
||||||
true)]
|
true)]
|
||||||
public ScriptType Require(Script script, string file)
|
public ScriptType Require(Script script, ScriptString fileName)
|
||||||
{
|
{
|
||||||
|
var file = fileName.Value;
|
||||||
var loader = script.Options.ScriptLoader;
|
var loader = script.Options.ScriptLoader;
|
||||||
if (loader != null)
|
if (loader != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue