internal override void GenCode0(CodeGenContext context)
        {
            context.newLine(location);
            recv.GenCode(context);
            LOCAL recvLocal = context.StoreInLocal("recv", PrimitiveType.Object, recv.location);

            // lhs.vid=(lhs.vid() op rhs)
            new METHOD_CALL(recvLocal, vid + "=", new METHOD_CALL(new METHOD_CALL(recvLocal, vid, new ARGS(null, null, null, null, recv.location, true), null, recv.location), op, rhs, location), location).GenCode(context);

            context.ReleaseLocal(recvLocal.local, true);
        }
        internal void GenCode(CodeGenContext context, PERWAPI.CILLabel endLabel, int RescueTemp, int exception)
        {
            for (RESCUE_CLAUSE clause = this; clause != null; clause = clause.next)
            {
                PERWAPI.CILLabel nextClause = context.NewLabel();
                PERWAPI.CILLabel thisClause = context.NewLabel();

                context.ldc_i4(0);
                LOCAL exceptionCaught = context.StoreInLocal("caught", PERWAPI.PrimitiveType.Boolean, this.location);

                for (Node type = clause.types; type != null; type = type.nd_next)
                {
                    PERWAPI.CILLabel label1 = context.NewLabel();

                    // Precompute each separately to avoid computing a list of types
                    type.GenCode0(context);
                    LOCAL tt = context.StoreInLocal("type", PERWAPI.PrimitiveType.Object, type.location);

                    new METHOD_CALL(tt, ID.intern(Tokens.tEQQ), new AST.LOCAL(exception, type.location), type.location).GenCode(context);

                    context.ReleaseLocal(tt.local, true);

                    context.call(Runtime.Eval.Test);
                    context.brfalse(label1);
                    context.PushTrue();
                    context.stloc(exceptionCaught.local);
                    context.CodeLabel(label1);                  
                }

                context.ldloc(exceptionCaught.local);
                context.brtrue(thisClause);
                context.ReleaseLocal(exceptionCaught.local, true);

                context.br(nextClause);

                context.CodeLabel(thisClause);

                if (clause.var != null)
                {
                    clause.var.Assign(context, new AST.LOCAL(exception, clause.var.location));
                    context.pop();
                }

                if (clause.body != null)
                    clause.body.GenCode(context);
                else
                    context.ldnull();

                if (context.Reachable())
                    context.stloc(RescueTemp);

                // reset $!
                //Eval.ruby_errinfo.value = null;
                context.ldsfld(Runtime.Eval.ruby_errinfo);
                context.ldnull();
                context.stfld(Runtime.global_variable.value);

                context.Goto(endLabel);

                context.CodeLabel(nextClause);
            }
        }
Beispiel #3
0
        internal override void GenCode0(CodeGenContext context)
        {
            PERWAPI.CILLabel endLabel = context.NewLabel();
            Node clause;

            if (target != null)
            {
                context.newLine(target.location);
                target.GenCode(context);
                LOCAL t = context.StoreInLocal("target", PrimitiveType.Object, location);
                
                for (clause = body; clause != null && clause is WHEN; clause = clause.nd_next)
                    ((WHEN)clause).GenCode(context, t, endLabel);

                context.ReleaseLocal(t.local, true);
            }
            else
            {
                for (clause = body; clause != null && clause is WHEN; clause = clause.nd_next)
                {
                    context.newLine(clause.location);
                    ((WHEN)clause).GenCode(context, endLabel);
                }
            }

            if (clause != null) /* assume else clause */
                clause.GenCode(context);
            else
                context.ldnull();

            context.CodeLabel(endLabel);
            context.newEndPoint(location);
        }