DefineInstanceMethodInstr.java

  1. package org.jruby.ir.instructions;

  2. import org.jruby.ir.*;
  3. import org.jruby.ir.operands.Operand;
  4. import org.jruby.ir.runtime.IRRuntimeHelpers;
  5. import org.jruby.ir.transformations.inlining.CloneInfo;
  6. import org.jruby.parser.StaticScope;
  7. import org.jruby.runtime.DynamicScope;
  8. import org.jruby.runtime.ThreadContext;
  9. import org.jruby.runtime.builtin.IRubyObject;

  10. public class DefineInstanceMethodInstr extends Instr implements FixedArityInstr {
  11.     private final IRMethod method;

  12.     // SSS FIXME: Implicit self arg -- make explicit to not get screwed by inlining!
  13.     public DefineInstanceMethodInstr(IRMethod method) {
  14.         super(Operation.DEF_INST_METH);
  15.         this.method = method;
  16.     }

  17.     @Override
  18.     public Operand[] getOperands() {
  19.         return EMPTY_OPERANDS;
  20.     }

  21.     @Override
  22.     public String toString() {
  23.         return getOperation() + "(" + method.getName() + ", " + method.getFileName() + ")";
  24.     }

  25.     @Override
  26.     public boolean computeScopeFlags(IRScope scope) {
  27.         scope.getFlags().add(IRFlags.REQUIRES_DYNSCOPE);
  28.         scope.getFlags().add(IRFlags.REQUIRES_VISIBILITY);
  29.         return true;
  30.     }

  31.     public IRMethod getMethod() {
  32.         return method;
  33.     }

  34.     @Override
  35.     public Instr clone(CloneInfo ii) {
  36.         return new DefineInstanceMethodInstr(method);
  37.     }

  38.     @Override
  39.     public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
  40.         IRRuntimeHelpers.defInterpretedInstanceMethod(context, method, currDynScope, self);

  41.         return null; // unused; symbol is propagated
  42.     }

  43.     @Override
  44.     public void visit(IRVisitor visitor) {
  45.         visitor.DefineInstanceMethodInstr(this);
  46.     }
  47. }