public static bool Neg(Instruction instruction, CompileContext compileContext) { var value = compileContext.Pop(); compileContext.Push(value.type, CompileContext.Format("-({0})", value)); return(true); }
public static bool Construct(MethodReference methodReference, CompileContext compileContext) { var parameters = compileContext.Pop(methodReference.Parameters.Count); var method = compileContext.Method(methodReference, parameters); compileContext.Push(method); return(true); }
public static bool Bgt(Instruction instruction, CompileContext compileContext) { var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} > {1})", a, b)); return(true); }
public static bool Ldobj(Instruction instruction, CompileContext compileContext) { // ldobj – copy a value from an address to the stack var value = compileContext.Pop(); compileContext.Push(value); return(true); }
public static bool Rem(Instruction instruction, CompileContext compileContext) { var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(new Value(a.type, CompileContext.Format("mod({0}, {1})", a, b))); return(true); }
public static bool Ldloc_S(Instruction instruction, CompileContext compileContext) { // ldloc.s indx - Load local variable of index indx onto stack, short form. var variableDefinition = instruction.Operand as VariableDefinition; var local = compileContext.Allocate(variableDefinition.VariableType, (uint)variableDefinition.Index); compileContext.Push(local); return(true); }
public static bool Ldarga_S(Instruction instruction, CompileContext compileContext) { // ldloca.s indx - Load address of local variable with index indx, short form. var parameterDefinition = instruction.Operand as ParameterDefinition; var local = compileContext.Push(parameterDefinition); local.isAddress = true; return(true); }
public static bool Blt_S(Instruction instruction, CompileContext compileContext) { // blt.s target - Branch to target if less than, short for var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} < {1})", a, b)); return(true); }
public static bool Ble(Instruction instruction, CompileContext compileContext) { // ble target - Branch to target if less than or equal to. var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} <= {1})", a, b)); return(true); }
public static bool Ldfld(Instruction instruction, CompileContext compileContext) { // ldfld field - Push the value of field of object (or value type) obj, onto the stack. var fieldDefinition = (instruction.Operand as FieldReference).Resolve(); var @this = compileContext.Pop(); compileContext.Push(fieldDefinition.FieldType, compileContext.Field(@this, fieldDefinition)); return(true); }
public static bool Ldloca_S(Instruction instruction, CompileContext compileContext) { // ldloca.s indx - Load address of local variable with index indx, short form. var variableDefinition = instruction.Operand as VariableDefinition; var local = compileContext.Allocate(variableDefinition.VariableType, (uint)variableDefinition.Index); local.isAddress = true; compileContext.Push(local); return(true); }
public static bool Operator(Instruction instruction, CompileContext compileContext, string @operator, TypeReference type = null) { var b = compileContext.Pop(); var a = compileContext.Pop(); string pattern; if (type != null) { pattern = "{3}({0} {1} {2})"; } else { pattern = "({0} {1} {2})"; } compileContext.Push(new Value(type != null ? type : a.type, CompileContext.Format(pattern, a, @operator, b, type))); return(true); }
public static bool Ldarg_N(Instruction instruction, CompileContext compileContext, int n) { compileContext.Push(compileContext.parameters[n - 1]); return(true); }
public static bool Ldarg_0(Instruction instruction, CompileContext compileContext) { // ldarg.s num - Load argument numbered num onto the stack, short form. compileContext.Push(compileContext.declaringType, "this"); return(true); }
public static bool Dup(Instruction instruction, CompileContext compileContext) { compileContext.Push(compileContext.Peek()); return(true); }
public static bool Conv_R4(Instruction instruction, CompileContext compileContext) { compileContext.Push(typeof(float).GetTypeDefinition(), CompileContext.Format("float({0})", compileContext.Pop())); return(true); }
public static bool Ldc_R4(Instruction instruction, CompileContext compileContext) { // ldc.r4 num - Push num of type float32 onto the stack as F. compileContext.Push(typeof(float).GetTypeDefinition(), string.Format("float({0})", (float)instruction.Operand)); return(true); }
public static bool Ldarg_S(Instruction instruction, CompileContext compileContext) { // ldarg.s num - Load argument numbered num onto the stack, short form. compileContext.Push(instruction.Operand as ParameterDefinition); return(true); }
public static bool Brfalse(Instruction instruction, CompileContext compileContext) { compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} == 0)", compileContext.Pop())); return(true); }
public static bool Brtrue(Instruction instruction, CompileContext compileContext) { // brtrue target - Branch to target if value is non-zero (true). compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} == 1)", compileContext.Pop())); return(true); }
public static bool Ldc_I4_X(Instruction instruction, CompileContext compileContext, int value) { // ldc.i4.m1 - Push -1 onto the stack as int32. compileContext.Push(typeof(int).GetTypeDefinition(), value); return(true); }
public static bool Call(MethodReference methodReference, CompileContext compileContext) { var methodDefinition = methodReference.Resolve(); if (methodDefinition.IsGetter) // call property getter { var propertyName = methodDefinition.Name.Substring("get_".Length); var @this = compileContext.Pop(); var typeDefinition = @this.type.Resolve(); var propertyDefinition = typeDefinition.FindPropertyDefinitionIncludeAncestors(propertyName); if (typeof(ScriptableMaterial).IsAssignableFrom(typeDefinition.GetRuntimeType())) { Debug.Assert((@this.name as string) == "this"); // uniform type is defined as a property in ScriptingMaterial compileContext.Push(propertyDefinition); var propertyInfo = propertyDefinition.DeclaringType.GetRuntimeType().GetProperty(propertyDefinition.Name); if (propertyInfo.GetCustomAttribute <UniformAttribute>() != null) { compileContext.AddUniform(new Uniform(propertyInfo)); } else { throw new Exception("uncertain material property get behaviour"); } return(true); } else { compileContext.Push(compileContext.Property(@this, propertyDefinition)); } } else // method { var parameters = compileContext.Pop(methodReference.Parameters.Count()); if (methodDefinition.IsConstructor) { // Call the initializer on the local (from ECMA-335: Page 163) var method = compileContext.Method(methodDefinition, parameters.ToArray()); if (compileContext.Peek().isAddress) { var target = compileContext.Pop(); compileContext.Assign(target, method); } } else { if (methodDefinition.HasThis) { parameters.Insert(0, compileContext.Pop()); } var method = compileContext.Method(methodDefinition, parameters.ToArray()); if (!methodDefinition.ReturnType.Resolve().IsSameRuntimeOf(typeof(void).GetTypeDefinition())) { compileContext.Push(method); } else { compileContext.WriteLine(method.ToString()); } } } return(true); }
public static bool Ldloc_N(Instruction instruction, CompileContext compileContext, uint index) { compileContext.Push(compileContext.GetLocal(index)); return(true); }