Пример #1
0
        protected override void DoGenerate(CilEmitter emitter)
        {
            ILabel comparisonLabel = emitter.GenerateLabel();
            ILabel contentsLabel   = emitter.GenerateLabel();

            variable = emitter.EmitLocalVarDeclaration("STEPS_LOOP_VAR" + stepCountExpr.lexline + "_" + stepCountExpr.lexline, typeof(int));
            stepCountExpr.EmitRValue(emitter);
            variable.EmitAssignment();

            comparisonLabel.Emit();

            variable.EmitValue();
            emitter.EmitInt32(0);
            emitter.EmitComparison(">");

            after.EmitJumpIfFalse();
            contentsLabel.Emit();

            statement.Generate(emitter, contentsLabel, comparisonLabel);

            variable.EmitValue();
            emitter.EmitInt32(1);
            emitter.EmitBinaryOperator("-");
            variable.EmitAssignment();

            comparisonLabel.EmitJump();

            /*
             *
             * logicalExpression.jumping(0, after)
             *
             * create label
             *
             * emit label
             *
             * stmt.Gen(label, begin)
             *
             * emit goto begin
             *
             */
        }
Пример #2
0
        // a * 3 + b * 2 - c
        private void TestComplexExpression()
        {
            // Initialize  variables a, b and c

            // a = 5
            ILocalVariable aVar = emitter.EmitLocalVarDeclaration("A", typeof(int));

            emitter.EmitInt32(5);
            aVar.EmitAssignment();

            // b = 6
            ILocalVariable bVar = emitter.EmitLocalVarDeclaration("B", typeof(int));

            emitter.EmitInt32(6);
            bVar.EmitAssignment();

            // c = 7
            ILocalVariable cVar = emitter.EmitLocalVarDeclaration("B", typeof(int));

            emitter.EmitInt32(7);
            cVar.EmitAssignment();

            // Emit lhs R Value
            aVar.EmitValue();
            emitter.EmitInt32(3);
            emitter.EmitBinaryOperator("*");

            // Emit rhs R Value
            bVar.EmitValue();
            emitter.EmitInt32(2);
            emitter.EmitBinaryOperator("*");

            emitter.EmitBinaryOperator("+");

            cVar.EmitValue();
            emitter.EmitBinaryOperator("-");

            emitter.EmitWrite(typeof(int));
        }
Пример #3
0
        public override void EmitRValue(CilEmitter emitter)
        {
            if (!prefix)
            {
                variableExpr.EmitRValue(emitter);
            }

            variableExpr.EmitRValue(emitter);
            emitter.EmitInt32(1);
            emitter.EmitBinaryOperator(add ? "+" : "-");
            variableExpr.EmitAssignment();

            if (prefix)
            {
                variableExpr.EmitRValue(emitter);
            }
        }
Пример #4
0
 public override void EmitRValue(CilEmitter emitter)
 {
     emitter.EmitInt32(value);
 }