Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Komax refactoring factor methods #849

Closed
wants to merge 5 commits into from

3 participants

@komax

Refactoring on:

  • descriptive identifiers
  • factorization of long conditions into separate variable
  • private helper methods for code duplicates
  • small amount @Override
@komax komax referenced this pull request
Closed

Komax codereview #847

@enebo
Owner

I think verifybytecode looks like a good change to me but you might want to isolate current JIT code changes to it's own PR and perhaps only make the verifyByteCode() method as the sole PR. @headius can decide whether he likes the change since he primarily works in that package space.

The Ruby try { inputstream.close() } bulletproofing can also be it's own PR. We generally don't bulletproof code against things which should not happen (although we should have had an assert there) but your pattern is quite common and someone will likely eventually submit that change again.

You can make a massive @Override PR and I will apply that so long as it has no other changes. We have not been up to date with that in a long time. Make sure you @Oveeride with respect to Java 6 and not Java 7 though.

@enebo enebo closed this
@headius
Owner

Yeah re Java 6 versus Java 7; I believe Java 6 will error if you @Override an interface method...so make sure any change you make works on 6 and 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2013
  1. @komax

    refactored ASTCompiler checking for dropping last value on stack (new…

    komax authored
    … help
    
    method discardTopValue()); Addition of some @Override
  2. @komax

    tiny code formatting: @Override, factorization into local variables i…

    komax authored
    …nstead of
    
    long method calls
  3. @komax
  4. @komax
  5. @komax

    simplification for equals() method and code styling

    komax authored
    Conflicts:
    	src/org/jruby/ir/IRScope.java
This page is out of date. Refresh to see the latest.
View
18 src/org/jruby/Ruby.java
@@ -504,7 +504,11 @@ public void runFromMain(InputStream inputStream, String filename) {
Node scriptNode = parseFromMain(inputStream, filename);
// done with the stream, shut it down
- try {inputStream.close();} catch (IOException ioe) {}
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException ioe) {}
ThreadContext context = getCurrentContext();
@@ -718,7 +722,8 @@ private void handeCompileError(Node node, Throwable t) {
private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader classLoader, boolean dump) {
if (config.getCompileMode() == CompileMode.FORCEIR) {
- final IRScope scope = IRBuilder.createIRBuilder(getIRManager(), is1_9()).buildRoot((RootNode) node);
+ final IRBuilder irBuilder = IRBuilder.createIRBuilder(getIRManager(), is1_9());
+ final IRScope scope = irBuilder.buildRoot((RootNode) node);
final Class compiled = JVMVisitor.compile(this, scope, classLoader);
final StaticScope staticScope = scope.getStaticScope();
staticScope.setModule(getTopSelf().getMetaClass());
@@ -1242,7 +1247,9 @@ private void initRoot() {
classClass.setMetaClass(classClass);
RubyClass metaClass;
- if (oneNine) metaClass = basicObjectClass.makeMetaClass(classClass);
+ if (oneNine) {
+ metaClass = basicObjectClass.makeMetaClass(classClass);
+ }
metaClass = objectClass.makeMetaClass(classClass);
metaClass = moduleClass.makeMetaClass(metaClass);
metaClass = classClass.makeMetaClass(metaClass);
@@ -1372,7 +1379,10 @@ private void initCore() {
RubyStruct.createStructClass(this);
}
if (profile.allowClass("Tms")) {
- tmsStruct = RubyStruct.newInstance(structClass, new IRubyObject[]{newString("Tms"), newSymbol("utime"), newSymbol("stime"), newSymbol("cutime"), newSymbol("cstime")}, Block.NULL_BLOCK);
+ tmsStruct = RubyStruct.newInstance(structClass,
+ new IRubyObject[]{ newString("Tms"),
+ newSymbol("utime"), newSymbol("stime"), newSymbol("cutime"),
+ newSymbol("cstime")}, Block.NULL_BLOCK);
}
if (profile.allowClass("Binding")) {
View
10 src/org/jruby/ast/executable/AbstractScript.java
@@ -8,7 +8,6 @@
import java.math.BigInteger;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
-import org.jruby.Ruby;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
import org.jruby.RubyModule;
@@ -34,31 +33,38 @@
public AbstractScript() {
}
+ @Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, Block block) {
return __file__(context, self, IRubyObject.NULL_ARRAY, block);
}
+ @Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject arg, Block block) {
return __file__(context, self, new IRubyObject[] {arg}, block);
}
+ @Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2, Block block) {
return __file__(context, self, new IRubyObject[] {arg1, arg2}, block);
}
+ @Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
return __file__(context, self, new IRubyObject[] {arg1, arg2, arg3}, block);
}
@Deprecated
+ @Override
public IRubyObject load(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
return load(context, self, false);
}
+ @Override
public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap) {
return null;
}
+ @Override
public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
return __file__(context, self, args, block);
}
@@ -407,6 +413,7 @@ public void setEncoding(int index, String encStr) {
return callSites;
}
+ @Override
public final void setFilename(String filename) {
this.filename = filename;
}
@@ -415,6 +422,7 @@ public final void initFromDescriptor(String descriptor) {
runtimeCache.initFromDescriptor(descriptor);
}
+ @Override
public void setRootScope(StaticScope scope) {
runtimeCache.scopes[0] = scope;
}
View
240 src/org/jruby/compiler/ASTCompiler.java
@@ -374,6 +374,11 @@ public void compileArguments(Node node, BodyCompiler context) {
context.convertToJavaArray();
}
}
+
+ private void discardTopValue(boolean expr, BodyCompiler context) {
+ // TODO: don't require pop
+ if (!expr) context.consumeCurrentValue();
+ }
public class VariableArityArguments implements ArgumentsCallback {
private Node node;
@@ -496,6 +501,7 @@ public void compileAssignment(Node node, BodyCompiler context) {
public void compileAlias(final AliasNode alias, BodyCompiler context, boolean expr) {
CompilerCallback args = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(alias.getNewName(), context, true);
compile(alias.getOldName(), context, true);
@@ -503,9 +509,7 @@ public void call(BodyCompiler context) {
};
context.defineAlias(args);
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileAnd(Node node, BodyCompiler context, final boolean expr) {
@@ -521,13 +525,14 @@ public void compileAnd(Node node, BodyCompiler context, final boolean expr) {
} else {
compile(andNode.getFirstNode(), context, true);
BranchCallback longCallback = new BranchCallback() {
+ @Override
public void branch(BodyCompiler context) {
compile(andNode.getSecondNode(), context, true);
}
};
context.performLogicalAnd(longCallback);
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
}
@@ -603,9 +608,7 @@ public void compileArgsCat(Node node, BodyCompiler context, boolean expr) {
compile(argsCatNode.getFirstNode(), context,true);
compile(argsCatNode.getSecondNode(), context,true);
context.argsCat();
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileArgsPush(Node node, BodyCompiler context, boolean expr) {
@@ -616,6 +619,7 @@ private void compileAttrAssign(Node node, BodyCompiler context, boolean expr) {
final AttrAssignNode attrAssignNode = (AttrAssignNode) node;
CompilerCallback receiverCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(attrAssignNode.getReceiverNode(), context,true);
}
@@ -633,6 +637,7 @@ public void compileAttrAssignAssignment(Node node, BodyCompiler context) {
final AttrAssignNode attrAssignNode = (AttrAssignNode) node;
CompilerCallback receiverCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(attrAssignNode.getReceiverNode(), context,true);
}
@@ -651,8 +656,7 @@ public void compileBackref(Node node, BodyCompiler context, boolean expr) {
BackRefNode iVisited = (BackRefNode) node;
context.performBackref(iVisited.getType());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileBegin(Node node, BodyCompiler context, boolean expr) {
@@ -662,7 +666,9 @@ public void compileBegin(Node node, BodyCompiler context, boolean expr) {
}
public void compileBignum(Node node, BodyCompiler context, boolean expr) {
- if (expr) context.createNewBignum(((BignumNode) node).getValue());
+ if (expr) {
+ context.createNewBignum(((BignumNode) node).getValue());
+ }
}
public void compileBlock(Node node, BodyCompiler context, boolean expr) {
@@ -680,6 +686,7 @@ public void compileBreak(Node node, BodyCompiler context, boolean expr) {
CompilerCallback valueCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
if (breakNode.getValueNode() != null) {
compile(breakNode.getValueNode(), context, true);
@@ -690,14 +697,14 @@ public void call(BodyCompiler context) {
};
context.issueBreakEvent(valueCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileCall(Node node, BodyCompiler context, boolean expr) {
final CallNode callNode = (CallNode) node;
CompilerCallback receiverCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(callNode.getReceiverNode(), context, true);
}
@@ -714,13 +721,13 @@ public void call(BodyCompiler context) {
if (argument instanceof FixnumNode) {
if (MethodIndex.hasFastFixnumOps(name)) {
context.getInvocationCompiler().invokeBinaryFixnumRHS(name, receiverCallback, ((FixnumNode)argument).getValue());
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
return;
}
} else if (argument instanceof FloatNode) {
if (MethodIndex.hasFastFloatOps(name)) {
context.getInvocationCompiler().invokeBinaryFloatRHS(name, receiverCallback, ((FloatNode)argument).getValue());
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
return;
}
}
@@ -744,9 +751,7 @@ public void call(BodyCompiler context) {
name, receiverCallback, argsCallback,
callType, closureArg, callNode.getIterNode() instanceof IterNode);
}
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
private static final Map<Class, Map<Class, Map<String, String>>> Intrinsics;
@@ -898,6 +903,7 @@ public void call(BodyCompiler context) {
for (Node node : whenNodes) {
final WhenNode whenNode = (WhenNode)node;
CompilerCallback body = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
if (RubyInstanceConfig.FULL_TRACE_ENABLED) context.traceLine();
compile(whenNode.getBodyNode(), context, expr);
@@ -908,6 +914,7 @@ public void call(BodyCompiler context) {
}
CompilerCallback fallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(elseNode, context, expr);
}
@@ -966,10 +973,12 @@ private void addConditionalForWhen(final WhenNode whenNode, List<ArgumentsCallba
if (whenNode instanceof WhenOneArgNode) {
// one arg but it's an array, treat it as a proper array
conditionals.add(new ArgumentsCallback() {
+ @Override
public int getArity() {
return 1;
}
+ @Override
public void call(BodyCompiler context) {
compile(whenNode.getExpressionNodes(), context, true);
}
@@ -990,6 +999,7 @@ public void compileClass(Node node, BodyCompiler context, boolean expr) {
CompilerCallback superCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(superNode, context, true);
}
@@ -1000,6 +1010,7 @@ public void call(BodyCompiler context) {
CompilerCallback bodyCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
boolean oldIsAtRoot = isAtRoot;
isAtRoot = false;
@@ -1014,6 +1025,7 @@ public void call(BodyCompiler context) {
CompilerCallback pathCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
if (cpathNode instanceof Colon2Node) {
Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
@@ -1037,9 +1049,9 @@ public void call(BodyCompiler context) {
ASTInspector inspector = new ASTInspector();
inspector.inspect(classNode.getBodyNode());
- context.defineClass(classNode.getCPath().getName(), classNode.getScope(), superCallback, pathCallback, bodyCallback, null, inspector);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ context.defineClass(classNode.getCPath().getName(), classNode.getScope(),
+ superCallback, pathCallback, bodyCallback, null, inspector);
+ discardTopValue(expr, context);
}
public void compileSClass(Node node, BodyCompiler context, boolean expr) {
@@ -1047,6 +1059,7 @@ public void compileSClass(Node node, BodyCompiler context, boolean expr) {
CompilerCallback receiverCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(sclassNode.getReceiverNode(), context, true);
}
@@ -1054,6 +1067,7 @@ public void call(BodyCompiler context) {
CompilerCallback bodyCallback = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
boolean oldIsAtRoot = isAtRoot;
isAtRoot = false;
@@ -1070,29 +1084,28 @@ public void call(BodyCompiler context) {
inspector.inspect(sclassNode.getBodyNode());
context.defineClass("SCLASS", sclassNode.getScope(), null, null, bodyCallback, receiverCallback, inspector);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileClassVar(Node node, BodyCompiler context, boolean expr) {
ClassVarNode classVarNode = (ClassVarNode) node;
context.retrieveClassVariable(classVarNode.getName());
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileClassVarAsgn(Node node, BodyCompiler context, boolean expr) {
final ClassVarAsgnNode classVarAsgnNode = (ClassVarAsgnNode) node;
CompilerCallback value = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(classVarAsgnNode.getValueNode(), context, true);
}
};
context.assignClassVariable(classVarAsgnNode.getName(), value);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileClassVarAsgnAssignment(Node node, BodyCompiler context) {
@@ -1107,14 +1120,14 @@ public void compileClassVarDecl(Node node, BodyCompiler context, boolean expr) {
final ClassVarDeclNode classVarDeclNode = (ClassVarDeclNode) node;
CompilerCallback value = new CompilerCallback() {
+ @Override
public void call(BodyCompiler context) {
compile(classVarDeclNode.getValueNode(), context, true);
}
};
context.declareClassVariable(classVarDeclNode.getName(), value);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileClassVarDeclAssignment(Node node, BodyCompiler context) {
@@ -1150,8 +1163,7 @@ public void call(BodyCompiler context) {
}
});
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileConstDeclAssignment(Node node, BodyCompiler context) {
@@ -1175,9 +1187,7 @@ public void compileConst(Node node, BodyCompiler context, boolean expr) {
ConstNode constNode = (ConstNode) node;
context.retrieveConstant(constNode.getName());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
- // XXX: const lookup can trigger const_missing; is that enough to warrant it always being executed?
+ discardTopValue(expr, context);
}
public void compileColon2(Node node, BodyCompiler context, boolean expr) {
@@ -1204,8 +1214,7 @@ public void call(BodyCompiler context) {
compile(iVisited.getLeftNode(), context, true);
}
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileColon3(Node node, BodyCompiler context, boolean expr) {
@@ -1213,8 +1222,7 @@ public void compileColon3(Node node, BodyCompiler context, boolean expr) {
String name = iVisited.getName();
context.retrieveConstantFromObject(name);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileGetDefinitionBase(final Node node, BodyCompiler context) {
@@ -1799,8 +1807,7 @@ public void call(BodyCompiler context) {
defnNode.getScope(), body, args, null, inspector, isAtRoot,
defnNode.getPosition().getFile(), defnNode.getPosition().getStartLine(),
Helpers.encodeParameterList(argsNode));
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileDefs(Node node, BodyCompiler context, boolean expr) {
@@ -1857,8 +1864,7 @@ public void call(BodyCompiler context) {
defsNode.getScope(), body, args, receiver, inspector, false,
defsNode.getPosition().getFile(), defsNode.getPosition().getStartLine(),
Helpers.encodeParameterList(argsNode));
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileArgs(Node node, BodyCompiler context, boolean expr) {
@@ -1931,8 +1937,7 @@ public void call(BodyCompiler context) {
optionalNotGiven,
restAssignment,
blockAssignment);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileDot(Node node, BodyCompiler context, boolean expr) {
@@ -2054,8 +2059,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().invokeDynamic("`", null, argsCallback, CallType.FUNCTIONAL, null, false);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileEnsureNode(Node node, BodyCompiler context, boolean expr) {
@@ -2085,8 +2089,7 @@ public void branch(BodyCompiler context) {
context.loadNil();
}
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileEvStr(Node node, BodyCompiler context, boolean expr) {
@@ -2094,8 +2097,7 @@ public void compileEvStr(Node node, BodyCompiler context, boolean expr) {
compile(evStrNode.getBody(), context,true);
context.asString();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileFalse(Node node, BodyCompiler context, boolean expr) {
@@ -2117,9 +2119,7 @@ public void compileFCall(Node node, BodyCompiler context, boolean expr) {
} else {
context.getInvocationCompiler().invokeDynamic(fcallNode.getName(), null, argsCallback, CallType.FUNCTIONAL, closureArg, fcallNode.getIterNode() instanceof IterNode);
}
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
private CompilerCallback getBlock(Node node) {
@@ -2228,8 +2228,7 @@ public void branch(BodyCompiler context) {
}
});
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
private void becomeTrueOrFalse(BodyCompiler context) {
@@ -2284,8 +2283,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().invokeDynamic("each", receiverCallback, null, CallType.NORMAL, closureArg, true);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileForIter(Node node, BodyCompiler context) {
@@ -2360,9 +2358,7 @@ public void call(BodyCompiler context) {
} else {
context.assignGlobalVariable(globalAsgnNode.getName(), value);
}
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileGlobalAsgnAssignment(Node node, BodyCompiler context) {
@@ -2541,8 +2537,7 @@ public void call(BodyCompiler context) {
};
context.assignInstanceVariable(instAsgnNode.getName(), value);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileInstAsgnAssignment(Node node, BodyCompiler context) {
@@ -2645,8 +2640,7 @@ public void compileMatch(Node node, BodyCompiler context, boolean expr) {
compile(matchNode.getRegexpNode(), context,true);
context.match(is1_9());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileMatch2(Node node, BodyCompiler context, boolean expr) {
@@ -2660,8 +2654,7 @@ public void call(BodyCompiler context) {
};
context.match2(value, is1_9());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileMatch3(Node node, BodyCompiler context, boolean expr) {
@@ -2671,8 +2664,7 @@ public void compileMatch3(Node node, BodyCompiler context, boolean expr) {
compile(matchNode.getValueNode(), context,true);
context.match3(is1_9());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileModule(Node node, BodyCompiler context, boolean expr) {
@@ -2712,8 +2704,7 @@ public void call(BodyCompiler context) {
inspector.inspect(moduleNode.getBodyNode());
context.defineModule(moduleNode.getCPath().getName(), moduleNode.getScope(), pathCallback, bodyCallback, inspector);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileMultipleAsgn(Node node, BodyCompiler context, boolean expr) {
@@ -2852,8 +2843,7 @@ public void call(BodyCompiler context) {
context.forEachInValueArray(0, multipleAsgnNode.getHeadNode().size(), multipleAsgnNode.getHeadNode(), headAssignCallback, argsCallback);
}
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileNewline(Node node, BodyCompiler context, boolean expr) {
@@ -2884,8 +2874,7 @@ public void call(BodyCompiler context) {
context.pollThreadEvents();
context.issueNextEvent(valueCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileNthRef(Node node, BodyCompiler context, boolean expr) {
@@ -2906,8 +2895,7 @@ public void compileNot(Node node, BodyCompiler context, boolean expr) {
compile(notNode.getConditionNode(), context, true);
context.negateCurrentValue();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpAsgnAnd(Node node, BodyCompiler context, boolean expr) {
@@ -2924,8 +2912,7 @@ public void branch(BodyCompiler context) {
context.performLogicalAnd(longCallback);
context.pollThreadEvents();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpAsgnOr(Node node, BodyCompiler context, boolean expr) {
@@ -2977,8 +2964,7 @@ public void branch(BodyCompiler context) {
}
context.pollThreadEvents();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
/**
@@ -3026,8 +3012,7 @@ public void compileOpAsgn(Node node, BodyCompiler context, boolean expr) {
}
context.pollThreadEvents();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpAsgnWithOr(Node node, BodyCompiler context, boolean expr) {
@@ -3043,8 +3028,7 @@ public void call(BodyCompiler context) {
ArgumentsCallback argsCallback = getArgsCallback(opAsgnNode.getValueNode());
context.getInvocationCompiler().invokeOpAsgnWithOr(opAsgnNode.getVariableName(), opAsgnNode.getVariableNameAsgn(), receiverCallback, argsCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpAsgnWithAnd(Node node, BodyCompiler context, boolean expr) {
@@ -3060,8 +3044,7 @@ public void call(BodyCompiler context) {
ArgumentsCallback argsCallback = getArgsCallback(opAsgnNode.getValueNode());
context.getInvocationCompiler().invokeOpAsgnWithAnd(opAsgnNode.getVariableName(), opAsgnNode.getVariableNameAsgn(), receiverCallback, argsCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpAsgnWithMethod(Node node, BodyCompiler context, boolean expr) {
@@ -3085,8 +3068,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().invokeOpAsgnWithMethod(opAsgnNode.getOperatorName(), opAsgnNode.getVariableName(), opAsgnNode.getVariableNameAsgn(), receiverCallback, argsCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpElementAsgn(Node node, BodyCompiler context, boolean expr) {
@@ -3157,8 +3139,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().opElementAsgnWithOr(receiverCallback, argsCallback, valueCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpElementAsgnWithAnd(Node node, BodyCompiler context, boolean expr) {
@@ -3179,8 +3160,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().opElementAsgnWithAnd(receiverCallback, argsCallback, valueCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOpElementAsgnWithMethod(Node node, BodyCompiler context, boolean expr) {
@@ -3201,8 +3181,7 @@ public void call(BodyCompiler context) {
};
context.getInvocationCompiler().opElementAsgnWithMethod(receiverCallback, argsCallback, valueCallback, opElementAsgnNode.getOperatorName());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileOr(Node node, BodyCompiler context, boolean expr) {
@@ -3226,8 +3205,7 @@ public void branch(BodyCompiler context) {
};
context.performLogicalOr(longCallback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
}
@@ -3246,8 +3224,7 @@ public void call(BodyCompiler context) {
}
};
context.createNewEndBlock(closureBody);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compilePreExe(Node node, BodyCompiler context, boolean expr) {
@@ -3265,16 +3242,14 @@ public void call(BodyCompiler context) {
}
};
context.runBeginBlock(preExeNode.getScope(), closureBody);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileRedo(Node node, BodyCompiler context, boolean expr) {
//RedoNode redoNode = (RedoNode)node;
context.issueRedoEvent();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileRegexp(Node node, BodyCompiler context, boolean expr) {
@@ -3285,9 +3260,7 @@ public void compileRegexp(Node node, BodyCompiler context, boolean expr) {
public void compileRescue(Node node, BodyCompiler context, boolean expr) {
compileRescueInternal(node, context, false);
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
private void compileRescueInternal(Node node, BodyCompiler context, final boolean light) {
@@ -3413,8 +3386,7 @@ public void compileRetry(Node node, BodyCompiler context, boolean expr) {
context.pollThreadEvents();
context.issueRetryEvent();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileReturn(Node node, BodyCompiler context, boolean expr) {
@@ -3427,8 +3399,7 @@ public void compileReturn(Node node, BodyCompiler context, boolean expr) {
}
context.performReturn();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileRoot(Node node, ScriptCompiler context, ASTInspector inspector) {
@@ -3482,8 +3453,7 @@ public void compileSplat(Node node, BodyCompiler context, boolean expr) {
compile(splatNode.getValue(), context, true);
splatCurrentValue(context);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
protected void splatCurrentValue(BodyCompiler context) {
@@ -3515,9 +3485,7 @@ public void compileSuper(Node node, BodyCompiler context, boolean expr) {
} else {
context.getInvocationCompiler().invokeDynamic(null, null, argsCallback, CallType.SUPER, closureArg, superNode.getIterNode() instanceof IterNode);
}
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileSValue(Node node, BodyCompiler context, boolean expr) {
@@ -3526,14 +3494,12 @@ public void compileSValue(Node node, BodyCompiler context, boolean expr) {
compile(svalueNode.getValue(), context,true);
context.singlifySplattedValue();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileSymbol(Node node, BodyCompiler context, boolean expr) {
context.createNewSymbol(((SymbolNode) node).getName());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileToAry(Node node, BodyCompiler context, boolean expr) {
@@ -3542,8 +3508,7 @@ public void compileToAry(Node node, BodyCompiler context, boolean expr) {
compile(toAryNode.getValue(), context,true);
context.aryToAry();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileTrue(Node node, BodyCompiler context, boolean expr) {
@@ -3560,8 +3525,7 @@ public void call(BodyCompiler context) {
}
};
context.undefMethod(nameArg);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileUntil(Node node, BodyCompiler context, boolean expr) {
@@ -3597,8 +3561,7 @@ public void branch(BodyCompiler context) {
}
context.pollThreadEvents();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
}
@@ -3606,16 +3569,14 @@ public void compileVAlias(Node node, BodyCompiler context, boolean expr) {
VAliasNode valiasNode = (VAliasNode) node;
context.aliasGlobal(valiasNode.getNewName(), valiasNode.getOldName());
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileVCall(Node node, BodyCompiler context, boolean expr) {
VCallNode vcallNode = (VCallNode) node;
context.getInvocationCompiler().invokeDynamic(vcallNode.getName(), null, null, CallType.VARIABLE, null, false);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileWhile(Node node, BodyCompiler context, boolean expr) {
@@ -3649,8 +3610,7 @@ public void branch(BodyCompiler context) {
}
context.pollThreadEvents();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
}
@@ -3668,8 +3628,7 @@ public void call(BodyCompiler context) {
}
};
context.getInvocationCompiler().invokeDynamic("`", null, argsCallback, CallType.FUNCTIONAL, null, false);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileYield(Node node, BodyCompiler context, boolean expr) {
@@ -3695,8 +3654,7 @@ public void call(BodyCompiler context) {
context.getInvocationCompiler().yield(argsCallback2, yieldNode.getExpandArguments());
}
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileZArray(Node node, BodyCompiler context, boolean expr) {
@@ -3711,8 +3669,7 @@ public void compileZSuper(Node node, BodyCompiler context, boolean expr) {
CompilerCallback closure = getBlock(zsuperNode.getIterNode());
context.callZSuper(closure);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileArgsCatArguments(Node node, BodyCompiler context, boolean expr) {
@@ -3724,9 +3681,7 @@ public void compileArgsCatArguments(Node node, BodyCompiler context, boolean exp
compileArguments(argsCatNode.getFirstNode(), context);
compile(argsCatNode.getSecondNode(), context,true);
context.argsCatToArguments();
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileArgsPushArguments(Node node, BodyCompiler context, boolean expr) {
@@ -3737,9 +3692,7 @@ public void compileArgsPushArguments(Node node, BodyCompiler context, boolean ex
compileArguments(argsPushNode.getFirstNode(), context);
compile(argsPushNode.getSecondNode(), context,true);
context.appendToObjectArray();
-
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
public void compileArrayArguments(Node node, BodyCompiler context, boolean expr) {
@@ -3755,9 +3708,7 @@ public void nextValue(BodyCompiler context, Object sourceArray, int index) {
context.setLinePosition(arrayNode.getPosition());
context.createObjectArray(arrayNode.childNodes().toArray(), callback);
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
- // leave as a normal array
+ discardTopValue(expr, context);
}
public void compileSplatArguments(Node node, BodyCompiler context, boolean expr) {
@@ -3765,7 +3716,6 @@ public void compileSplatArguments(Node node, BodyCompiler context, boolean expr)
compile(splatNode.getValue(), context,true);
context.splatToArguments();
- // TODO: don't require pop
- if (!expr) context.consumeCurrentValue();
+ discardTopValue(expr, context);
}
}
View
21 src/org/jruby/compiler/impl/StandardASMCompiler.java
@@ -227,8 +227,7 @@ public void writeInvokers(File destination) throws IOException {
descriptor.getCallConfig(),
descriptor.getFile(),
descriptor.getLine());
-
- if (VERIFY_CLASSFILES) CheckClassAdapter.verify(new ClassReader(invokerBytes), false, new PrintWriter(System.err));
+ verifyByteCode(invokerBytes);
writeClassFile(destination, invokerBytes, descriptor.getInvokerName());
}
@@ -239,8 +238,7 @@ public void writeInvokers(File destination) throws IOException {
descriptor.getMethod(),
descriptor.getFile(),
descriptor.getLine());
-
- if (VERIFY_CLASSFILES) CheckClassAdapter.verify(new ClassReader(callbackBytes), false, new PrintWriter(System.err));
+ verifyByteCode(callbackBytes);
writeClassFile(destination, callbackBytes, descriptor.getCallbackName());
}
@@ -251,8 +249,7 @@ public void writeInvokers(File destination) throws IOException {
descriptor.getMethod(),
descriptor.getFile(),
descriptor.getLine());
-
- if (VERIFY_CLASSFILES) CheckClassAdapter.verify(new ClassReader(callbackBytes), false, new PrintWriter(System.err));
+ verifyByteCode(callbackBytes);
writeClassFile(destination, callbackBytes, descriptor.getCallbackName());
}
@@ -261,7 +258,7 @@ public void writeInvokers(File destination) throws IOException {
private void writeClass(String classname, File destination, ClassWriter writer) throws IOException {
// verify the class
byte[] bytecode = writer.toByteArray();
- if (VERIFY_CLASSFILES) CheckClassAdapter.verify(new ClassReader(bytecode), false, new PrintWriter(System.err));
+ verifyByteCode(bytecode);
writeClassFile(destination, bytecode, classname);
}
@@ -291,6 +288,12 @@ private void writeClassFile(File destination, byte[] bytecode, String classname)
}
}
+ private void verifyByteCode(byte[] bytecode) {
+ if (VERIFY_CLASSFILES) {
+ CheckClassAdapter.verify(new ClassReader(bytecode), false, new PrintWriter(System.err));
+ }
+ }
+
public static class InvokerDescriptor {
private final String rubyName;
private final String javaName;
@@ -414,6 +417,7 @@ public ClassVisitor getClassVisitor() {
return classWriter;
}
+ @Override
public void startScript(StaticScope scope) {
classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
@@ -459,6 +463,7 @@ public void startScript(StaticScope scope) {
classWriter.visitSource(sourcename, sourceFile.getAbsolutePath());
}
+ @Override
public void endScript(boolean generateLoad, boolean generateMain) {
// add Script#run impl, used for running this script with a specified threadcontext and self
// root method of a script is always in __file__ method
@@ -625,6 +630,7 @@ public CacheCompiler getCacheCompiler() {
return cacheCompiler;
}
+ @Override
public BodyCompiler startMethod(String rubyName, String javaName, CompilerCallback args, StaticScope scope, ASTInspector inspector, int scopeIndex) {
RootScopedBodyCompiler methodCompiler = new MethodBodyCompiler(this, rubyName, javaName, inspector, scope, scopeIndex);
@@ -633,6 +639,7 @@ public BodyCompiler startMethod(String rubyName, String javaName, CompilerCallba
return methodCompiler;
}
+ @Override
public BodyCompiler startFileMethod(CompilerCallback args, StaticScope scope, ASTInspector inspector) {
MethodBodyCompiler methodCompiler = new MethodBodyCompiler(this, "__file__", "__file__", inspector, scope, 0);
View
69 src/org/jruby/ir/IRScope.java
@@ -335,7 +335,7 @@ public IRScope(IRManager manager, IRScope lexicalParent, String name,
setupLexicalContainment();
}
- private final void setupLexicalContainment() {
+ private void setupLexicalContainment() {
if (manager.isDryRun()) {
lexicalChildren = new ArrayList<IRScope>();
if (lexicalParent != null) lexicalParent.addChildScope(this);
@@ -346,6 +346,21 @@ private final void setupLexicalContainment() {
public int hashCode() {
return scopeId;
}
+<<<<<<< HEAD
+=======
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final IRScope other = (IRScope) obj;
+ return this.scopeId == other.scopeId;
+ }
+>>>>>>> c33ef72... simplification for equals() method and code styling
protected void addChildScope(IRScope scope) {
lexicalChildren.add(scope);
@@ -371,10 +386,15 @@ public void addInstr(Instr i) {
// SSS FIXME: If more instructions set these flags, there may be
// a better way to do this by encoding flags in its own object
// and letting every instruction update it.
- if (i instanceof ThreadPollInstr) threadPollInstrsCount++;
- else if (i instanceof BreakInstr) this.hasBreakInstrs = true;
- else if (i instanceof NonlocalReturnInstr) this.hasNonlocalReturns = true;
- else if (i instanceof DefineMetaClassInstr) this.canReceiveNonlocalReturns = true;
+ if (i instanceof ThreadPollInstr) {
+ threadPollInstrsCount++;
+ } else if (i instanceof BreakInstr) {
+ this.hasBreakInstrs = true;
+ } else if (i instanceof NonlocalReturnInstr) {
+ this.hasNonlocalReturns = true;
+ } else if (i instanceof DefineMetaClassInstr) {
+ this.canReceiveNonlocalReturns = true;
+ }
instrList.add(i);
}
@@ -587,7 +607,10 @@ private void setupLabelPCs(HashMap<Label, Integer> labelIPCMap) {
private Instr[] prepareInstructionsForInterpretation() {
checkRelinearization();
- if (linearizedInstrArray != null) return linearizedInstrArray; // Already prepared
+ if (linearizedInstrArray != null) {
+ // Already prepared
+ return linearizedInstrArray;
+ }
try {
buildLinearization(); // FIXME: compiler passes should have done this
@@ -875,39 +898,41 @@ public String toString() {
}
public String toStringInstrs() {
- StringBuilder b = new StringBuilder();
+ StringBuilder stringBuilder = new StringBuilder();
int i = 0;
for (Instr instr : instrList) {
- if (i > 0) b.append("\n");
+ if (i > 0) {
+ stringBuilder.append("\n");
+ }
- b.append(" ").append(i).append('\t').append(instr);
+ stringBuilder.append(" ").append(i).append('\t').append(instr);
i++;
}
if (!nestedClosures.isEmpty()) {
- b.append("\n\n------ Closures encountered in this scope ------\n");
+ stringBuilder.append("\n\n------ Closures encountered in this scope ------\n");
for (IRClosure c: nestedClosures)
- b.append(c.toStringBody());
- b.append("------------------------------------------------\n");
+ stringBuilder.append(c.toStringBody());
+ stringBuilder.append("------------------------------------------------\n");
}
- return b.toString();
+ return stringBuilder.toString();
}
public String toPersistableString() {
- StringBuilder b = new StringBuilder();
+ StringBuilder stringBuilder = new StringBuilder();
- b.append("Scope:<");
- b.append(name);
- b.append(">");
+ stringBuilder.append("Scope:<");
+ stringBuilder.append(name);
+ stringBuilder.append(">");
for (Instr instr : instrList) {
- b.append("\n");
- b.append(instr);
+ stringBuilder.append("\n");
+ stringBuilder.append(instr);
}
- return b.toString();
+ return stringBuilder.toString();
}
public String toStringVariables() {
@@ -1006,7 +1031,9 @@ public LocalVariable getNewLocalVariable(String name, int depth) {
}
protected void initEvalScopeVariableAllocator(boolean reset) {
- if (reset || evalScopeVars == null) evalScopeVars = new LocalVariableAllocator();
+ if (reset || evalScopeVars == null) {
+ evalScopeVars = new LocalVariableAllocator();
+ }
}
public TemporaryVariable getNewTemporaryVariable() {
View
1  src/org/jruby/ir/IRScriptBody.java
@@ -34,6 +34,7 @@ public LocalVariable getImplicitBlockArg() {
return null;
}
+ @Override
public String getScopeName() {
return "ScriptBody";
}
View
14 src/org/jruby/ir/targets/JVMVisitor.java
@@ -191,10 +191,12 @@ public void emit(IRModuleBody method) {
jvm.method().pushHandle(jvm.clsData().clsName, name, method.getStaticScope().getRequiredArgs());
}
+ @Override
public void visit(Instr instr) {
instr.visit(this);
}
+ @Override
public void visit(Operand operand) {
if (operand.hasKnownValue()) {
operand.visit(this);
@@ -353,8 +355,7 @@ public void CallInstr(CallInstr callInstr) {
if ( (name.equals("+") || name.equals("-") || name.equals("*") || name.equals("/"))
&& numArgs == 1
&& args[0] instanceof Fixnum
- && callInstr.getCallType() == CallType.NORMAL)
- {
+ && callInstr.getCallType() == CallType.NORMAL) {
m.loadLocal(0);
m.loadLocal(2); // dummy to satisfy signature of existing target linker (MathLinker)
visit(callInstr.getReceiver());
@@ -409,7 +410,8 @@ public void ConstMissingInstr(ConstMissingInstr constmissinginstr) {
jvm.method().loadContext();
jvm.method().adapter.ldc("const_missing");
jvm.method().pushSymbol(constmissinginstr.getMissingConst());
- jvm.method().invokeVirtual(Type.getType(RubyModule.class), Method.getMethod("org.jruby.runtime.builtin.IRubyObject callMethod(org.jruby.runtime.ThreadContext, java.lang.String, org.jruby.runtime.builtin.IRubyObject)"));
+ final Method invokeVirtualMethod = Method.getMethod("org.jruby.runtime.builtin.IRubyObject callMethod(org.jruby.runtime.ThreadContext, java.lang.String, org.jruby.runtime.builtin.IRubyObject)");
+ jvm.method().invokeVirtual(Type.getType(RubyModule.class), invokeVirtualMethod);
}
@Override
@@ -464,13 +466,15 @@ public void DefineClassInstr(DefineClassInstr defineclassinstr) {
// is meta?
a.ldc(newIRClassBody instanceof IRMetaClassBody);
- m.invokeHelper("newClassForIR", RubyClass.class, ThreadContext.class, String.class, IRubyObject.class, RubyModule.class, Object.class, boolean.class);
+ m.invokeHelper("newClassForIR", RubyClass.class, ThreadContext.class,
+ String.class, IRubyObject.class, RubyModule.class, Object.class, boolean.class);
//// static scope
a.aload(0);
a.aload(1);
a.ldc(scopeString);
- a.invokestatic(p(Helpers.class), "decodeScope", "(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/parser/StaticScope;Ljava/lang/String;)Lorg/jruby/parser/StaticScope;");
+ a.invokestatic(p(Helpers.class), "decodeScope",
+ "(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/parser/StaticScope;Ljava/lang/String;)Lorg/jruby/parser/StaticScope;");
a.swap();
// set into StaticScope
Something went wrong with that request. Please try again.