Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Formatting + comment tweaks in IR builder
  • Loading branch information
subbuss committed Jan 13, 2015
1 parent c7d8cc4 commit b39a9cc
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -43,7 +43,7 @@
// ----------------------------------------------
// Note that in general, there will be lots of a = b kind of copies
// introduced in the IR because the translation is entirely single-node focused.
// An example will make this clear
// An example will make this clear.
//
// RUBY:
// v = @f
Expand Down Expand Up @@ -74,7 +74,7 @@
// ----------------------------
// - We should be returning null from the build methods where it is a normal "error" condition
// - We should be returning manager.getNil() where the actual return value of a build is the ruby nil operand
// Look in buildIf for an example of this
// Look in buildIf for an example of this.
//
// 3. Temporary variable reuse
// ---------------------------
Expand Down Expand Up @@ -270,15 +270,15 @@ public void cloneIntoHostScope(IRBuilder b, IRScope s) {
// of cloning.
private Stack<Label> activeRescuers = new Stack<>();

private int _lastProcessedLineNum = -1;

// Since we are processing ASTs, loop bodies are processed in depth-first manner
// with outer loops encountered before inner loops, and inner loops finished before outer ones.
//
// So, we can keep track of loops in a loop stack which keeps track of loops as they are encountered.
// This lets us implement next/redo/break/retry easily for the non-closure cases
// This lets us implement next/redo/break/retry easily for the non-closure cases.
private Stack<IRLoop> loopStack = new Stack<>();

private int _lastProcessedLineNum = -1;

public IRLoop getCurrentLoop() {
return loopStack.isEmpty() ? null : loopStack.peek();
}
Expand Down Expand Up @@ -842,8 +842,8 @@ public Operand buildBegin(BeginNode beginNode, IRScope s) {
}

public Operand buildBignum(BignumNode node) {
// SSS: Since bignum literals are effectively interned objects, no need to copyAndReturnValue(...)
// Or is this a premature optimization?
// Since bignum literals are effectively interned objects, no need to copyAndReturnValue(...)
// SSS FIXME: Or is this a premature optimization?
return new Bignum(node.getValue());
}

Expand Down Expand Up @@ -959,8 +959,8 @@ private void receiveBreakException(final IRScope s, Operand block, final CallIns
}

public Operand buildCall(CallNode callNode, IRScope s) {
Node callArgsNode = callNode.getArgsNode();
Node receiverNode = callNode.getReceiverNode();
Node callArgsNode = callNode.getArgsNode();
Node receiverNode = callNode.getReceiverNode();

// check for "string".freeze
if (receiverNode instanceof StrNode && callNode.getName().equals("freeze")) {
Expand All @@ -972,17 +972,16 @@ public Operand buildCall(CallNode callNode, IRScope s) {
// new Callinstr( ... , build(receiverNode, s), ...)
// that is incorrect IR because the receiver has to be built *before* call arguments are built
// to preserve expected code execution order
Operand receiver = build(receiverNode, s);
Operand[] args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(callNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(callResult, callNode.getName(), receiver, args, block);
Operand receiver = build(receiverNode, s);
Operand[] args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(callNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(callResult, callNode.getName(), receiver, args, block);

// This is to support the ugly Proc.new with no block, which must see caller's frame
if (
callNode.getName().equals("new") &&
receiverNode instanceof ConstNode &&
((ConstNode)receiverNode).getName().equals("Proc")) {
if ( callNode.getName().equals("new") &&
receiverNode instanceof ConstNode &&
((ConstNode)receiverNode).getName().equals("Proc")) {
callInstr.setProcNew(true);
}

Expand Down Expand Up @@ -1952,7 +1951,7 @@ public void buildArgsMasgn(Node node, IRScope s, Operand argsArray, boolean isMa
}
}

// SSS: This method is called both for regular multiple assignment as well as argument passing
// This method is called both for regular multiple assignment as well as argument passing
//
// Ex: a,b,*c=v is a regular assignment and in this case, the "values" operand will be non-null
// Ex: { |a,b,*c| ..} is the argument passing case
Expand Down Expand Up @@ -2008,7 +2007,7 @@ private void handleBreakAndReturnsInLambdas(IRClosure s) {
Label rEndLabel = s.getNewLabel();
Label rescueLabel = Label.getGlobalEnsureBlockLabel();

// protect the entire body as it exists now with the global ensure block
// Protect the entire body as it exists now with the global ensure block
addInstrAtBeginning(s, new ExceptionRegionStartMarkerInstr(rescueLabel));
addInstr(s, new ExceptionRegionEndMarkerInstr());

Expand Down Expand Up @@ -2171,12 +2170,12 @@ public Operand buildEnsureNode(EnsureNode ensureNode, IRScope s) {
// Generate IR for code being protected
Operand rv = bodyNode instanceof RescueNode ? buildRescueInternal((RescueNode) bodyNode, s, ebi) : build(bodyNode, s);

// end of protected region
// End of protected region
addInstr(s, new ExceptionRegionEndMarkerInstr());
activeRescuers.pop();

// Clone the ensure body and jump to the end.
// Dont bother if the protected body ended in a return.
// Don't bother if the protected body ended in a return.
if (rv != U_NIL && !(bodyNode instanceof RescueNode)) {
ebi.cloneIntoHostScope(this, s);
addInstr(s, new JumpInstr(ebi.end));
Expand All @@ -2186,8 +2185,8 @@ public Operand buildEnsureNode(EnsureNode ensureNode, IRScope s) {
activeEnsureBlockStack.pop();

// ------------ Emit the ensure body alongwith dummy rescue block ------------
// Now build the dummy rescue block that:
// * catches all exceptions thrown by the body
// Now build the dummy rescue block that
// catches all exceptions thrown by the body
Variable exc = s.createTemporaryVariable();
addInstr(s, new LabelInstr(ebi.dummyRescueBlockLabel));
addInstr(s, new ReceiveJRubyExceptionInstr(exc));
Expand Down Expand Up @@ -2219,11 +2218,11 @@ public Operand buildFalse() {
}

public Operand buildFCall(FCallNode fcallNode, IRScope s) {
Node callArgsNode = fcallNode.getArgsNode();
Node callArgsNode = fcallNode.getArgsNode();
Operand[] args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(fcallNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args, block);
Operand block = setupCallClosure(fcallNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args, block);
receiveBreakException(s, block, callInstr);
return callResult;
}
Expand Down Expand Up @@ -2331,8 +2330,8 @@ public Operand buildFlip(FlipNode flipNode, IRScope s) {
}

public Operand buildFloat(FloatNode node) {
// SSS: Since flaot literals are effectively interned objects, no need to copyAndReturnValue(...)
// Or is this a premature optimization?
// Since flaot literals are effectively interned objects, no need to copyAndReturnValue(...)
// SSS FIXME: Or is this a premature optimization?
return new Float(node.getValue());
}

Expand All @@ -2347,7 +2346,7 @@ public Operand buildFor(ForNode forNode, IRScope s) {
}

public Operand buildForIter(final ForNode forNode, IRScope s) {
// Create a new closure context
// Create a new closure context
IRClosure closure = new IRFor(manager, s, forNode.getPosition().getLine(), forNode.getScope(), Arity.procArityOf(forNode.getVarNode()), forNode.getArgumentType());

// Create a new nested builder to ensure this gets its own IR builder state
Expand All @@ -2357,7 +2356,7 @@ public Operand buildForIter(final ForNode forNode, IRScope s) {
// Prepare all implicit state (self, frame block, etc)
forBuilder.prepareImplicitState(closure);

// Build args
// Build args
Node varNode = forNode.getVarNode();
if (varNode != null && varNode.getNodeType() != null) forBuilder.receiveBlockArgs(forNode, closure);

Expand All @@ -2369,10 +2368,10 @@ public Operand buildForIter(final ForNode forNode, IRScope s) {
// Thread poll on entry of closure
forBuilder.addInstr(closure, new ThreadPollInstr());

// Start label -- used by redo!
// Start label -- used by redo!
forBuilder.addInstr(closure, new LabelInstr(closure.startLabel));

// Build closure body and return the result of the closure
// Build closure body and return the result of the closure
Operand closureRetVal = forNode.getBodyNode() == null ? manager.getNil() : forBuilder.build(forNode.getBodyNode(), closure);
if (closureRetVal != U_NIL) { // can be null if the node is an if node with returns in both branches.
forBuilder.addInstr(closure, new ReturnInstr(closureRetVal));
Expand Down Expand Up @@ -2651,7 +2650,7 @@ public Operand buildMultipleAsgn(MultipleAsgnNode multipleAsgnNode, IRScope s) {
return ret;
}

// SSS: This method is called both for regular multiple assignment as well as argument passing
// This method is called both for regular multiple assignment as well as argument passing
//
// Ex: a,b,*c=v is a regular assignment and in this case, the "values" operand will be non-null
// Ex: { |a,b,*c| ..} is the argument passing case
Expand Down Expand Up @@ -3326,7 +3325,8 @@ public Operand buildSValue(SValueNode node, IRScope s) {
}

public Operand buildSymbol(SymbolNode node) {
// SSS: Since symbols are interned objects, no need to copyAndReturnValue(...)
// Since symbols are interned objects, no need to copyAndReturnValue(...)
// SSS FIXME: Premature opt?
return new Symbol(node.getName(), node.getEncoding());
}

Expand Down

0 comments on commit b39a9cc

Please sign in to comment.