internal override void GenCode0(CodeGenContext context) { context.newLine(location); if (return_val != null) return_val.GenCode(context); else context.ldnull(); if (this.parent_scope is BLOCK) { //throw new Ruby.ReturnException(return_value, this.defining_scope); context.ldarg(0); // current Ruby.MethodBody context.ldfld(Runtime.Block.defining_scope); context.newobj(Runtime.ReturnException.ctor); context.throwOp(); } else if (this.parent_scope is BEGIN) { //throw new Ruby.ReturnException(return_value, caller); context.ldarg("caller"); context.newobj(Runtime.ReturnException.ctor); context.throwOp(); } else { // return context.stloc(parent_scope.returnTemp); context.Goto(context.labels.Return); } }
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 override void GenCode0(CodeGenContext context) { context.newLine(location); if (context.labels != null && context.labels.Retry != null) context.Goto(context.labels.Retry); else { System.Diagnostics.Debug.Assert(this.parent_scope is BLOCK); // throw new Ruby.RetryException(block.defining_scope); context.ldarg(0); // current Ruby.MethodBody context.ldfld(Runtime.Block.defining_scope); context.newobj(Runtime.RetryException.ctor); context.throwOp(); } }
internal override void GenCode0(CodeGenContext context) { context.newLine(location); if (return_val != null) return_val.GenCode(context); else context.ldnull(); if (context.labels != null && context.labels.Break != null) { context.stloc(parent_scope.returnTemp); context.Goto(context.labels.Break); } else { System.Diagnostics.Debug.Assert(this.parent_scope is BLOCK); //throw new Ruby.BreakException(return_value, this.defining_scope); context.ldarg(0); // current Ruby.MethodBody context.ldfld(Runtime.Block.defining_scope); context.newobj(Runtime.BreakException.ctor); context.throwOp(); } }
private void CopyNormalFormals(CodeGenContext context, Scope scope) { PERWAPI.CILLabel OKLabel = context.NewLabel(); if (min_args > 0) { // if (args.Length < min_args) context.ldarg("args"); context.callvirt(Runtime.ArgList.get_Length); int length = context.StoreInTemp("length", PrimitiveType.Int32, location); context.ldloc(length); context.ldc_i4(min_args); context.bge(OKLabel); //context.Inst(Op.clt); //context.brfalse(OKLabel); // context.Branch(BranchOp.bge, OKLabel); // throw new ArgumentError(string.Format("wrong number of arguments ({0} for {1})", args.Length, arity).raise(caller); // FIXME: next line needs a String context.ldstr("wrong number of arguments ({0} for {1})"); context.ldloc(length); context.box(PrimitiveType.Int32); context.ldc_i4(min_args); context.box(PrimitiveType.Int32); context.call(Runtime.SystemString.Format); context.newobj(Runtime.ArgumentError.ctor); context.ldloc(0); context.callvirt(Runtime.Exception.raise); context.throwOp(); context.ReleaseLocal(length, true); // OKLabel: context.CodeLabel(OKLabel); } // Copy parameters to locals for (Node f = normal; f != null; f = f.nd_next) { string name = ID.ToDotNetName(((VAR)f).vid); // local.f = args.GetNext(); context.ldloc(0); context.ldarg("args"); context.callvirt(Runtime.ArgList.GetNext); context.stfld(scope.GetFrameField(name)); } }
private void CatchBreakException(CodeGenContext context, int result, PERWAPI.CILLabel endLabel) { // catch (Exception exception) int exception = context.StoreInTemp("exception", Runtime.BreakExceptionRef, location); PERWAPI.CILLabel reThrowLabel = context.NewLabel(); // if (exception.scope != current_frame) goto reThrowLabel; context.ldloc(0); context.ldloc(exception); context.ldfld(Runtime.BreakException.scope); context.bne( reThrowLabel); // result = exception.return_value; context.ldloc(exception); context.ldfld(Runtime.BreakException.return_value); context.stloc(result); // goto endLabel; context.Goto(endLabel); // reThrowLabel: context.CodeLabel(reThrowLabel); // throw exception; context.ldloc(exception); context.throwOp(); context.ReleaseLocal(exception, true); }
private void CatchRetryException(CodeGenContext context, PERWAPI.CILLabel retryLabel) { // catch (Exception exception) int exception = context.StoreInTemp("exception", Runtime.RetryExceptionRef, location); PERWAPI.CILLabel reThrowLabel = context.NewLabel(); // if (exception.scope != current_frame) goto reThrowLabel; context.ldloc(0); context.ldloc(exception); context.ldfld(Runtime.RetryException.scope); context.bne( reThrowLabel); // goto retryLabel context.Goto(retryLabel); // reThrowLabel: context.CodeLabel(reThrowLabel); // throw exception; context.ldloc(exception); context.throwOp(); context.ReleaseLocal(exception, true); }