Skip to content

Commit

Permalink
[PRISM] Implement PM_SOURCE_FILE_NODE for defined?
Browse files Browse the repository at this point in the history
Ruby code:

```ruby
defined?(__FILE__)
```

Instructions:

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

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,18)>
0000 putobject                              "expression"
0002 leave
```
  • Loading branch information
eileencodes authored and jemmaissroff committed Dec 6, 2023
1 parent 41b117e commit d474239
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions prism_compile.c
Expand Up @@ -1492,6 +1492,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co
case PM_RANGE_NODE:
case PM_REGULAR_EXPRESSION_NODE:
case PM_SOURCE_ENCODING_NODE:
case PM_SOURCE_FILE_NODE:
case PM_STRING_NODE:
case PM_SYMBOL_NODE:
case PM_X_STRING_NODE:
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -111,6 +111,7 @@ def test_DefinedNode
assert_prism_eval("defined? a && b")
assert_prism_eval("defined? a || b")
assert_prism_eval("defined? __ENCODING__")
assert_prism_eval("defined? __FILE__")

assert_prism_eval("defined? %[1,2,3]")
assert_prism_eval("defined? %q[1,2,3]")
Expand Down

0 comments on commit d474239

Please sign in to comment.