Skip to content

Commit f491b95

Browse files
committed
Translate nodes - LambdaNode
1 parent 0a33a82 commit f491b95

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

spec/tags/truffle/parsing/parsing_tags.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ fails:Parsing a defined? (with yield in a method body (defined? yield)) case is
1919
fails:Parsing a Ensure keyword (ensure in a method) case is parsed correctly
2020
fails:Parsing a For operator (for ... in ... operator) case is parsed correctly
2121
fails:Parsing a Integer (when doesn't fit into Java Long (>= 64 bits)) case is parsed correctly
22-
fails:Parsing a Lambda (literal `-> () { ... }`) case is parsed correctly
2322
fails:Parsing a Method call (super / in a method body with explicit arguments) case is parsed correctly
2423
fails:Parsing a Method call (super / in a method body without explicit arguments) case is parsed correctly
2524
fails:Parsing a Method call (super / outside a method body with explicit arguments) case is parsed correctly
2625
fails:Parsing a Method call (super / outside a method body without explicit arguments) case is parsed correctly
27-
fails:Parsing a Method call (Special cases/method #lambda (Kernel#lambda)) case is parsed correctly
28-
fails:Parsing a Method call (Special cases/method #lambda (not Kernel#lambda)) case is parsed correctly
2926
fails:Parsing a Method call (super / in a method body with explicit arguments) case is parsed correctly
3027
fails:Parsing a Method call (super / in a method body without explicit arguments) case is parsed correctly
3128
fails:Parsing a Method call (super / outside a method body with explicit arguments) case is parsed correctly
@@ -39,7 +36,6 @@ fails:Parsing a &&= (Variable assignment/fully qualified constant (::A &&= b)) c
3936
fails:Parsing a &&= (Variable assignment/global variable ($a &&= b)) case is parsed correctly
4037
fails:Parsing a &&= (Variable assignment/instance variable (@a &&= b)) case is parsed correctly
4138
fails:Parsing a &&= (Variable assignment/local variable (a &&= b)) case is parsed correctly
42-
fails:Parsing a Flip-flop operator (in a lambda) case is parsed correctly
4339
fails:Parsing a Match (=~ operator) case is parsed correctly
4440
fails:Parsing a Match (=~ operator/with Regexp literal as a RHS) case is parsed correctly
4541
fails:Parsing a Match (=~ operator/with Regexp literal as a LHS (without named capture groups)) case is parsed correctly
@@ -85,12 +81,6 @@ fails:Parsing a Rescue keyword (modifier / backtrace optimization / enabled / wh
8581
fails:Parsing a Rescue keyword (with exception and variable) case is parsed correctly
8682
fails:Parsing a Rescue keyword (with multiple rescue branches) case is parsed correctly
8783
fails:Parsing a Rescue keyword (without exception but with a variable) case is parsed correctly
88-
fails:Parsing a Return (return operator in a lambda) case is parsed correctly
89-
fails:Parsing a Return (return operator in a lambda in a class definition body) case is parsed correctly
90-
fails:Parsing a Return (return operator in a lambda in a module definition body) case is parsed correctly
91-
fails:Parsing a Return (return operator in a lambda method call) case is parsed correctly
92-
fails:Parsing a Return (return operator in a lambda method call in a class definition body) case is parsed correctly
93-
fails:Parsing a Return (return operator in a lambda method call in a module definition body) case is parsed correctly
9484
fails:Parsing a Sequence of expressions () case is parsed correctly
9585
fails:Parsing a String (Literal with interpolation when when expressions are % String literals) case is parsed correctly
9686
fails:Parsing a String (Literal with interpolation when expressions are Strings) case is parsed correctly

spec/truffle/parsing/fixtures/operators/flip_flop_operator/in_lambda.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ ast: |
143143
begin =
144144
ReadLocalVariableNode
145145
attributes:
146-
flags = 1
146+
flags = 0
147147
frameSlot = 1
148148
type = FRAME_LOCAL
149149
end =
150150
ReadLocalVariableNode
151151
attributes:
152-
flags = 1
152+
flags = 0
153153
frameSlot = 1
154154
type = FRAME_LOCAL
155155
thenBody =

spec/truffle/parsing/fixtures/return/in_lambda_method_call_in_class_body.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ast: |
6868
CatchBreakNode
6969
attributes:
7070
breakID = org.truffleruby.language.control.BreakID@...
71-
flags = 0
71+
flags = 1
7272
isWhile = false
7373
children:
7474
body =

spec/truffle/parsing/fixtures/return/in_lambda_method_call_in_module_body.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ast: |
6868
CatchBreakNode
6969
attributes:
7070
breakID = org.truffleruby.language.control.BreakID@...
71-
flags = 0
71+
flags = 1
7272
isWhile = false
7373
children:
7474
body =

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ public RubyNode visitBlockArgumentNode(Nodes.BlockArgumentNode node) {
423423

424424
@Override
425425
public RubyNode visitBlockNode(Nodes.BlockNode node) {
426-
final boolean isStabbyLambda = false; // TODO: handle lambda literal as well in visitLambdaNode
426+
return translateBlockAndLambda(node, node.parameters, node.body, node.locals);
427+
}
428+
429+
private RubyNode translateBlockAndLambda(Nodes.Node node, Nodes.BlockParametersNode blockParameters,
430+
Nodes.Node body, String[] locals) {
431+
final boolean isStabbyLambda = node instanceof Nodes.LambdaNode;
427432
final boolean hasOwnScope = true;
428433
final boolean isProc = !isStabbyLambda;
429434

@@ -433,14 +438,14 @@ public RubyNode visitBlockNode(Nodes.BlockNode node) {
433438
final int blockDepth = environment.getBlockDepth() + 1;
434439

435440
final Nodes.ParametersNode parameters;
436-
if (node.parameters != null) {
437-
parameters = node.parameters.parameters;
441+
if (blockParameters != null) {
442+
parameters = blockParameters.parameters;
438443
} else {
439444
// handle numbered parameters
440445
int max = 0;
441446

442447
// don't rely on locals order and find the largest index
443-
for (var name : node.locals) {
448+
for (var name : locals) {
444449
if (ParserSupport.isNumberedParameter(name)) {
445450
int n = name.charAt(1) - '0';
446451
if (n > max) {
@@ -508,8 +513,8 @@ public RubyNode visitBlockNode(Nodes.BlockNode node) {
508513
methodCompiler.frameOnStackMarkerSlotStack = frameOnStackMarkerSlotStack;
509514

510515
final RubyNode rubyNode = methodCompiler.compileBlockNode(
511-
node.body,
512-
node.locals,
516+
body,
517+
locals,
513518
isStabbyLambda,
514519
getSourceSection(node));
515520

@@ -1538,7 +1543,7 @@ public RubyNode visitKeywordHashNode(Nodes.KeywordHashNode node) {
15381543

15391544
@Override
15401545
public RubyNode visitLambdaNode(Nodes.LambdaNode node) {
1541-
return defaultVisit(node);
1546+
return translateBlockAndLambda(node, node.parameters, node.body, node.locals);
15421547
}
15431548

15441549
@Override

0 commit comments

Comments
 (0)