public static bool Stind_R4(Instruction instruction, CompileContext compileContext) { var value = compileContext.Pop(); var target = compileContext.Pop(); compileContext.Assign(target, value); return(true); }
public static bool Stloc_N(Instruction instruction, CompileContext compileContext, uint index) { var value = compileContext.Pop(); var local = compileContext.Allocate(value.type, index); compileContext.Assign(local, value); return(true); }
public static bool Stobj(Instruction instruction, CompileContext compileContext) { // stobj typeTok - Store a value of type typeTok at an address. var value = compileContext.Pop(); var target = compileContext.Pop(); compileContext.Assign(target, value); return(true); }
public static bool Stfld(Instruction instruction, CompileContext compileContext) { // stfld field - Replace the value of field of the object obj with value var fieldDefinition = instruction.Operand as FieldDefinition; var value = compileContext.Pop(); var @this = compileContext.Pop(); compileContext.Assign(compileContext.Field(@this, fieldDefinition), 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); }