internal void GenCall(CodeGenContext context) { int result = context.CreateLocal("result", PrimitiveType.Object); PERWAPI.CILLabel endLabel = context.NewLabel(); PERWAPI.CILLabel retryLabel = context.NewLabel(); context.CodeLabel(retryLabel); context.StartBlock(Clause.Try); { // object result = Call(...) GenCall0(context); context.stloc(result); context.Goto(endLabel); } PERWAPI.TryBlock tryBlock = context.EndTryBlock(); context.StartBlock(Clause.Catch); { CatchBreakException(context, result, endLabel); } context.EndCatchBlock(Runtime.BreakExceptionRef, tryBlock); context.StartBlock(Clause.Catch); { CatchRetryException(context, retryLabel); } context.EndCatchBlock(Runtime.RetryExceptionRef, tryBlock); context.CodeLabel(endLabel); context.ldloc(result); context.ReleaseLocal(result, true); }
internal override void GenCode0(CodeGenContext context) { PERWAPI.CILLabel finalLabel = context.NewLabel(); int RescueTemp = context.CreateLocal("rescueTemp", PERWAPI.PrimitiveType.Object); context.ldnull(); context.stloc(RescueTemp); if (ensure != null) { context.StartBlock(Clause.Try); // outer try block with finally context.StartBlock(Clause.Try); // inner try block with catch } GenInnerBlock(context, RescueTemp); if (ensure != null) { context.Goto(finalLabel); PERWAPI.TryBlock innerTry = context.EndTryBlock(); context.StartBlock(Clause.Catch); GenRescue(context, null, 0, null); context.EndCatchBlock(Runtime.SystemExceptionRef, innerTry); PERWAPI.TryBlock outerTry = context.EndTryBlock(); // Fixme: reset labels to prevent branches out of finally block. context.StartBlock(Clause.Finally); ensure.GenCode(context); if (context.Reachable()) context.pop(); context.endfinally(); context.EndFinallyBlock(outerTry); context.CodeLabel(finalLabel); context.newEndPoint(location); } context.ldloc(RescueTemp); context.ReleaseLocal(RescueTemp, true); }
internal void AddScopeBody(CodeGenContext context) { returnTemp = context.CreateLocal("returnTemp", PrimitiveType.Object); context.labels = new Labels(); context.labels.Redo = context.NewLabel(); context.labels.Return = context.NewLabel(); // try { ... } context.StartBlock(Clause.Try); { if (BEGIN != null) BEGIN.GenCode(context); context.CodeLabel(context.labels.Redo); if (body != null) { body.GenCode(context); if (context.Reachable()) context.stloc(returnTemp); } context.Goto(context.labels.Return); } PERWAPI.TryBlock tryBlock = context.EndTryBlock(); CatchReturnException(context, tryBlock); // ReturnLabel: // return returnTemp; context.CodeLabel(context.labels.Return); context.newEndPoint(location); if (context.Method.GetRetType() != PERWAPI.PrimitiveType.Void) context.ldloc(returnTemp); context.ret(); context.ReleaseLocal(returnTemp, true); }
internal override void GenCode0(CodeGenContext context) { int receiverLocal = 0; // singleton_class(caller, receiver).define_method(...); context.newStartPoint(location); if (!(receiver is AST.CALL)) { context.ldloc(0); receiver.GenCode(context); } else { receiver.GenCode(context); receiverLocal = context.CreateLocal("receiverLocal", PrimitiveType.Object); context.stloc(receiverLocal); context.ldloc(0); context.ldloc(receiverLocal); } context.call(Runtime.Class.singleton_class); DefineMethod(context); if (receiver is AST.CALL) context.ReleaseLocal(receiverLocal, true); }
internal override void Defined(CodeGenContext context) { if (qualified) if (scope != null) { // object result; int result = context.CreateLocal("result", PrimitiveType.Object); PERWAPI.CILLabel endLabel = context.NewLabel(); // try { context.StartBlock(Clause.Try); { // result = Eval.const_defined(scope, vid, caller); scope.GenCode(context); context.ldstr(vid.ToString()); context.ldloc(0); context.call(Runtime.Eval.const_defined); context.stloc(result); context.leave(endLabel); } TryBlock block = context.EndTryBlock(); // catch (System.Exception) { context.StartBlock(Clause.Catch); { // result = null; context.ldnull(); context.stloc(result); context.leave(endLabel); } context.EndCatchBlock(Runtime.SystemExceptionRef, block); context.CodeLabel(endLabel); context.ldloc(result); context.ReleaseLocal(result, true); } else { context.ldsfld(Ruby.Compiler.Runtime.Init.rb_cObject); context.ldstr(vid.ToString()); context.ldloc(0); context.call(Runtime.Eval.const_defined); } else { context.ruby_cbase(parent_scope); context.ldstr(vid.ToString()); context.ldloc(0); context.call(Runtime.Eval.const_defined); } }
internal override void GenCode0(CodeGenContext context) { int RescueTemp = context.CreateLocal("rescueTemp", PERWAPI.PrimitiveType.Object); int ExceptionTemp = context.CreateLocal("exceptionTemp", PERWAPI.PrimitiveType.Object); PERWAPI.CILLabel endLabel = context.NewLabel(); context.StartBlock(Clause.Try); { expr.GenCode(context); if (context.Reachable()) { context.stloc(RescueTemp); context.Goto(endLabel); } } PERWAPI.TryBlock tryBlock = context.EndTryBlock(); context.StartBlock(Clause.Catch); { PERWAPI.CILLabel stdErrLabel = context.NewLabel(); context.stloc(ExceptionTemp); context.ldloc(ExceptionTemp); context.ldfld(Runtime.RubyException.parent); context.isinst(Runtime.StandardErrorRef); context.brtrue(stdErrLabel); context.ldloc(ExceptionTemp); context.throwOp(); context.CodeLabel(stdErrLabel); rescue.GenCode(context); if (context.Reachable()) { context.stloc(RescueTemp); context.Goto(endLabel); } } context.EndCatchBlock(Runtime.RubyExceptionRef, tryBlock); context.CodeLabel(endLabel); context.ldloc(RescueTemp); context.ReleaseLocal(RescueTemp, true); context.ReleaseLocal(ExceptionTemp, true); }
internal void GenRescue(CodeGenContext context, PERWAPI.CILLabel endLabel, int RescueTemp, RESCUE_CLAUSE clauses) { // catch (System.Exception e) { int e = context.StoreInTemp("e", Runtime.SystemExceptionRef, location); //if (e is Ruby.ControlException) PERWAPI.CILLabel else1 = context.NewLabel(); context.ldloc(e); context.isinst(Runtime.ControlExceptionRef); context.brfalse(else1); // throw e; context.rethrow(); context.CodeLabel(else1); // Ruby.Exception exception; int exception = context.CreateLocal("exception", Runtime.ExceptionRef); //if (!(e is Ruby.RubyException)) PERWAPI.CILLabel else2 = context.NewLabel(); PERWAPI.CILLabel end = context.NewLabel(); context.ldloc(e); context.isinst(Runtime.RubyExceptionRef); context.brtrue(else2); // exception = new Ruby.CLRException(frame, e); context.ldloc(0); context.ldloc(e); context.newobj(Runtime.CLRException.ctor); context.stloc(exception); context.br(end); //else context.CodeLabel(else2); // exception = (Ruby.RubyException)e.parent; context.ldloc(e); context.cast(Runtime.RubyExceptionRef); context.ldfld(Runtime.RubyException.parent); context.stloc(exception); context.CodeLabel(end); //Eval.ruby_errinfo.value = exception; context.ldsfld(Runtime.Eval.ruby_errinfo); context.ldloc(exception); context.stfld(Runtime.global_variable.value); if (clauses != null) clauses.GenCode(context, endLabel, RescueTemp, exception); context.rethrow(); context.ReleaseLocal(e, true); context.ReleaseLocal(exception, true); }