Esempio n. 1
0
        public static bool Stind_R4(Instruction instruction, CompileContext compileContext)
        {
            var value  = compileContext.Pop();
            var target = compileContext.Pop();

            compileContext.Assign(target, value);
            return(true);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public static bool Neg(Instruction instruction, CompileContext compileContext)
        {
            var value = compileContext.Pop();

            compileContext.Push(value.type, CompileContext.Format("-({0})", value));
            return(true);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 public static bool Brfalse(Instruction instruction, CompileContext compileContext)
 {
     compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} == 0)", compileContext.Pop()));
     return(true);
 }
Esempio n. 15
0
 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);
 }
Esempio n. 16
0
 public static bool Conv_R4(Instruction instruction, CompileContext compileContext)
 {
     compileContext.Push(typeof(float).GetTypeDefinition(), CompileContext.Format("float({0})", compileContext.Pop()));
     return(true);
 }
Esempio n. 17
0
 public static bool Pop(Instruction instruction, CompileContext compileContext)
 {
     compileContext.Pop();
     return(true);
 }
Esempio n. 18
0
        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);
        }