/// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            ex1.Compile(cont);

            // Check whether top of the stack is 1 ( TRUE )
            // Check Whether the previous operation was successful
            // Functionally equivalent to Logical Not
            //
            // Case Top of Stack is 1 (TRUE )
            // ------------------------------
            // Top of Stack =>    [ 1 ]
            // LDC_I4 =>  [ 1 1 ]
            // CEQ    =>  [ 1 ]
            // LDC_I4 =>  [ 1 0 ]
            // CEQ    =>  [ 0 ]
            //
            // Case Top of Stack is 0 (FALSE)
            // -----------------------------
            // Top of Stack =>    [ 0 ]
            // LDC_I4 =>  [ 0 1 ]
            // CEQ    =>  [ 0 ]
            // LDC_I4 =>  [ 0 0 ]
            // CEQ    =>  [ 1 ]
            cont.CodeOutput.Emit(OpCodes.Ldc_I4, 1);
            cont.CodeOutput.Emit(OpCodes.Ceq);
            cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
            cont.CodeOutput.Emit(OpCodes.Ceq);

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            // Compile the Left Expression
            exp1.Compile(cont);
            //
            // Compile the Right Expression
            exp2.Compile(cont);
            //
            // Emit Add instruction
            //
            if (_type == TYPE_INFO.TYPE_NUMERIC)
            {
                cont.CodeOutput.Emit(OpCodes.Add);
            }
            else
            {
                // This is a string type..we need to call
                // Concat method..

                Type[] str2 =
                {
                    typeof(string),
                    typeof(string)
                };

                cont.CodeOutput.Emit(OpCodes.Call,
                                     typeof(String).GetMethod("Concat", str2));
            }
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            if (m_formals != null)
            {
                int i = 0;

                foreach (SYMBOL_INFO b in m_formals)
                {
                    System.Type type = (b.Type == TYPE_INFO.TYPE_BOOL) ?
                                       typeof(bool) : (b.Type == TYPE_INFO.TYPE_NUMERIC) ?
                                       typeof(double) : typeof(string);
                    int s = cont.DeclareLocal(type);
                    b.loc_position = s;
                    cont.TABLE.Add(b);
                    cont.CodeOutput.Emit(OpCodes.Ldarg, i);
                    cont.CodeOutput.Emit(OpCodes.Stloc, cont.GetLocal(s));
                    i++;
                }
            }


            foreach (Stmt e1 in m_statements)
            {
                e1.Compile(cont);
            }

            cont.CodeOutput.Emit(OpCodes.Ret);
            return(true);
        }
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     exp1.Compile(cont);
     exp2.Compile(cont);
     cont.CodeOutput.Emit(OpCodes.Div);
     return(true);
 }
示例#5
0
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            //
            //  Compile the Expression
            //  The Output will be on the top of stack
            exp1.Compile(cont);
            //
            // Generate Code to Call Console.Write
            //
            System.Type typ        = Type.GetType("System.Console");
            Type[]      Parameters = new Type[1];

            TYPE_INFO tdata = exp1.get_type();

            if (tdata == TYPE_INFO.TYPE_STRING)
            {
                Parameters[0] = typeof(string);
            }
            else if (tdata == TYPE_INFO.TYPE_NUMERIC)
            {
                Parameters[0] = typeof(double);
            }
            else
            {
                Parameters[0] = typeof(bool);
            }
            cont.CodeOutput.Emit(OpCodes.Call, typ.GetMethod("Write", Parameters));
            return(true);
        }
示例#6
0
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     //
     //  Compile the Expression
     //  The Output will be on the top of stack
     exp1.Compile(cont);
     return(true);
 }
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     //
     // Compile The Expression and do not do
     // anything...else
     //
     exp1.Compile(cont);
     return(true);
 }
示例#8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     if (m_e1 != null)
     {
         m_e1.Compile(cont);
     }
     cont.CodeOutput.Emit(OpCodes.Ret);
     return(true);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     //
     //
     // For string emit
     //     LDSTR => Load String
     //
     cont.CodeOutput.Emit(OpCodes.Ldstr, info.str_val);
     return(true);
 }
示例#10
0
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            foreach (Stmt e1 in m_statements)
            {
                e1.Compile(cont);
            }

            cont.CodeOutput.Emit(OpCodes.Ret);
            return(true);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     //
     // Retrieve the IL Code generator and Emit
     //    LDC_I4 => Load Constant Integer 4
     // We are planning to use a 32 bit long for Boolean
     // True or False
     cont.CodeOutput.Emit(OpCodes.Ldc_I4, (info.bol_val) ? 1 : 0);
     return(true);
 }
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     // Compile the expression
     exp1.Compile(cont);
     //
     // Negate the value on the top of the
     // stack
     //
     cont.CodeOutput.Emit(OpCodes.Neg);
     return(true);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     //
     // Emit LDC_R8 => Load Constant Real 8
     // IEEE 754 floating Point
     //
     // cont.CodeOutput will return ILGenerator of the
     // current method...
     cont.CodeOutput.Emit(OpCodes.Ldc_R8, info.dbl_val);
     return(true);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     compiled_procs = new ArrayList();
     foreach (Procedure p in m_procs)
     {
         DNET_EXECUTABLE_GENERATION_CONTEXT con = new DNET_EXECUTABLE_GENERATION_CONTEXT(this, p, _exe.type_bulder);
         compiled_procs.Add(con);
         p.Compile(con);
     }
     return(true);
 }
示例#15
0
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            if (!exp1.Compile(cont))
            {
                throw new Exception("Compilation in error string");
            }
            SYMBOL_INFO  info = cont.TABLE.Get(variable.Name);
            LocalBuilder lb   = cont.GetLocal(info.loc_position);

            cont.CodeOutput.Emit(OpCodes.Stloc, lb);
            return(true);
        }
示例#16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            Label true_label, false_label;

            //
            // Generate Label for True
            true_label = cont.CodeOutput.DefineLabel();
            // Generate Label for False
            false_label = cont.CodeOutput.DefineLabel();
            //
            // Compile the expression
            //
            cond.Compile(cont);
            //
            // Check whether the top of the stack contain
            // 1 ( TRUE)
            cont.CodeOutput.Emit(OpCodes.Ldc_I4, 1);
            cont.CodeOutput.Emit(OpCodes.Ceq);
            //
            //  if False , jump to false_label ...
            //  ie to else part
            cont.CodeOutput.Emit(OpCodes.Brfalse, false_label);

            foreach (Stmt rst in stmnts)
            {
                rst.Compile(cont);
            }
            // Once we have reached here...go
            // to True label...
            cont.CodeOutput.Emit(OpCodes.Br, true_label);
            //
            // Place a Label here...if the condition evaluates
            // to false , jump to this place..
            cont.CodeOutput.MarkLabel(false_label);

            if (else_part != null)
            {
                foreach (Stmt rst in else_part)
                {
                    rst.Compile(cont);
                }
            }
            //
            // Place a label here...to mark the end of the
            // IF statement
            cont.CodeOutput.MarkLabel(true_label);
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            ex1.Compile(cont);
            ex2.Compile(cont);
            if (m_op == TOKEN.TOK_AND)
            {
                cont.CodeOutput.Emit(OpCodes.And);
            }
            else if (m_op == TOKEN.TOK_OR)
            {
                cont.CodeOutput.Emit(OpCodes.Or);
            }


            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        private bool CompileStringRelOp(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            //
            // Compile the Left Expression
            ex1.Compile(cont);
            //
            // Compile the Right Expression
            ex2.Compile(cont);

            // This is a string type..we need to call
            // Compare method..

            Type[] str2 =
            {
                typeof(string),
                typeof(string)
            };

            cont.CodeOutput.Emit(OpCodes.Call,
                                 typeof(String).GetMethod("Compare", str2));

            if (m_op == RELATION_OPERATOR.TOK_EQ)
            {
                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }
            else
            {
                //
                // This logic is bit convoluted...
                // String.Compare will give 0 , 1 or -1
                // First we will check whether the stack value
                // is zero..
                // This will put 1 on stack ..if value was zero
                // after string.Compare
                // Once again check against zero ...it is equivalent
                // to negation

                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }


            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            //
            // Retrieve the Symbol information from the
            // Symbol Table. Symbol name is the key here..
            //
            SYMBOL_INFO info = cont.TABLE.Get(m_name);
            //
            // Give the Position to retrieve the Local Variable
            // Builder.
            //
            LocalBuilder lb = cont.GetLocal(info.loc_position);

            //
            // LDLOC => Load Local... we need to give
            // a Local Builder as parameter
            //
            cont.CodeOutput.Emit(OpCodes.Ldloc, lb);
            return(true);
        }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            Label true_label, false_label;

            true_label  = cont.CodeOutput.DefineLabel();
            false_label = cont.CodeOutput.DefineLabel();
            cont.CodeOutput.MarkLabel(true_label);
            cond.Compile(cont);
            cont.CodeOutput.Emit(OpCodes.Ldc_I4, 1);
            cont.CodeOutput.Emit(OpCodes.Ceq);
            cont.CodeOutput.Emit(OpCodes.Brfalse, false_label);

            foreach (Stmt rst in stmnts)
            {
                rst.Compile(cont);
            }

            cont.CodeOutput.Emit(OpCodes.Br, true_label);
            cont.CodeOutput.MarkLabel(false_label);
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            if (m_proc == null)
            {
                // if it is  a recursive call..
                // resolve the address...
                m_proc = cont.GetProgram().Find(_procname);
            }

            string name = m_proc.Name;


            TModule       str = cont.GetProgram();
            MethodBuilder bld = str._get_entry_point(name);

            foreach (Exp ex in m_actuals)
            {
                ex.Compile(cont);
            }
            cont.CodeOutput.Emit(OpCodes.Call, bld);
            return(true);
        }
示例#22
0
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            exp1.Compile(cont);
            System.Type typ        = Type.GetType("System.Console");
            Type[]      Parameters = new Type[1];

            TYPE_INFO tdata = exp1.get_type();

            if (tdata == TYPE_INFO.TYPE_STRING)
            {
                Parameters[0] = typeof(string);
            }
            else if (tdata == TYPE_INFO.TYPE_NUMERIC)
            {
                Parameters[0] = typeof(double);
            }
            else
            {
                Parameters[0] = typeof(bool);
            }
            cont.CodeOutput.Emit(OpCodes.Call, typ.GetMethod("WriteLine", Parameters));
            return(true);
        }
示例#23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            //
            // Retrieve the type from the SYMBOL_INFO
            //
            System.Type type = (m_inf.Type == TYPE_INFO.TYPE_BOOL) ?
                               typeof(bool) : (m_inf.Type == TYPE_INFO.TYPE_NUMERIC) ?
                               typeof(double) : typeof(string);
            //
            //  Get the offset of the variable
            //
            int s = cont.DeclareLocal(type);

            // Store the offset in the SYMBOL_INFO
            //
            m_inf.loc_position = s;
            //
            // Add the variable into Symbol Table..
            //
            cont.TABLE.Add(m_inf);

            return(true);
        }
 /// <summary>
 ///   Added in the STEP 5 for .NET IL code generation
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public abstract bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont);
示例#25
0
 //
 // Added in the Step 5 for .net IL compilation
 //
 public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
 {
     return(false);
 }
        /// <summary>
        ///      Compile the Relational Expression...
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            if (_optype == TYPE_INFO.TYPE_STRING)
            {
                return(CompileStringRelOp(cont));
            }

            //
            // Compile the Left Expression
            ex1.Compile(cont);
            //
            // Compile the Right Expression
            ex2.Compile(cont);


            if (m_op == RELATION_OPERATOR.TOK_EQ)
            {
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }
            else if (m_op == RELATION_OPERATOR.TOK_GT)
            {
                cont.CodeOutput.Emit(OpCodes.Cgt);
            }
            else if (m_op == RELATION_OPERATOR.TOK_LT)
            {
                cont.CodeOutput.Emit(OpCodes.Clt);
            }
            else if (m_op == RELATION_OPERATOR.TOK_NEQ)
            {
                // There is no IL instruction for !=
                // We check for the equivality of the
                // top two values on the stack ...
                // This will put 0 ( FALSE ) or 1 (TRUE)
                // on the top of stack...
                // Load zero and check once again
                // Check == once again...

                cont.CodeOutput.Emit(OpCodes.Ceq);
                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }
            else if (m_op == RELATION_OPERATOR.TOK_GTE)
            {
                // There is no IL instruction for >=
                // We check for the <  of the
                // top two values on the stack ...
                // This will put 0 ( FALSE ) or 1 (TRUE)
                // on the top of stack...
                // Load Zero and
                // Check == once again...

                cont.CodeOutput.Emit(OpCodes.Clt);
                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }
            else if (m_op == RELATION_OPERATOR.TOK_LTE)
            {
                // There is no IL instruction for <=
                // We check for the >  of the
                // top two values on the stack ...
                // This will put 0 ( FALSE ) or 1 (TRUE)
                // on the top of stack...
                // Load Zero and
                // Check == once again...

                cont.CodeOutput.Emit(OpCodes.Cgt);
                cont.CodeOutput.Emit(OpCodes.Ldc_I4, 0);
                cont.CodeOutput.Emit(OpCodes.Ceq);
            }



            return(true);
        }