Skip to content

Commit 1db38f5

Browse files
committed
Translate nodes
1 parent 26a17bb commit 1db38f5

File tree

7 files changed

+1041
-118
lines changed

7 files changed

+1041
-118
lines changed

spec/tags/truffle/parsing/parsing_tags.txt

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,17 @@ fails:Parsing a Block (Tail expression / with explicit return inside then branch
4747
fails:Parsing a Block (a block with empty body) case is parsed correctly
4848
fails:Parsing a Block (a block with not empty body) case is parsed correctly
4949
fails:Parsing a Block (a block without parameters) case is parsed correctly
50-
fails:Parsing a Break (break operator with argument) case is parsed correctly
51-
fails:Parsing a Break (break operator with splat operator (break *a)) case is parsed correctly
5250
fails:Parsing a Break (break operator within a block) case is parsed correctly
53-
fails:Parsing a Break (break operator without argument) case is parsed correctly
5451
fails:Parsing a case expression (case expression with expression/value to match (case a when ... end)) case is parsed correctly
5552
fails:Parsing a case expression (case expression with expression to match and `else` branch (case a when ... else ... end)) case is parsed correctly
5653
fails:Parsing a case expression (case expression with expression to match and multiple values in a `when` branch (case a when a, b ... end)) case is parsed correctly
5754
fails:Parsing a case expression (case expression without expression to match (case when expr ... end)) case is parsed correctly
5855
fails:Parsing a case expression (case expression without expression to match and with `else` branch (case when expr ... else ... end)) case is parsed correctly
5956
fails:Parsing a case expression (case expression without expression to match and with multiple conditions in a `when` branch (case when a, b ... end)) case is parsed correctly
6057
fails:Parsing a class << (reopen an object singleton class) case is parsed correctly
61-
fails:Parsing a class (class definition) case is parsed correctly
62-
fails:Parsing a class (class definition with explicit lexical parent module (class Foo::Bar)) case is parsed correctly
63-
fails:Parsing a class (class definition when there are some expressions inside a body) case is parsed correctly
64-
fails:Parsing a class (class definition with inheriting a parent class) case is parsed correctly
6558
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Float is represented as `Complext.convert(0, Rational.convert(b*100, 100))` where 100 is some power of 10 to convert b to Integer) case is parsed correctly
6659
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Integer is represented as `Complext.convert(0, Rational.convert(b, 1))`) case is parsed correctly
6760
fails:Parsing a Complex number (Complex literal in format of a + bi is represented as `a + Complex.convert(0, b)`) case is parsed correctly
68-
fails:Parsing a Constant (reading / a constant) case is parsed correctly
69-
fails:Parsing a Constant (reading / a fully qualified constant (::A)) case is parsed correctly
70-
fails:Parsing a Constant (reading / a fully qualified constant with lexical parent (::A::B)) case is parsed correctly
71-
fails:Parsing a Constant (reading / a constant with lexical grandparent (A::B::C)) case is parsed correctly
72-
fails:Parsing a Constant (reading / a constant with lexical parent (A::B)) case is parsed correctly
73-
fails:Parsing a Constant (assigning / a constant) case is parsed correctly
74-
fails:Parsing a Constant (assigning / a fully qualified constant (::A)) case is parsed correctly
75-
fails:Parsing a Constant (assigning / a fully qualified constant with lexical parent (::A::B)) case is parsed correctly
76-
fails:Parsing a Constant (assigning / a constant with lexical grandparent (A::B::C)) case is parsed correctly
77-
fails:Parsing a Constant (assigning / a constant with lexical parent (A::B)) case is parsed correctly
7861
fails:Parsing a Def (Argument descriptors / with block (def a(&b))) case is parsed correctly
7962
fails:Parsing a Def (Argument descriptors / with double splat operator (**kw)) case is parsed correctly
8063
fails:Parsing a Def (Argument descriptors / with double splat operator without variable name (**)) case is parsed correctly
@@ -118,40 +101,15 @@ fails:Parsing a Def (Method definition with empty body) case is parsed correctly
118101
fails:Parsing a Def (Method definition with not empty body) case is parsed correctly
119102
fails:Parsing a Def (Method definition without parameters) case is parsed correctly
120103
fails:Parsing a defined? (with yield in a method body (defined? yield)) case is parsed correctly
121-
fails:Parsing a defined? (with yield in a module/class body (defined? yield)) case is parsed correctly
122-
fails:Parsing a Ensure keyword (ensure in a begin/end block) case is parsed correctly
123104
fails:Parsing a Ensure keyword (ensure in a do/end block) case is parsed correctly
124105
fails:Parsing a Ensure keyword (ensure in a method) case is parsed correctly
125-
fails:Parsing a Ensure keyword (ensure in a module) case is parsed correctly
126-
fails:Parsing a Ensure keyword (with empty body) case is parsed correctly
127-
fails:Parsing a Float (Float literal fixed-point format with underscores) case is parsed correctly
128106
fails:Parsing a For operator (for ... in ... operator) case is parsed correctly
129-
fails:Parsing a Hash (Hash literal with key-value pairs) case is parsed correctly
130-
fails:Parsing a Hash (when empty) case is parsed correctly
131-
fails:Parsing a Hash (with '=>' syntax (key => value)) case is parsed correctly
132-
fails:Parsing a Hash (Double Splat operator/there is only double splat operator (`{**{}}`)) case is parsed correctly
133-
fails:Parsing a Hash (Double Splat operator/double splat operator + key-value pairs (`{**{}, a: 1}`)) case is parsed correctly
134-
fails:Parsing a Hash (Double Splat operator/key-value pairs + double splat operator (`{a: 1, **{}}`)) case is parsed correctly
135-
fails:Parsing a Hash (Double Splat operator/key-value pairs + double splat operator + key-value pairs (`{a: 1, **{}, b: 2}`)) case is parsed correctly
136-
fails:Parsing a Hash (with String literal key) case is parsed correctly
137-
fails:Parsing a Hash (with symbol keys syntax (key: value)) case is parsed correctly
138-
fails:Parsing a Hash (with symbol keys syntax and dynamic symbol ('key': value)) case is parsed correctly
139-
fails:Parsing a Hash (with symbol keys syntax and dynamic symbol with interpolation) case is parsed correctly
140-
fails:Parsing a Instance variable (reading an instance variable) case is parsed correctly
141-
fails:Parsing a Instance variable (assigning an instance variable new value) case is parsed correctly
142-
fails:Parsing a Integer (Big Integer literal (that takes >= 64 bits)) case is parsed correctly
143-
fails:Parsing a Integer (Integer literal with binary prefix) case is parsed correctly
144-
fails:Parsing a Integer (Integer literal with explicit decimal prefix) case is parsed correctly
145-
fails:Parsing a Integer (Integer literal with hexadecimal prefix) case is parsed correctly
146-
fails:Parsing a Integer (Integer literal with octal prefix) case is parsed correctly
147-
fails:Parsing a Integer (Integer literal with underscore) case is parsed correctly
107+
fails:Parsing a Integer (when doesn't fit into Java Long (>= 64 bits)) case is parsed correctly
148108
fails:Parsing a Lambda (literal `-> () { ... }`) case is parsed correctly
149109
fails:Parsing a Local variable (in a block / reading a local variable) case is parsed correctly
150110
fails:Parsing a Local variable (in a block / assigning a local variable new value) case is parsed correctly
151111
fails:Parsing a Local variable (in a block but defined in an outer scope / reading a local variable) case is parsed correctly
152112
fails:Parsing a Local variable (in a block but defined in an outer scope / assigning a local variable new value) case is parsed correctly
153-
fails:Parsing a Local variable (reading a local variable) case is parsed correctly
154-
fails:Parsing a Local variable (assigning a local variable new value) case is parsed correctly
155113
fails:Parsing a Method call (Arguments/with a &-deconstruction to a block argument (&bar)) case is parsed correctly
156114
fails:Parsing a Method call (Arguments/with block literal argument) case is parsed correctly
157115
fails:Parsing a Method call (Arguments/with double splat operator (**kw)) case is parsed correctly
@@ -192,12 +150,6 @@ fails:Parsing a Method call (Special cases/method #attr= (property assignment))
192150
fails:Parsing a Method call (Method call with implicit receiver (`foo`)) case is parsed correctly
193151
fails:Parsing a Method call (With safe navigation operator (&.)) case is parsed correctly
194152
fails:Parsing a Method call (Without arguments and parentheses) case is parsed correctly
195-
fails:Parsing a module (module definition) case is parsed correctly
196-
fails:Parsing a module (module definition with explicit lexical parent module (module Foo::Bar)) case is parsed correctly
197-
fails:Parsing a module (module definition when there are some expressions inside a body) case is parsed correctly
198-
fails:Parsing a Next (next operator with returning value) case is parsed correctly
199-
fails:Parsing a Next (next operator with splat operator (next *a)) case is parsed correctly
200-
fails:Parsing a Next (next operator without returning value) case is parsed correctly
201153
fails:Parsing a &&= (Assign an attribute local variable (a.b &&= c)) case is parsed correctly
202154
fails:Parsing a &&= (Assign an referenced element (a[b] &&= c)) case is parsed correctly
203155
fails:Parsing a &&= (Assign an element referenced with multiple indexes (a[b, c, d] &&= e)) case is parsed correctly
@@ -253,30 +205,31 @@ fails:Parsing a Rational number (with big Integer value (>= 2^64).) case is pars
253205
fails:Parsing a Rational number (with Float value) case is parsed correctly
254206
fails:Parsing a Rational number (with Integer value) case is parsed correctly
255207
fails:Parsing a Rational number (with negative value) case is parsed correctly
256-
fails:Parsing a Redo (redo operator) case is parsed correctly
257208
fails:Parsing a Regexp (Regexp literal in boolean context (e.g. condition in if, while, etc)) case is parsed correctly
258209
fails:Parsing a Regexp (a literal) case is parsed correctly
259210
fails:Parsing a Regexp (a literal with interpolation (with #{...})) case is parsed correctly
260211
fails:Parsing a Regexp (a literal with interpolation but without expression (#{})) case is parsed correctly
261212
fails:Parsing a Regexp (a literal with options (e.g. i, x, m, o)) case is parsed correctly
213+
fails:Parsing a Rescue keyword (backtrace optimization / disabled / when rescue section is Range (... rescue 1..3)) case is parsed correctly
214+
fails:Parsing a Rescue keyword (backtrace optimization / disabled / when rescue section is Regexp (... rescue /a/)) case is parsed correctly
215+
fails:Parsing a Rescue keyword (backtrace optimization / enabled / when rescue section is __FILE__ constant (... rescue __FILE__)) case is parsed correctly
216+
fails:Parsing a Rescue keyword (backtrace optimization / enabled / when rescue section is local variable defined in outer scope (... rescue a)) case is parsed correctly
262217
fails:Parsing a Rescue keyword (capturing / with an attribute) case is parsed correctly
263218
fails:Parsing a Rescue keyword (capturing / with a class variable) case is parsed correctly
264219
fails:Parsing a Rescue keyword (capturing / with a constant) case is parsed correctly
220+
fails:Parsing a Rescue keyword (capturing / with a constant with lexical parent (A::B)) case is parsed correctly
221+
fails:Parsing a Rescue keyword (capturing / with a fully qualified constant (::A)) case is parsed correctly
222+
fails:Parsing a Rescue keyword (capturing / with a constant with fully qualified lexical parent (::A::B)) case is parsed correctly
223+
fails:Parsing a Rescue keyword (capturing / with element reference) case is parsed correctly
265224
fails:Parsing a Rescue keyword (capturing / with a global variable) case is parsed correctly
266225
fails:Parsing a Rescue keyword (capturing / with an instance variable) case is parsed correctly
267226
fails:Parsing a Rescue keyword (capturing / with a local variable) case is parsed correctly
268-
fails:Parsing a Rescue keyword (exceptions list / with single explicit exception class) case is parsed correctly
269-
fails:Parsing a Rescue keyword (exceptions list / with explicit multiple exception classes) case is parsed correctly
270-
fails:Parsing a Rescue keyword (exceptions list / with a splat operator) case is parsed correctly
271-
fails:Parsing a Rescue keyword (exceptions list / with a splat operator, followed and preceded by list elements) case is parsed correctly
272-
fails:Parsing a Rescue keyword (exceptions list / without explicit exceptions list) case is parsed correctly
273-
fails:Parsing a Rescue keyword (rescue in a begin/end block) case is parsed correctly
274227
fails:Parsing a Rescue keyword (rescue in a do/end block) case is parsed correctly
275228
fails:Parsing a Rescue keyword (rescue in a method) case is parsed correctly
276-
fails:Parsing a Rescue keyword (rescue in a module) case is parsed correctly
277-
fails:Parsing a Rescue keyword (rescue with else branch) case is parsed correctly
278-
fails:Parsing a Rescue keyword (rescue with empty else branch) case is parsed correctly
279-
fails:Parsing a Rescue keyword (with empty body) case is parsed correctly
229+
fails:Parsing a Rescue keyword (modifier / backtrace optimization / disabled / when rescue section is Range (... rescue 1..3)) case is parsed correctly
230+
fails:Parsing a Rescue keyword (modifier / backtrace optimization / disabled / when rescue section is Regexp (... rescue /a/)) case is parsed correctly
231+
fails:Parsing a Rescue keyword (modifier / backtrace optimization / enabled / when rescue section is __FILE__ constant (... rescue __FILE__)) case is parsed correctly
232+
fails:Parsing a Rescue keyword (modifier / backtrace optimization / enabled / when rescue section is local variable defined in outer scope (... rescue a)) case is parsed correctly
280233
fails:Parsing a Rescue keyword (with exception and variable) case is parsed correctly
281234
fails:Parsing a Rescue keyword (with multiple rescue branches) case is parsed correctly
282235
fails:Parsing a Rescue keyword (without exception but with a variable) case is parsed correctly
@@ -290,19 +243,12 @@ fails:Parsing a Return (return operator in a method (with a value)) case is pars
290243
fails:Parsing a Return (return operator in a method without value) case is parsed correctly
291244
fails:Parsing a Return (return operator with splat operator (return *a)) case is parsed correctly
292245
fails:Parsing a Sequence of expressions () case is parsed correctly
293-
fails:Parsing a String (Backtick literal (`echo 1`) to execute a shell command) case is parsed correctly
294-
fails:Parsing a String (Backtick literal (`echo 1`) with interpolation (#{...})) case is parsed correctly
295-
fails:Parsing a String (Backtick literal (`echo 1`) with interpolation without expression (#{})) case is parsed correctly
296246
fails:Parsing a String (Frozen literal) case is parsed correctly
297247
fails:Parsing a String (Literal with interpolation when when expressions are % String literals) case is parsed correctly
298248
fails:Parsing a String (Literal with interpolation when expressions are Strings) case is parsed correctly
299249
fails:Parsing a Symbol (Literal with interpolation when expressions are % String literals) case is parsed correctly
300250
fails:Parsing a Symbol (Literal with interpolation when expressions are Strings) case is parsed correctly
301251
fails:Parsing a Undef (with multiple Symbols) case is parsed correctly
302-
fails:Parsing a Until (until loop operator) case is parsed correctly
303-
fails:Parsing a Until (until modifier (... until())) case is parsed correctly
304-
fails:Parsing a While (while loop operator) case is parsed correctly
305-
fails:Parsing a While (while modifier (... while())) case is parsed correctly
306252
fails:Parsing a Yield (yield operator with arguments) case is parsed correctly
307253
fails:Parsing a Yield (yield operator with keyword arguments) case is parsed correctly
308254
fails:Parsing a Yield (yield operator with double splat operator (yield **a)) case is parsed correctly
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 2.0, or
7+
* GNU General Public License version 2, or
8+
* GNU Lesser General Public License version 2.1.
9+
*/
10+
package org.truffleruby.core.rescue;
11+
12+
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.frame.VirtualFrame;
14+
import org.truffleruby.core.array.AssignableNode;
15+
import org.truffleruby.language.RubyContextSourceNode;
16+
import org.truffleruby.language.RubyNode;
17+
import org.truffleruby.language.globals.ReadGlobalVariableNode;
18+
import org.truffleruby.language.globals.ReadGlobalVariableNodeGen;
19+
20+
public final class AssignRescueVariableNode extends RubyContextSourceNode {
21+
22+
@Child private AssignableNode rescueVariableNode;
23+
@Child private ReadGlobalVariableNode readCurrentExceptionNode;
24+
25+
public AssignRescueVariableNode(AssignableNode node) {
26+
this.rescueVariableNode = node;
27+
}
28+
29+
@Override
30+
public Object execute(VirtualFrame frame) {
31+
if (readCurrentExceptionNode == null) {
32+
CompilerDirectives.transferToInterpreterAndInvalidate();
33+
readCurrentExceptionNode = insert(ReadGlobalVariableNodeGen.create("$!"));
34+
}
35+
36+
Object value = readCurrentExceptionNode.execute(frame);
37+
rescueVariableNode.assign(frame, value);
38+
return nil;
39+
}
40+
41+
public RubyNode cloneUninitialized() {
42+
var copy = new AssignRescueVariableNode(rescueVariableNode.cloneUninitializedAssignable());
43+
return copy.copyFlags(this);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)