示例#1
0
        public override void Compile(Execution.VM.ByteCode bc)
        {
            m_Exp1.Compile(bc);

            if (m_Operator == Operator.Or)
            {
                Instruction i = bc.Emit_Jump(OpCode.JtOrPop, -1);
                m_Exp2.Compile(bc);
                i.NumVal = bc.GetJumpPointForNextInstruction();
                return;
            }

            if (m_Operator == Operator.And)
            {
                Instruction i = bc.Emit_Jump(OpCode.JfOrPop, -1);
                m_Exp2.Compile(bc);
                i.NumVal = bc.GetJumpPointForNextInstruction();
                return;
            }


            if (m_Exp2 != null)
            {
                m_Exp2.Compile(bc);
            }

            bc.Emit_Operator(OperatorToOpCode(m_Operator));

            if (ShouldInvertBoolean(m_Operator))
            {
                bc.Emit_Operator(OpCode.Not);
            }
        }
        private void CompileOp(Execution.VM.ByteCode bc, Operator op, Expression exp)
        {
            if (op == Operator.Or)
            {
                Instruction i = bc.Emit_Jump(OpCode.JtOrPop, -1);
                exp.Compile(bc);
                i.NumVal = bc.GetJumpPointForNextInstruction();
                return;
            }

            if (op == Operator.And)
            {
                Instruction i = bc.Emit_Jump(OpCode.JfOrPop, -1);
                exp.Compile(bc);
                i.NumVal = bc.GetJumpPointForNextInstruction();
                return;
            }


            if (exp != null)
            {
                exp.Compile(bc);
            }

            bc.Emit_Operator(OperatorToOpCode(op));

            if (ShouldInvertBoolean(op))
            {
                bc.Emit_Operator(OpCode.Not);
            }
        }
示例#3
0
        public override void Compile(Execution.VM.ByteCode bc)
        {
            List <int> endJumps = new List <int>();

            int lastIfJmp = -1;

            foreach (var ifblock in m_Ifs)
            {
                using (bc.EnterSource(ifblock.Source))
                {
                    if (lastIfJmp != -1)
                    {
                        bc.SetNumVal(lastIfJmp, bc.GetJumpPointForNextInstruction());
                    }

                    ifblock.Exp.CompilePossibleLiteral(bc);
                    lastIfJmp = bc.Emit_Jump(OpCode.Jf, -1);
                    bc.Emit_Enter(ifblock.StackFrame);
                    ifblock.Block.Compile(bc);
                }

                using (bc.EnterSource(m_End))
                    bc.Emit_Leave(ifblock.StackFrame);

                endJumps.Add(bc.Emit_Jump(OpCode.Jump, -1));
            }

            bc.SetNumVal(lastIfJmp, bc.GetJumpPointForNextInstruction());

            if (m_Else != null)
            {
                using (bc.EnterSource(m_Else.Source))
                {
                    bc.Emit_Enter(m_Else.StackFrame);
                    m_Else.Block.Compile(bc);
                }

                using (bc.EnterSource(m_End))
                    bc.Emit_Leave(m_Else.StackFrame);
            }

            foreach (var endjmp in endJumps)
            {
                bc.SetNumVal(endjmp, bc.GetJumpPointForNextInstruction());
            }
        }
示例#4
0
        public override void Compile(Execution.VM.ByteCode bc)
        {
            List <Instruction> endJumps = new List <Instruction>();

            Instruction lastIfJmp = null;

            foreach (var ifblock in m_Ifs)
            {
                using (bc.EnterSource(ifblock.Source))
                {
                    if (lastIfJmp != null)
                    {
                        lastIfJmp.NumVal = bc.GetJumpPointForNextInstruction();
                    }

                    ifblock.Exp.Compile(bc);
                    lastIfJmp = bc.Emit_Jump(OpCode.Jf, -1);
                    bc.Emit_Enter(ifblock.StackFrame);
                    ifblock.Block.Compile(bc);
                }

                using (bc.EnterSource(m_End))
                    bc.Emit_Leave(ifblock.StackFrame);

                endJumps.Add(bc.Emit_Jump(OpCode.Jump, -1));
            }

            lastIfJmp.NumVal = bc.GetJumpPointForNextInstruction();

            if (m_Else != null)
            {
                using (bc.EnterSource(m_ElseRef))
                {
                    bc.Emit_Enter(m_ElseStackFrame);
                    m_Else.Compile(bc);
                }

                using (bc.EnterSource(m_End))
                    bc.Emit_Leave(m_ElseStackFrame);
            }

            foreach (var endjmp in endJumps)
            {
                endjmp.NumVal = bc.GetJumpPointForNextInstruction();
            }
        }