コード例 #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));
        }