public override void Compile(ILGenerator g, CompilerContext cc)
        {
            if (cc.IsFirstPass())
            {
                e.Compile(g, cc);
                return;
            }
            MethodInfo mi = null;

            switch (effx)
            {
            case FunctionType.Cos: mi = typeof(Math).GetMethod("Cos"); break;

            case FunctionType.Sin: mi = typeof(Math).GetMethod("Sin"); break;

            case FunctionType.Ln: mi = typeof(Math).GetMethod("Log"); break;

            case FunctionType.Log: mi = typeof(Math).GetMethod("Log10"); break;

            default:
                break;
            }
            if (mi == null)
            {
                return;
            }

            e.Compile(g, cc);

            g.EmitCall(OpCodes.Call, mi, null);
        }
 // First Pass: none
 // Push a float literal (partial evaluation)
 public override void Compile(ILGenerator g, CompilerContext cc)
 {
     if (cc.IsFirstPass())
     {
         return;
     }
     g.Emit(OpCodes.Ldc_R8, thevalue);
 }
Exemple #3
0
        // Compilation First Pass: check sizes
        // Code Generation: the operator code

        public override void Compile(ILGenerator g, CompilerContext cc)
        {
            expr1.Compile(g, cc);
            expr2.Compile(g, cc);
            if (cc.IsFirstPass())
            {
                return;
            }
            oper.Compile(g);
        }
Exemple #4
0
 public override void Compile(ILGenerator g, CompilerContext cc)
 {
     if (cc.IsFirstPass())
     {
         expr1.Compile(g, cc);
         expr2.Compile(g, cc);
         if (!(expr2.Size == MathlineSize.Scalar))
         {
             throw new SizeMismatchException("Pow Operator requires a scalar second operand");
         }
         return;
     }
     expr1.Compile(g, cc);
     expr2.Compile(g, cc);
     g.EmitCall(OpCodes.Call, typeof(Math).GetMethod("Pow"), null);
 }
        public override void Compile(ILGenerator g, CompilerContext cc)
        {
            if (cc.IsFirstPass())
            {
                e.Compile(g, cc);
                return;
            }

            // swap the indexes at the compiler level
            int i1 = cc.GetIndexVariable(0);
            int i2 = cc.GetIndexVariable(1);

            cc.SetIndexVariable(1, i1);
            cc.SetIndexVariable(0, i2);
            e.Compile(g, cc);
            cc.SetIndexVariable(0, i1);
            cc.SetIndexVariable(1, i2);
        }
Exemple #6
0
        public override void Compile(ILGenerator g, CompilerContext cc)
        {
            bool biloop = size.rows > 1 && size.cols > 1;

            if (cc.IsFirstPass())
            {
                if (!partial)
                {
                    iI = cc.AllocIndexVariable();   // i
                    lL = cc.AllocIndexVariable();   // l
                }
                expr.Compile(g, cc);
                lexpr.CompileAssign(g, cc, true, partial);
            }
            else
            {
                if (!partial)
                {
                    int   i, l, svi;
                    Label topLabel;
                    Label topLabelE;

                    topLabel  = g.DefineLabel();
                    topLabelE = g.DefineLabel();

                    i = cc.GetIndexVariable(iI);
                    l = cc.GetIndexVariable(lL);
                    // then
                    svi = cc.GetIndexVariable(0);

                    cc.SetIndexVariable(0, i);
                    cc.SetIndexVariable(1, size.rows);

                    g.Emit(OpCodes.Ldc_I4_0);   // i = 0
                    g.Emit(OpCodes.Stloc, i);
                    g.Emit(OpCodes.Ldarg_0);
                    g.Emit(OpCodes.Ldc_I4_0);
                    g.EmitCall(OpCodes.Callvirt, typeof(CombinedReckoner).GetMethod("GetRowCount", new Type[] { typeof(int) }), null);
                    g.Emit(OpCodes.Stloc, l);

                    if (size.rows > 1 || size.cols > 1)
                    {
                        // iterate rows, so move
                        int index;
                        int count;

                        index = i;
                        count = size.rows;

                        // just one loop. Set wich
                        g.MarkLabel(topLabel);          // TP:

                        lexpr.CompileAssign(g, cc, false, false);
                        expr.Compile(g, cc);                        // value
                        lexpr.CompileAssign(g, cc, true, false);

                        // increment j
                        g.Emit(OpCodes.Ldloc, index);           // 1
                        g.Emit(OpCodes.Ldc_I4_1);               // j =>
                        g.Emit(OpCodes.Add);                    // +
                        g.Emit(OpCodes.Dup);
                        g.Emit(OpCodes.Stloc, index);           // j <=

                        // here from first jump
                        //g.Emit(OpCodes.Ldc_I4, count);  // j < cols

                        g.Emit(OpCodes.Ldloc, l);
                        g.Emit(OpCodes.Blt, topLabel);
                    }
                    else
                    {
                        lexpr.CompileAssign(g, cc, false, false);
                        expr.Compile(g, cc);                        // value
                        lexpr.CompileAssign(g, cc, true, false);
                    }
                    cc.SetIndexVariable(0, svi);
                }
                else
                {
                    lexpr.CompileAssign(g, cc, false, true);
                    expr.Compile(g, cc);                        // value
                    lexpr.CompileAssign(g, cc, true, true);
                }
            }
        }