Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4a420c6e08f8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 084268afac45
Choose a head ref
  • 7 commits
  • 10 files changed
  • 1 contributor

Commits on Aug 9, 2015

  1. Copy the full SHA
    5933d09 View commit details
  2. Copy the full SHA
    f7879e5 View commit details
  3. Copy the full SHA
    2531c60 View commit details
  4. Copy the full SHA
    fdcaf20 View commit details
  5. Copy the full SHA
    bf7b220 View commit details
  6. Copy the full SHA
    d7b64b4 View commit details
  7. Copy the full SHA
    084268a View commit details
2 changes: 2 additions & 0 deletions spec/truffle/tags/language/lambda_tags.txt
Original file line number Diff line number Diff line change
@@ -16,3 +16,5 @@ fails:"A lambda expression 'lambda { ... }' assigns variables from parameters fo
fails:"A lambda expression 'lambda { ... }' assigns variables from parameters for definition \n @a = lambda do |a: (@a = -> (a: 1) { a }), b:|\n [a, b]\n end"
fails:"A lambda expression 'lambda { ... }' assigns variables from parameters for definition \n @a = lambda do |a, b=1, *c, (*d, (e)), f: 2, g:, h:, **k, &l|\n [a, b, c, d, e, f, g, h, k, l]\n end"
fails:"A lambda expression 'lambda { ... }' assigns variables from parameters for definition \n @a = lambda do |a, b=1, *c, d, e:, f: 2, g:, **k, &l|\n [a, b, c, d, e, f, g, k, l]\n end"
fails:"A lambda literal -> () { } assigns variables from parameters for definition \n @a = -> (**) { }"
fails:"A lambda literal -> () { } assigns variables from parameters for definition \n @a = -> (a, b) { [a, b] }"
47 changes: 0 additions & 47 deletions truffle/src/main/java/org/jruby/truffle/nodes/cast/LambdaNode.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -12,8 +12,10 @@
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ProcNodes;
import org.jruby.truffle.nodes.core.ProcNodes.Type;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
@@ -26,6 +28,7 @@
*/
public class BlockDefinitionNode extends RubyNode {

private final Type type;
private final SharedMethodInfo sharedMethodInfo;

// TODO(CS, 10-Jan-15) having three call targets isn't ideal, but they all have different semantics, and we don't
@@ -37,10 +40,11 @@ public class BlockDefinitionNode extends RubyNode {

private final BreakID breakID;

public BlockDefinitionNode(RubyContext context, SourceSection sourceSection, SharedMethodInfo sharedMethodInfo,
CallTarget callTargetForBlocks,
CallTarget callTargetForProcs, CallTarget callTargetForLambdas, BreakID breakID) {
public BlockDefinitionNode(RubyContext context, SourceSection sourceSection, Type type, SharedMethodInfo sharedMethodInfo,
CallTarget callTargetForBlocks, CallTarget callTargetForProcs, CallTarget callTargetForLambdas,
BreakID breakID) {
super(context, sourceSection);
this.type = type;
this.sharedMethodInfo = sharedMethodInfo;

this.callTargetForBlocks = callTargetForBlocks;
@@ -55,7 +59,7 @@ public BreakID getBreakID() {

@Override
public Object execute(VirtualFrame frame) {
return ProcNodes.createRubyProc(getContext().getCoreLibrary().getProcClass(), ProcNodes.Type.PROC, sharedMethodInfo,
return ProcNodes.createRubyProc(getContext().getCoreLibrary().getProcClass(), type, sharedMethodInfo,
callTargetForBlocks, callTargetForProcs, callTargetForLambdas,
frame.materialize(),
RubyArguments.getMethod(frame.getArguments()),
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

/**
* Define a method. That is, store the definition of a method and when executed
* Define a method from a method literal (def mymethod ... end).
* That is, store the definition of a method and when executed
* produce the executable object that results.
*/
public class MethodDefinitionNode extends RubyNode {
@@ -37,7 +38,8 @@ public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, St
}

public InternalMethod executeMethod(VirtualFrame frame) {
return new InternalMethod(sharedMethodInfo, name, null, null, false, callTarget, frame.materialize());
return new InternalMethod(sharedMethodInfo, name, null, null, false, callTarget,
frame.materialize() /* Currently used for visibility, will be fixed when we keep visibility in some better place */);
}

@Override
Original file line number Diff line number Diff line change
@@ -40,6 +40,10 @@ public Arity(int preRequired, int optional, boolean hasRest, int postRequired, S
assert keywordArguments != null && preRequired >= 0 && optional >= 0 && postRequired >= 0 : toString();
}

public Arity withRest(boolean hasRest) {
return new Arity(preRequired, optional, hasRest, postRequired, keywordArguments, hasKeywordsRest);
}

public int getPreRequired() {
return preRequired;
}
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.nodes.ThreadLocalObjectNode;
import org.jruby.truffle.nodes.arguments.IsRubiniusUndefinedNode;
import org.jruby.truffle.nodes.cast.*;
import org.jruby.truffle.nodes.cast.LambdaNode;
import org.jruby.truffle.nodes.constants.ReadConstantNode;
import org.jruby.truffle.nodes.constants.ReadConstantWithLexicalScopeNode;
import org.jruby.truffle.nodes.constants.ReadLiteralConstantNode;
@@ -41,6 +40,7 @@
import org.jruby.truffle.nodes.control.ReturnNode;
import org.jruby.truffle.nodes.control.WhileNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.core.ProcNodes.Type;
import org.jruby.truffle.nodes.core.array.*;
import org.jruby.truffle.nodes.core.fixnum.FixnumLiteralNode;
import org.jruby.truffle.nodes.core.hash.ConcatHashLiteralNode;
@@ -139,21 +139,8 @@ public RubyNode visitAliasNode(org.jruby.ast.AliasNode node) {
public RubyNode visitAndNode(org.jruby.ast.AndNode node) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode x;

if (node.getFirstNode() == null) {
x = nilNode(sourceSection);
} else {
x = node.getFirstNode().accept(this);
}

RubyNode y;

if (node.getSecondNode() == null) {
y = nilNode(sourceSection);
} else {
y = node.getSecondNode().accept(this);
}
final RubyNode x = translateNodeOrNil(sourceSection, node.getFirstNode());
final RubyNode y = translateNodeOrNil(sourceSection, node.getSecondNode());

final RubyNode ret = new AndNode(context, sourceSection, x, y);
return addNewlineIfNeeded(node, ret);
@@ -732,13 +719,7 @@ protected ArgumentsAndBlockTranslation translateArgumentsAndBlock(SourceSection
public RubyNode visitCaseNode(org.jruby.ast.CaseNode node) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode elseNode;

if (node.getElseNode() != null) {
elseNode = node.getElseNode().accept(this);
} else {
elseNode = nilNode(sourceSection);
}
RubyNode elseNode = translateNodeOrNil(sourceSection, node.getElseNode());

/*
* There are two sorts of case - one compares a list of expressions against a value, the
@@ -800,13 +781,7 @@ public RubyNode visitCaseNode(org.jruby.ast.CaseNode node) {

// Create the if node

RubyNode thenNode;

if (when.getBodyNode() == null || when.getBodyNode().isNil()) {
thenNode = nilNode(sourceSection);
} else {
thenNode = when.getBodyNode().accept(this);
}
final RubyNode thenNode = translateNodeOrNil(sourceSection, when.getBodyNode());

final IfNode ifNode = new IfNode(context, sourceSection, conditionNode, thenNode, elseNode);

@@ -1169,7 +1144,7 @@ protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNo

final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, false, source, argsNode);

final MethodDefinitionNode functionExprNode = (MethodDefinitionNode) methodCompiler.compileFunctionNode(sourceSection, methodName, bodyNode, sharedMethodInfo);
final MethodDefinitionNode functionExprNode = methodCompiler.compileMethodNode(sourceSection, methodName, bodyNode, sharedMethodInfo);

return new AddMethodNode(context, sourceSection, classNode, functionExprNode);
}
@@ -1606,13 +1581,7 @@ public RubyNode visitIfNode(org.jruby.ast.IfNode node) {
elseBody = new org.jruby.ast.NilNode(node.getPosition());
}

RubyNode condition;

if (node.getCondition() == null) {
condition = nilNode(sourceSection);
} else {
condition = node.getCondition().accept(this);
}
final RubyNode condition = translateNodeOrNil(sourceSection, node.getCondition());

final RubyNode thenBodyTranslated = thenBody.accept(this);
final RubyNode elseBodyTranslated = elseBody.accept(this);
@@ -1626,8 +1595,7 @@ public RubyNode visitInstAsgnNode(org.jruby.ast.InstAsgnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
final String name = node.getName();

RubyNode rhs;

final RubyNode rhs;
if (node.getValueNode() == null) {
rhs = new DeadNode(context, sourceSection, new Exception("null RHS of instance variable assignment"));
} else {
@@ -1826,7 +1794,7 @@ public RubyNode visitIterNode(org.jruby.ast.IterNode node) {
methodCompiler.useClassVariablesAsIfInClass = true;
}

final RubyNode ret = methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), node.getBodyNode(), sharedMethodInfo);
final RubyNode ret = methodCompiler.compileBlockNode(translate(node.getPosition()), sharedMethodInfo.getName(), node.getBodyNode(), sharedMethodInfo, Type.PROC);
return addNewlineIfNeeded(node, ret);
}

@@ -2495,21 +2463,8 @@ private static org.jruby.ast.ArrayNode buildArrayNode(org.jruby.lexer.yacc.ISour
public RubyNode visitOrNode(org.jruby.ast.OrNode node) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode x;

if (node.getFirstNode() == null) {
x = nilNode(sourceSection);
} else {
x = node.getFirstNode().accept(this);
}

RubyNode y;

if (node.getSecondNode() == null) {
y = nilNode(sourceSection);
} else {
y = node.getSecondNode().accept(this);
}
final RubyNode x = translateNodeOrNil(sourceSection, node.getFirstNode());
final RubyNode y = translateNodeOrNil(sourceSection, node.getSecondNode());

final RubyNode ret = new OrNode(context, sourceSection, x, y);
return addNewlineIfNeeded(node, ret);
@@ -2650,13 +2605,7 @@ public RubyNode visitRescueNode(org.jruby.ast.RescueNode node) {
} else if (rescueBody.getExceptionNodes() instanceof org.jruby.ast.SplatNode) {
final org.jruby.ast.SplatNode splat = (org.jruby.ast.SplatNode) rescueBody.getExceptionNodes();

RubyNode splatTranslated;

if (splat.getValue() == null) {
splatTranslated = nilNode(sourceSection);
} else {
splatTranslated = splat.getValue().accept(this);
}
final RubyNode splatTranslated = translateNodeOrNil(sourceSection, splat.getValue());

RubyNode bodyTranslated;

@@ -2746,14 +2695,7 @@ public RubyNode visitSelfNode(org.jruby.ast.SelfNode node) {
public RubyNode visitSplatNode(org.jruby.ast.SplatNode node) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode value;

if (node.getValue() == null) {
value = nilNode(sourceSection);
} else {
value = node.getValue().accept(this);
}

final RubyNode value = translateNodeOrNil(sourceSection, node.getValue());
final RubyNode ret = SplatCastNodeGen.create(context, sourceSection, SplatCastNode.NilBehavior.EMPTY_ARRAY, false, value);
return addNewlineIfNeeded(node, ret);
}
@@ -2831,11 +2773,7 @@ private RubyNode visitWhileNode(org.jruby.ast.WhileNode node, boolean conditionI
BreakID oldBreakID = environment.getBreakID();
environment.setBreakIDForWhile(whileBreakID);
try {
if (node.getBodyNode().isNil()) {
body = nilNode(sourceSection);
} else {
body = node.getBodyNode().accept(this);
}
body = translateNodeOrNil(sourceSection, node.getBodyNode());
} finally {
environment.setBreakIDForWhile(oldBreakID);
translatingWhile = oldTranslatingWhile;
@@ -2951,10 +2889,9 @@ public RubyNode visitLambdaNode(org.jruby.ast.LambdaNode node) {
sharedMethodInfo, sharedMethodInfo.getName(), true, environment.getParseEnvironment().allocateBreakID());
final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, false, source, argsNode);

final RubyNode definitionNode = methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), node.getBodyNode(), sharedMethodInfo);
final RubyNode definitionNode = methodCompiler.compileBlockNode(translate(node.getPosition()), sharedMethodInfo.getName(), node.getBodyNode(), sharedMethodInfo, Type.LAMBDA);

final RubyNode ret = new LambdaNode(context, translate(node.getPosition()), definitionNode);
return addNewlineIfNeeded(node, ret);
return addNewlineIfNeeded(node, definitionNode);
}

protected RubyNode initFlipFlopStates(SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -171,45 +171,29 @@ public RubyNode visitKeywordRestArgNode(org.jruby.ast.KeywordRestArgNode node) {
public RubyNode visitKeywordArgNode(org.jruby.ast.KeywordArgNode node) {
final SourceSection sourceSection = translate(node.getPosition());

final String name;
final RubyNode defaultValue;

final org.jruby.ast.Node firstChild = node.childNodes().get(0);
final org.jruby.ast.AssignableNode asgnNode;
final String name;

if (firstChild instanceof org.jruby.ast.LocalAsgnNode) {
final org.jruby.ast.LocalAsgnNode localAsgnNode = (org.jruby.ast.LocalAsgnNode) firstChild;
name = localAsgnNode.getName();

if (localAsgnNode.getValueNode() == null) {
defaultValue = nilNode(sourceSection);
} else if (localAsgnNode.getValueNode() instanceof RequiredKeywordArgumentValueNode) {
/*
* This isn't a true default value - it's a marker to say there isn't one. This actually makes sense;
* the semantic action of executing this node is to report an error, and we do the same thing.
*/
defaultValue = new MissingKeywordArgumentNode(context, sourceSection, name);
} else {
defaultValue = localAsgnNode.getValueNode().accept(this);
}
asgnNode = (org.jruby.ast.LocalAsgnNode) firstChild;
name = ((org.jruby.ast.LocalAsgnNode) firstChild).getName();
} else if (firstChild instanceof org.jruby.ast.DAsgnNode) {
final org.jruby.ast.DAsgnNode dAsgnNode = (org.jruby.ast.DAsgnNode) firstChild;
name = dAsgnNode.getName();

if (dAsgnNode.getValueNode() == null) {
defaultValue = nilNode(sourceSection);
} else if (dAsgnNode.getValueNode() instanceof RequiredKeywordArgumentValueNode) {
/*
* This isn't a true default value - it's a marker to say there isn't one. This actually makes sense;
* the semantic action of executing this node is to report an error, and we do the same thing.
*/
defaultValue = new MissingKeywordArgumentNode(context, sourceSection, name);
}else {
defaultValue = dAsgnNode.getValueNode().accept(this);
}
asgnNode = (org.jruby.ast.DAsgnNode) firstChild;
name = ((org.jruby.ast.DAsgnNode) firstChild).getName();
} else {
throw new UnsupportedOperationException("unsupported keyword arg " + node);
}

final RubyNode defaultValue;
if (asgnNode.getValueNode() instanceof RequiredKeywordArgumentValueNode) {
/* This isn't a true default value - it's a marker to say there isn't one. This actually makes sense;
* the semantic action of executing this node is to report an error, and we do the same thing. */
defaultValue = new MissingKeywordArgumentNode(context, sourceSection, name);
} else {
defaultValue = translateNodeOrNil(sourceSection, asgnNode.getValueNode());
}

excludedKeywords.add(name);

final RubyNode readNode = new ReadKeywordArgumentNode(context, sourceSection, required, name, defaultValue, kwIndex - countKwArgs);
Loading