private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) { block = block.cloneBlockAndFrame(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); // a normal block passed to define_method changes to do arity checking; make it a lambda RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // various instructions can tell this scope is not an ordinary block but a block representing // a method definition. block.getBody().getStaticScope().makeArgumentScope(); return new ProcMethod(this, proc, visibility, name); }
private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) { block = block.cloneBlockAndFrame(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); // a normal block passed to define_method changes to do arity checking; make it a lambda RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // various instructions can tell this scope is not an ordinary block but a block representing // a method definition. block.getBody().getStaticScope().makeArgumentScope(); return new ProcMethod(this, proc, visibility, name); }
private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args) { // string to eval RubyString src = args[0].convertToString(); boolean bindingGiven = args.length > 1 && args[1] != context.nil; Binding binding = bindingGiven ? getBindingForEval(context, args[1]) : context.currentBinding(); if (args.length > 2) { // file given, use it and force it into binding binding.setFile(args[2].convertToString().toString()); if (args.length > 3) { // line given, use it and force it into binding // -1 because parser uses zero offsets and other code compensates binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1); } else { // filename given, but no line, start from the beginning. binding.setLine(0); } } else if (!bindingGiven) { // no binding given, use (eval) and start from first line. binding.setFile("(eval)"); binding.setLine(0); } // set method to current frame's, which should be caller's String frameName = context.getFrameName(); if (frameName != null) binding.setMethod(frameName); if (bindingGiven) recv = binding.getSelf(); return Interpreter.evalWithBinding(context, recv, src, binding); }
private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args) { // string to eval RubyString src = args[0].convertToString(); boolean bindingGiven = args.length > 1 && args[1] != context.nil; Binding binding = bindingGiven ? getBindingForEval(context, args[1]) : context.currentBinding(); if (args.length > 2) { // file given, use it and force it into binding binding.setFile(args[2].convertToString().toString()); if (args.length > 3) { // line given, use it and force it into binding // -1 because parser uses zero offsets and other code compensates binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1); } else { // filename given, but no line, start from the beginning. binding.setLine(0); } } else if (!bindingGiven) { // no binding given, use (eval) and start from first line. binding.setFile("(eval)"); binding.setLine(0); } // set method to current frame's, which should be caller's String frameName = context.getFrameName(); if (frameName != null) binding.setMethod(frameName); if (bindingGiven) recv = binding.getSelf(); return Interpreter.evalWithBinding(context, recv, src, binding); }
private DynamicMethod createProcMethod(String name, Visibility visibility, RubyProc proc) { Block block = proc.getBlock(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); StaticScope scope = block.getBody().getStaticScope(); // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope scope.makeArgumentScope(); Arity arity = block.arity(); // just using required is broken...but no more broken than before zsuper refactoring scope.setRequiredArgs(arity.required()); if(!arity.isFixed()) { scope.setRestArg(arity.required()); } return new ProcMethod(this, proc, visibility); }
private DynamicMethod createProcMethod(String name, Visibility visibility, RubyProc proc) { Block block = proc.getBlock(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); StaticScope scope = block.getBody().getStaticScope(); // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope scope.makeArgumentScope(); Arity arity = block.arity(); // just using required is broken...but no more broken than before zsuper refactoring scope.setRequiredArgs(arity.required()); if(!arity.isFixed()) { scope.setRestArg(arity.required()); } return new ProcMethod(this, proc, visibility); }
private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block, EvalBinding evalBinding) { Ruby runtime = context.runtime; // string to eval RubyString src = args[0].convertToString(); boolean bindingGiven = args.length > 1 && !args[1].isNil(); Binding binding = bindingGiven ? evalBinding.convertToBinding(args[1]) : context.currentBinding(); if (args.length > 2) { // file given, use it and force it into binding binding.setFile(args[2].convertToString().toString()); if (args.length > 3) { // line given, use it and force it into binding // -1 because parser uses zero offsets and other code compensates binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1); } else { // filename given, but no line, start from the beginning. binding.setLine(0); } } else if (bindingGiven) { // binding given, use binding's file and line-number } else { // no binding given, use (eval) and start from first line. binding.setFile("(eval)"); binding.setLine(0); } // set method to current frame's, which should be caller's String frameName = context.getFrameName(); if (frameName != null) binding.setMethod(frameName); if (bindingGiven) recv = binding.getSelf(); return ASTInterpreter.evalWithBinding(context, recv, src, binding); }
private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block, EvalBinding evalBinding) { Ruby runtime = context.runtime; // string to eval RubyString src = args[0].convertToString(); boolean bindingGiven = args.length > 1 && !args[1].isNil(); Binding binding = bindingGiven ? evalBinding.convertToBinding(args[1]) : context.currentBinding(); if (args.length > 2) { // file given, use it and force it into binding binding.setFile(args[2].convertToString().toString()); if (args.length > 3) { // line given, use it and force it into binding // -1 because parser uses zero offsets and other code compensates binding.setLine(((int) args[3].convertToInteger().getLongValue()) - 1); } else { // filename given, but no line, start from the beginning. binding.setLine(0); } } else if (bindingGiven) { // binding given, use binding's file and line-number } else { // no binding given, use (eval) and start from first line. binding.setFile("(eval)"); binding.setLine(0); } // set method to current frame's, which should be caller's String frameName = context.getFrameName(); if (frameName != null) binding.setMethod(frameName); if (bindingGiven) recv = binding.getSelf(); return ASTInterpreter.evalWithBinding(context, recv, src, binding); }