Skip to content

[Prism] Add some more nodes to defined #9119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

eileencodes
Copy link
Member

@eileencodes eileencodes commented Dec 4, 2023

Adds the following missing nodes and tests for defined?:

  • Fixes PM_PARENTHESES_NODE - the prior PR only accounted for an empty set of parens
  • Adds PM_INTERPOLATED_REGULAR_EXPRESSION_NODE, PM_INTERPOLATED_STRING_NODE, and PM_X_STRING_NODE to pm_compile_defined_expr0.
  • Adds tests for all these nodes and examples found in CRuby defined? tests.

cc/ @tenderlove

In ruby#9101 I only accounted for an empty paren. This change implements the
`PM_PARENTHESES_NODE` for when it's `nil` and when it's an expression.

Code:

```ruby
defined?(("a"))
```

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,15)>
0000 putobject                              "expression"
0002 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,15)>
0000 putobject                              "expression"
0002 leave
```
Implements `PM_INTERPOLATED_STRING_NODE` for `defined?`

Code:

```ruby
defined?("#{expr}")
```

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,19)>
0000 putobject                              "expression"
0002 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,19)>
0000 putobject                              "expression"
0002 leave
```
Implements `PM_INTERPOLATED_REGULAR_EXPRESSION_NODE` for `defined?`

Code:

```ruby
defined?(/#{1}/)
```

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,16)>
0000 putobject                              "expression"
0002 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,16)>
0000 putobject                              "expression"
0002 leave
```
Tests all the possible percent literal with `defined?`. Implements the
missing `PM_X_STRING_NODE` for the `%x` literal.

Code:

```ruby
defined?(%x[1,2,3])
```

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,19)>
0000 putobject                              "expression"
0002 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,19)>
0000 putobject                              "expression"
0002 leave
```
@jemmaissroff jemmaissroff merged commit 7d371ca into ruby:master Dec 4, 2023
@eileencodes eileencodes deleted the add-some-more-nodes-to-defined branch December 4, 2023 22:04
@eileencodes eileencodes changed the title Add some more nodes to defined [Prism] Add some more nodes to defined Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants