eileencodes
d2000e0e6c
[Prism] Implement defined? for PM_RATIONAL_NODE
...
Ruby code:
```ruby
defined?(1.2r)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
913772a08a
[Prism] Implement defined? for PM_MODULE_NODE
...
Ruby code:
```ruby
defined?(module M; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
a9a22b9f2d
[Prism] Implement defined? for PM_MATCH_REQUIRED_NODE
...
Ruby code:
```ruby
defined?(1 => 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
b40fc4f0a7
[Prism] Implement defined? for PM_MATCH_WRITE_NODE
...
Ruby code:
```ruby
defined?(/(?<foo>bar)/ =~ 'barbar')
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,35)>
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] foo@0
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,35)>
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] foo@0
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
a2092ef207
[Prism] Implement defined? for PM_IF_NODE
...
Ruby code:
```ruby
defined?(if true; 1; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
fb1eed3f70
[Prism] Implement defined? for PM_FOR_NODE
...
Ruby code:
```ruby
defined?(for i in [1,2] do; i; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
7460820fec
[Prism] Implement defined? for PM_DEF_NODE
...
Ruby code:
```ruby
defined?(def prism_test_def_node; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
30e7dbb78d
[Prism] Implement defined? for PM_CLASS_NODE
...
Ruby code:
```ruby
defined?(class PrismClassA; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
9bcd42c378
[Prism] Implement defined? for PM_CASE_MATCH_NODE
...
Ruby code:
```ruby
defined?(case [1, 2, 3]; in [1, 2, 3]; 4; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
eileencodes
75bed8c61a
[Prism] Implement defined? for PM_CASE_NODE
...
Ruby code:
```ruby
defined?(case :a; when :a; 1; else; 2; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,43)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,43)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 17:21:29 -05:00
Peter Zhu
9f0d38960f
[PRISM] Refactor keyword hash nodes
...
Follow up to #9540 .
2024-01-17 17:07:51 -05:00
Peter Zhu
00f9456f16
[PRISM] Remove unnecessary flag setting
...
VM_CALL_KW_SPLAT and VM_CALL_KW_SPLAT_MUT are guaranteeed to be set in
this code path, so we don't need to set it again.
2024-01-17 17:07:51 -05:00
eileencodes
e1bae2c693
[Prism] Implement defined? for PM_INDEX_OR_WRITE_NODE
...
Ruby code:
```ruby
defined?([0][0] ||= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
ff54a8f4c7
[Prism] Implement defined? for PM_INDEX_OPERATOR_WRITE_NODE
...
Ruby code:
```ruby
defined?([0][0] += 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
f8ef77af3b
[Prism] Implement defined? for PM_INDEX_AND_WRITE_NODE
...
Ruby code:
```ruby
defined?([0][0] &&= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
e217c5772b
[Prism] Implement defined? for PM_CONSTANT_PATH_WRITE_NODE
...
Ruby code:
```ruby
defined?(Prism::CPWN = 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
54b8330e45
[Prism] Implement defined? for PM_CONSTANT_PATH_OR_WRITE_NODE
...
Ruby code:
```ruby
defined?(Prism::CPOrWN ||= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
3c9dc2f806
[Prism] Implement defined? for PM_CONSTANT_PATH_OPERATOR_WRITE_NODE
...
Ruby code:
```ruby
defined?(Prism::CPOWN += 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
98d6f50312
[Prism] Implement defined? for PM_CONSTANT_PATH_AND_WRITE_NODE
...
Ruby code:
```ruby
defined?(Prism::CPAWN &&= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
7522e867ee
[Prism] Implement defined? for PM_CALL_OR_WRITE_NODE
...
Ruby code:
```ruby
defined?(PrismTestSubclass.test_call_or_write_node ||= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
9c5391d7dc
[Prism] Implement defined? for PM_CALL_OPERATOR_WRITE_NODE
...
Ruby code:
```ruby
defined?(PrismTestSubclass.test_call_operator_write_node += 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
eileencodes
f657fd150f
[Prism] Implement defined? for PM_CALL_AND_WRITE_NODE
...
Ruby code:
```ruby
defined?(PrismTestSubclass.test_call_and_write_node &&= 1)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,58)>
0000 putobject "assignment" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,58)>
0000 putobject "assignment" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 13:08:49 -08:00
Peter Zhu
ebc4704696
[PRISM] Fix indentation in pm_setup_args [ci skip]
2024-01-17 14:45:05 -05:00
Peter Zhu
f43a919be4
[PRISM] Fix fallthrough for PM_ENSURE_NODE
...
This caused it to fall into PM_ELSE_NODE which caused ensure nodes to be
compiled twice.
Fixes ruby/prism#2176 .
2024-01-17 13:17:44 -05:00
Peter Zhu
947194aacb
[PRISM] Fix memory leak of ST table
...
This commit fixes a memory leak in rb_translate_prism because the ST
table is never freed. There are still more memory leaks which still need
to be fixed.
For example:
10.times do
100_000.times do
RubyVM::InstructionSequence.compile_prism("")
end
puts `ps -o rss= -p #{$$}`
end
Before:
34544
57120
79360
102176
123712
146320
168192
190592
212192
234896
After:
18336
24592
31488
37648
44592
50944
57280
63632
69904
76160
2024-01-17 11:35:30 -05:00
eileencodes
78ad91f83f
[Prism] Fix more method call argumnents
...
In #2087 it was noted that there was a bug in the number of arguments in
`SplatNode` and `KeywordHashNode`. I looked into this with Aaron before
the linked PR was merged and we found a bunch of cases that weren't
working quite right. This PR aims to fix some of those cases, but there
may be more.
A splat argument followed by a positional argument will concat the array
until the end or unless the argument is a kwarg or splat kwarg. For
example
```
foo(a, *b, c, *d, e)
```
Will have an `argc` of 2, because `b`, `c`, `d`, and `e` will be
concatenated together.
```
foo(a, *b, c, *d, **e)
```
Will have an `argc` of 3, because `b`, `c`, and `d` will be concatenated
together and `e` is a separate argument.
2024-01-17 10:57:19 -05:00
eileencodes
dcf9d77b45
[Prism] Implement defined? for PM_BEGIN_NODE
...
Ruby code:
```ruby
defined?(begin; 1; end)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,23)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,23)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
338aa465c0
[Prism] Implement defined? for PM_RETRY_NODE
...
Ruby code:
```ruby
defined?(retry)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,15)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,15)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
8774abad55
[Prism] Implement defined? for PM_RETURN_NODE
...
Ruby code:
```ruby
defined?(return)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
d0a7c33f05
[Prism] Implement defined? for PM_REDO_NODE
...
Ruby code:
```ruby
defined?(redo)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,14)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,14)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
2697acf7ff
[Prism] Implement defined? for PM_INTERPOLATED_X_STRING_NODE
...
Ruby code:
```ruby
defined?(`echo #{1}`)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,21)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,21)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
e0c90199c9
[Prism] Implement defined? for PM_INTERPOLATED_SYMBOL_NODE
...
Ruby code:
```ruby
defined?(:"1 #{1 + 2} 1")
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,25)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,25)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
25f1a8e447
[Prism] Implement defined? for PM_DEFINED_NODE
...
Ruby code:
```ruby
defined?(defined?(a))
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,21)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,21)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
82ed90950e
[Prism] Implement defined? for PM_BREAK_NODE
...
Ruby code:
```ruby
defined?(break)
```
Instructions:
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,15)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,15)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
eileencodes
0c814092ee
[Prism] Implement defined for PM_NEXT_NODE
...
Ruby code:
```ruby
defined?(next)
```
Instructions
```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,15)>
0000 putobject "expression" ( 59)[Li]
0002 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,15)>
0000 putobject "expression" ( 58)[Li]
0002 leave
```
Related: ruby/prism#2188
2024-01-17 10:17:59 -05:00
Matt Valentine-House
ef4a08eb65
[PRISM] Fix stack inconsistency in MultiWriteNode
2024-01-17 14:48:46 +00:00
Peter Zhu
07b9b53459
[PRISM] Fix crash with empty ensure blocks
...
Fixes ruby/prism#2179 .
2024-01-16 12:55:57 -05:00
Matt Valentine-House
7bd7030a96
[PRISM] Replace local lookup recursion with loop
2024-01-16 12:43:53 -05:00
Peter Zhu
70a8ed0775
[PRISM] Don't allocate labels when not needed
...
The labels lstart, lend, lcont are only needed when there is a rescue
clause. They are not needed when there is only an ensure clause or
neither.
2024-01-16 12:43:14 -05:00
Peter Zhu
1caa881a56
[PRISM] Fix splat assignment
...
Fixes ruby/prism#2177
2024-01-16 11:12:06 -05:00
Matt Valentine-House
fef8ccff11
Rename pm_lookup_local_index_any_scope
...
Now it's the only local lookup function we can just call it
pm_lookup_local_index
2024-01-16 14:58:55 +00:00
Matt Valentine-House
543bd7f3db
Remove scope_node->local_depth_offset
2024-01-16 14:58:55 +00:00
Matt Valentine-House
1b97f61168
Remove pm_lookup_local_index_with_depth
2024-01-16 14:58:55 +00:00
Matt Valentine-House
0d705b342f
Remove the found_depth pointer
...
Now that we're returning pm_local_index_t
2024-01-16 14:58:55 +00:00
Matt Valentine-House
da383c0d74
Return pm_local_index_t when looking up local indexes
...
instead of returning the index and updating found_depth in the parent
scope
2024-01-16 14:58:55 +00:00
Matt Valentine-House
f4b299a1ed
Bind index & depth together into pm_local_index_t
2024-01-16 14:58:55 +00:00
Matt Valentine-House
3d45b743e4
Replace pm_lookup_local_index with lookup_local_index_with_depth
2024-01-16 14:58:55 +00:00
Peter Zhu
0520e9675b
[PRISM] Fix defined? for chained calls
...
Fixes ruby/prism#2148 .
2024-01-16 08:32:21 -05:00
Peter Zhu
6a175902f4
[PRISM] Fix keyword splat inside of array
...
Fixes ruby/prism#2155 .
2024-01-15 17:12:53 -05:00
Peter Zhu
7c6d7fbc28
[PRISM] Fix case without predicate
...
Fixes ruby/prism#2149 .
2024-01-15 09:58:44 -05:00