CheckArgsArrayArityInstr.java

  1. package org.jruby.ir.instructions;

  2. import org.jruby.RubyArray;
  3. import org.jruby.ir.IRVisitor;
  4. import org.jruby.ir.Operation;
  5. import org.jruby.ir.operands.Fixnum;
  6. import org.jruby.ir.operands.Operand;
  7. import org.jruby.ir.transformations.inlining.CloneInfo;
  8. import org.jruby.parser.StaticScope;
  9. import org.jruby.runtime.DynamicScope;
  10. import org.jruby.runtime.Helpers;
  11. import org.jruby.runtime.ThreadContext;
  12. import org.jruby.runtime.builtin.IRubyObject;

  13. import java.util.Map;

  14. public class CheckArgsArrayArityInstr extends Instr  implements FixedArityInstr {
  15.     public final int required;
  16.     public final int opt;
  17.     public final int rest;
  18.     private Operand argsArray;

  19.     public CheckArgsArrayArityInstr(Operand argsArray, int required, int opt, int rest) {
  20.         super(Operation.CHECK_ARGS_ARRAY_ARITY);

  21.         this.required = required;
  22.         this.opt = opt;
  23.         this.rest = rest;
  24.         this.argsArray = argsArray;
  25.     }

  26.     public Operand getArgsArray() {
  27.         return argsArray;
  28.     }

  29.     @Override
  30.     public Operand[] getOperands() {
  31.         return new Operand[] { argsArray, new Fixnum(required), new Fixnum(opt), new Fixnum(rest) };
  32.     }

  33.     @Override
  34.     public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
  35.         argsArray = argsArray.getSimplifiedOperand(valueMap, force);
  36.     }

  37.     @Override
  38.     public String toString() {
  39.         return super.toString() + "(" + argsArray + ", " +  required + ", " + opt + ", " + rest + ")";
  40.     }

  41.     @Override
  42.     public Instr clone(CloneInfo ii) {
  43.         return new CheckArgsArrayArityInstr(argsArray.cloneForInlining(ii), required, opt, rest);
  44.     }

  45.     @Override
  46.     public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
  47.         RubyArray args = (RubyArray) argsArray.retrieve(context, self, currScope, currDynScope, temp);
  48.         Helpers.irCheckArgsArrayArity(context, args, required, opt, rest);
  49.         return null;
  50.     }

  51.     @Override
  52.     public void visit(IRVisitor visitor) {
  53.         visitor.CheckArgsArrayArityInstr(this);
  54.     }
  55. }