-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use static name for super in a module method
Module methods have a dynamic hierarchy, but do not have a dynamic super target name. This eliminates part of the frame requirement for super within a module method, on the way to getting __callee__ working.
- Loading branch information
Showing
11 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
core/src/main/java/org/jruby/ir/instructions/ModuleSuperInstr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.jruby.ir.instructions; | ||
|
||
import org.jcodings.specific.USASCIIEncoding; | ||
import org.jruby.RubyInstanceConfig; | ||
import org.jruby.RubySymbol; | ||
import org.jruby.ir.IRFlags; | ||
import org.jruby.ir.IRScope; | ||
import org.jruby.ir.IRVisitor; | ||
import org.jruby.ir.Operation; | ||
import org.jruby.ir.operands.Operand; | ||
import org.jruby.ir.operands.Variable; | ||
import org.jruby.ir.operands.WrappedIRClosure; | ||
import org.jruby.ir.persistence.IRReaderDecoder; | ||
import org.jruby.ir.runtime.IRRuntimeHelpers; | ||
import org.jruby.ir.transformations.inlining.CloneInfo; | ||
import org.jruby.parser.StaticScope; | ||
import org.jruby.runtime.Block; | ||
import org.jruby.runtime.CallSite; | ||
import org.jruby.runtime.CallType; | ||
import org.jruby.runtime.DynamicScope; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.util.ByteList; | ||
|
||
import java.util.EnumSet; | ||
|
||
// SSS FIXME: receiver is never used -- being passed in only to meet requirements of CallInstr | ||
|
||
public class ModuleSuperInstr extends CallInstr { | ||
// clone constructor | ||
public ModuleSuperInstr(IRScope scope, Operation op, Variable result, RubySymbol name, Operand receiver, Operand[] args, | ||
Operand closure, boolean isPotentiallyRefined, CallSite callSite, long callSiteId) { | ||
super(scope, op, CallType.SUPER, result, name, | ||
receiver, args, closure, isPotentiallyRefined, callSite, callSiteId); | ||
} | ||
|
||
// normal constructor | ||
public ModuleSuperInstr(IRScope scope, Operation op, Variable result, RubySymbol name, Operand receiver, Operand[] args, Operand closure, | ||
boolean isPotentiallyRefined) { | ||
super(scope, op, CallType.SUPER, result, name, | ||
receiver, args, closure, isPotentiallyRefined); | ||
} | ||
|
||
// specific instr constructor | ||
public ModuleSuperInstr(IRScope scope, Variable result, RubySymbol name, Operand receiver, Operand[] args, Operand closure, | ||
boolean isPotentiallyRefined) { | ||
this(scope, Operation.UNRESOLVED_SUPER, result, name, receiver, args, closure, isPotentiallyRefined); | ||
} | ||
|
||
@Override | ||
public boolean computeScopeFlags(IRScope scope, EnumSet<IRFlags> flags) { | ||
super.computeScopeFlags(scope, flags); | ||
scope.setUsesSuper(); | ||
flags.add(IRFlags.REQUIRES_CLASS); // for current class and method name | ||
flags.add(IRFlags.REQUIRES_METHODNAME); // for current class and method name | ||
return true; | ||
} | ||
|
||
@Override | ||
public Instr clone(CloneInfo ii) { | ||
return new ModuleSuperInstr(ii.getScope(), Operation.UNRESOLVED_SUPER, ii.getRenamedVariable(getResult()), name, | ||
getReceiver().cloneForInlining(ii), cloneCallArgs(ii), | ||
getClosureArg() == null ? null : getClosureArg().cloneForInlining(ii), | ||
isPotentiallyRefined(), getCallSite(), getCallSiteId()); | ||
} | ||
|
||
public static ModuleSuperInstr decode(IRReaderDecoder d) { | ||
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("decoding call"); | ||
int callTypeOrdinal = d.decodeInt(); | ||
CallType callType = CallType.fromOrdinal(callTypeOrdinal); | ||
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("decoding call, calltype(ord): " + callType); | ||
RubySymbol methAddr = d.decodeSymbol(); | ||
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("decoding call, methaddr: " + methAddr); | ||
Operand receiver = d.decodeOperand(); | ||
int argsCount = d.decodeInt(); | ||
boolean hasClosureArg = argsCount < 0; | ||
int argsLength = hasClosureArg ? (-1 * (argsCount + 1)) : argsCount; | ||
if (RubyInstanceConfig.IR_READING_DEBUG) | ||
System.out.println("ARGS: " + argsLength + ", CLOSURE: " + hasClosureArg); | ||
Operand[] args = new Operand[argsLength]; | ||
|
||
for (int i = 0; i < argsLength; i++) { | ||
args[i] = d.decodeOperand(); | ||
} | ||
|
||
Operand closure = hasClosureArg ? d.decodeOperand() : null; | ||
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("before result"); | ||
|
||
return new ModuleSuperInstr(d.getCurrentScope(), d.decodeVariable(), d.decodeSymbol(), receiver, args, closure, d.getCurrentScope().maybeUsingRefinements()); | ||
} | ||
|
||
/* | ||
// We cannot convert this into a NoCallResultInstr | ||
@Override | ||
public Instr discardResult() { | ||
return this; | ||
} | ||
*/ | ||
|
||
@Override | ||
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { | ||
IRubyObject[] args = prepareArguments(context, self, currScope, currDynScope, temp); | ||
Block block = prepareBlock(context, self, currScope, currDynScope, temp); | ||
|
||
return IRRuntimeHelpers.moduleSuper(context, self, getId(), args, block); | ||
} | ||
|
||
@Override | ||
public void visit(IRVisitor visitor) { | ||
visitor.ModuleSuperInstr(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/main/java/org/jruby/ir/targets/indy/ModuleSuperInvokeSite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jruby.ir.targets.indy; | ||
|
||
import org.jruby.RubyClass; | ||
import org.jruby.ir.runtime.IRRuntimeHelpers; | ||
import org.jruby.runtime.Block; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
|
||
import java.lang.invoke.MethodType; | ||
|
||
/** | ||
* Created by headius on 10/23/14. | ||
*/ | ||
public class ModuleSuperInvokeSite extends SuperInvokeSite { | ||
public ModuleSuperInvokeSite(MethodType type, String name, String splatmapString, String file, int line) { | ||
super(type, name, splatmapString, file, line); | ||
} | ||
|
||
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, RubyClass definingModule, IRubyObject[] args, Block block) throws Throwable { | ||
// TODO: get rid of caller | ||
// TODO: caching | ||
return IRRuntimeHelpers.moduleSuperSplatArgs(context, self, superName, args, block, splatMap); | ||
} | ||
|
||
public IRubyObject fail(ThreadContext context, IRubyObject caller, IRubyObject self, RubyClass definingModule, IRubyObject[] args, Block block) throws Throwable { | ||
return invoke(context, caller, self, definingModule, args, block); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters