private static void TestFail(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var testName = (string)Stack[Stack.Length - 1].value; PrintWithColor("Test Failure: " + testName, ConsoleColor.Red); NumbOfFailedTests++; }
private void FieldInfo_SetValue(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var field = Stack[0]; var objToSetOn = Stack[1]; var value = Stack[2]; var fieldType = (DotNetType)Objects.ObjectRefs[(int)field.value].Fields["ParrentObjectID"].value; var Thefield = (DotNetField)Objects.ObjectRefs[(int)field.value].Fields["InternalField"].value; if (objToSetOn == MethodArgStack.ldnull) { //set on static field int idx = -1; foreach (var item in StaticFieldHolder.staticFields) { if (item.theField == Thefield) { break; } idx++; } StaticFieldHolder.staticFields[idx].value = value; } else { throw new NotImplementedException(); } }
private void WriteStringToType(MethodArgStack objectInstance, string property, string value) { Objects.ObjectRefs[(int)objectInstance.value].Fields.Add(property, new MethodArgStack() { type = StackItemType.String, value = value }); }
private void InternalMethod_Console_Writeline(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { if (Stack.Length == 0) { Console.WriteLine(); } else { var s = Stack[0]; string val = "<NULL>"; if (s.type == StackItemType.Int32) { val = ((int)s.value).ToString(); } else if (s.type == StackItemType.Int64) { val = ((long)s.value).ToString(); } else if (s.type == StackItemType.String) { val = (string)s.value; } Console.WriteLine(val); } }
private static void TestSuccess(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var testName = (string)Stack[Stack.Length - 1].value; PrintWithColor("Test Success: " + testName, ConsoleColor.Green); NumbOfSuccesssTests++; }
public static MethodArgStack Op(MethodArgStack arg1, MethodArgStack arg2, Operation op) { if (arg1.type == StackItemType.Int32 || arg2.type == StackItemType.Int32) { // int32 is a special case where types such as 'char' and 'boolean' can be converted to an int32 implicitely arg1 = ConvertToInt32(arg1); arg2 = ConvertToInt32(arg2); } if (arg1.type != arg2.type && arg2.type != StackItemType.ldnull) { throw new Exception("Inconsistent type definitions"); } switch (arg1.type) { case StackItemType.Float32: return(OpWithFloat32(arg1, arg2, op)); case StackItemType.Float64: return(OpWithFloat64(arg1, arg2, op)); case StackItemType.Int32: return(OpWithInt32(arg1, arg2, op)); case StackItemType.Int64: return(OpWithInt64(arg1, arg2, op)); case StackItemType.ldnull: return(OpWithLdNull(arg1, arg2, op)); case StackItemType.Object: return(OpWithObject(arg1, arg2, op)); case StackItemType.Array: return(OpWithArray(arg1, arg2, op)); default: throw new NotImplementedException(); } }
private void String_IndexOf(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = (string)Stack[0].value; var c = (char)(int)Stack[1].value; returnValue = MethodArgStack.Int32(str.IndexOf(c)); }
private void ListAddItem(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var list = Stack[Stack.Length - 2]; var item = Stack[Stack.Length - 1]; ; }
private void GetObjType(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var obj = Stack[Stack.Length - 1]; //TODO: Remove this hack if (obj.type != StackItemType.Object) { obj = Stack[0]; } if (obj.type != StackItemType.Object) { throw new InvalidOperationException(); } //Create the type object MethodArgStack a = CreateType("System", "Type"); WriteStringToType(a, "internal__fullname", obj.ObjectType.FullName); WriteStringToType(a, "internal__name", obj.ObjectType.Name); WriteStringToType(a, "internal__namespace", obj.ObjectType.NameSpace); Objects.ObjectRefs[(int)obj.value].Fields.Add("internal__type", new MethodArgStack() { type = StackItemType.None, value = obj.ObjectType }); returnValue = a; }
private void Action2InvokeImpl(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { MethodArgStack obj = Stack[0]; var d = Objects.ObjectRefs[(int)obj.value]; if (!d.Fields.ContainsKey("__internal_method")) { throw new Exception("Invaild instance of Action"); } var toCall = d.Fields["__internal_method"]; if (toCall.type != StackItemType.Object) { throw new InvalidOperationException(); } var toCallMethod = (DotNetMethod)Objects.ObjectRefs[(int)toCall.value].Fields["PtrToMethod"].value; var parms = new CustomList <MethodArgStack>(); parms.Add(obj); //Is this needed? parms.Add(Stack[1]); parms.Add(Stack[2]); RunMethod(toCallMethod, toCallMethod.File, parms); //stack.RemoveRange(stack.Count - 2, 2); }
private void InternalGetFields(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var val = Stack[0]; var type = (DotNetType)Objects.ObjectRefs[(int)val.value].Fields["internal__type"].value; var array = Arrays.AllocArray((int)type.Fields.Count); int i = 0; foreach (var item in type.Fields) { var field2 = CreateType("System.Reflection", "FieldInfo"); WriteStringToType(field2, "_internalName", item.Name); Objects.ObjectRefs[(int)field2.value].Fields.Add("ParrentObjectID", new MethodArgStack() { type = StackItemType.Object, value = type }); Objects.ObjectRefs[(int)field2.value].Fields.Add("InternalField", new MethodArgStack() { type = StackItemType.Object, value = item }); Arrays.ArrayRefs[array.Index].Items[i] = field2; i++; } returnValue = new MethodArgStack() { type = StackItemType.Array, value = array.Index }; }
private void InternalGetField(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var val = Stack[0]; var type = (DotNetType)Objects.ObjectRefs[(int)val.value].Fields["internal__type"].value; DotNetField f = null; foreach (var item in type.Fields) { if (item.Name == (string)Stack[Stack.Length - 1].value) { f = item; break; } } if (f == null) { throw new InvalidOperationException(); } var field2 = CreateType("System.Reflection", "FieldInfo"); WriteStringToType(field2, "_internalName", f.Name); Objects.ObjectRefs[(int)field2.value].Fields.Add("ParrentObjectID", new MethodArgStack() { type = StackItemType.Object, value = type }); Objects.ObjectRefs[(int)field2.value].Fields.Add("InternalField", new MethodArgStack() { type = StackItemType.Object, value = f }); returnValue = field2; }
public static MethodArgStack OpWithInt64(MethodArgStack arg1, MethodArgStack arg2, Operation op) { long v1 = (long)arg1.value; long v2 = (long)arg2.value; switch (op) { case Operation.Add: return(MethodArgStack.Int64(v1 + v2)); case Operation.Subtract: return(MethodArgStack.Int64(v1 - v2)); case Operation.Multiply: return(MethodArgStack.Int64(v1 * v2)); case Operation.Divide: return(MethodArgStack.Int64(v1 / v2)); case Operation.Remainder: return(MethodArgStack.Int64(v1 % v2)); case Operation.Equal: return(MethodArgStack.Int32(v1 == v2 ? 1 : 0)); case Operation.GreaterThan: return(MethodArgStack.Int32(v1 > v2 ? 1 : 0)); case Operation.LessThan: return(MethodArgStack.Int32(v1 < v2 ? 1 : 0)); case Operation.GreaterThanEqual: return(MethodArgStack.Int32(v1 >= v2 ? 1 : 0)); case Operation.LessThanEqual: return(MethodArgStack.Int32(v1 <= v2 ? 1 : 0)); case Operation.Negate: return(MethodArgStack.Int64(-v1)); default: throw new Exception("Invalid operation"); } }
private void Internal__System_UInt64_ToString(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = new MethodArgStack(); str.type = StackItemType.String; str.value = ((ulong)(long)Stack[Stack.Length - 1].value).ToString(); returnValue = str; }
private void String_SubString(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = (string)Stack[0].value; var startIndex = (int)Stack[1].value; var len = (int)Stack[2].value; returnValue = MethodArgStack.String(str.Substring(startIndex, len)); }
private void InternalMethod_Byte_ToString(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = new MethodArgStack(); str.type = StackItemType.String; str.value = ((int)Stack[Stack.Length - 1].value).ToString(); returnValue = str; }
private static void TestsComplete(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { Console.WriteLine(); PrintWithColor("All Tests Completed.", ConsoleColor.DarkYellow); Console.WriteLine(); PrintWithColor("Passed tests: " + NumbOfSuccesssTests, ConsoleColor.Green); PrintWithColor("Failed tests: " + NumbOfFailedTests, ConsoleColor.Red); }
private void Internal__System_Char_ToString(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var c = Stack[Stack.Length - 1].value; returnValue = new MethodArgStack() { value = (int)c, type = StackItemType.Int32 }; }
private void Internal__System_String_Get_Length(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var stringToRead = Stack[Stack.Length - 1]; var str = (string)stringToRead.value; returnValue = new MethodArgStack() { type = StackItemType.Int32, value = str.Length }; }
private void Internal__System_String_get_Chars_1(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = (string)Stack[0].value; var index = (int)Stack[1].value; returnValue = new MethodArgStack() { type = StackItemType.Char, value = str[index] }; }
private MethodArgStack CreateType(DotNetType type) { //TODO: Do we need to resolve the constructor? MethodArgStack a = new MethodArgStack() { ObjectContructor = null, ObjectType = type, type = StackItemType.Object, value = Objects.AllocObject().Index }; return(a); }
private void Array_GetLength(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var array = Stack[0]; if (array.type != StackItemType.Array) { throw new Exception(); } returnValue = MethodArgStack.Int32(Arrays.ArrayRefs[(int)array.value].Length); }
private static void TestsComplete(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { if (NumbOfFailedTests == 0) { PrintWithColor("All tests are complete. Successed tests: " + NumbOfSuccesssTests + ", failed Tests: " + NumbOfFailedTests, ConsoleColor.Green); } else { PrintWithColor("All tests are complete. Successed tests: " + NumbOfSuccesssTests + ", failed Tests: " + NumbOfFailedTests, ConsoleColor.Red); } }
private static MethodArgStack ConvertToInt32(MethodArgStack arg) { switch (arg.type) { case StackItemType.Int32: return(arg); case StackItemType.Char: return(MethodArgStack.Int32((int)(char)arg.value)); default: throw new Exception("Unsupported type conversion"); } }
private static MethodArgStack OpWithArray(MethodArgStack arg1, MethodArgStack arg2, Operation op) { object v1 = arg1.value; object v2 = arg2.value; switch (op) { case Operation.Equal: return(MethodArgStack.Int32(v1 == v2 ? 1 : 0)); default: throw new Exception("Invalid operation"); } }
private void String_ToLower(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = Stack[0]; if (str.type != StackItemType.String) { throw new InvalidOperationException(); } var oldVal = (string)str.value; returnValue = MethodArgStack.String(oldVal.ToLower()); }
private void Array_GetLowerBound(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var array = Stack[0]; var bound = Stack[1]; if (array.type != StackItemType.Array) { throw new Exception(); } //todo returnValue = MethodArgStack.Int32(0); }
private static void TestRxObject(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var cctor = m.GetMethod("DotNetparserTester", "TestObject", ".ctor"); if (cctor == null) { throw new NullReferenceException(); } var s = new CustomList <MethodArgStack>(); s.Add(MethodArgStack.String("value")); returnValue = clr.CreateObject(cctor, s); }
private void String_EndsWith(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method) { var str = (string)Stack[0].value; var cmp = (string)Stack[1].value; if (str.EndsWith(cmp)) { returnValue = MethodArgStack.Int32(1); } else { returnValue = MethodArgStack.Int32(0); } }
public static MethodArgStack Op(MethodArgStack arg, Operation op) { switch (arg.type) { case StackItemType.Float32: return(OpWithFloat32(arg, arg, op)); case StackItemType.Float64: return(OpWithFloat64(arg, arg, op)); case StackItemType.Int32: return(OpWithInt32(arg, arg, op)); case StackItemType.Int64: return(OpWithInt64(arg, arg, op)); default: throw new NotImplementedException(); } }