private void InvokeInternalCall(MethodDefinition methDef)
{
object retVal;
var args = new object[methDef.Parameters.Count];
for (var i = args.Length - 1; i >= 0; i--)
{
args[i] = _opStack.Pop().ToClrObject();
}
if (PetitClrRuntime.Current.InternalCallMethods.ContainsKey(methDef.ToString()))
{
var func = PetitClrRuntime.Current.InternalCallMethods[methDef.ToString()];
retVal = func(_callThisArg, PetitClrThread.CurrentThread.Frame, args);
}
else
{
var realType = Type.GetType(methDef.DeclaringType.FullName.Replace("Inazuma.PetitClr.PetitCorlib.", ""));
var realMethod = realType.GetMethod(methDef.Name, BindingFlags.Static | BindingFlags.Public, null, methDef.Parameters.Select(x => Type.GetType(x.ParameterType.FullName)).ToArray(), null);
if (realMethod == null)
{
throw new InazumaExecutionException("Could not find the internal method: " + methDef.FullName);
}
retVal = realMethod.Invoke(null, args);
}
if (methDef.ReturnType.FullName != "System.Void") // TODO: should refer typevalue
{
_opStack.Push(ObjectInstance.FromClrObject(retVal));
}
}