summaryrefslogtreecommitdiff
path: root/prism_compile.c
AgeCommit message (Collapse)Author
2024-01-17[Prism] Implement defined? for PM_IF_NODEeileencodes
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[Prism] Implement defined? for PM_FOR_NODEeileencodes
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[Prism] Implement defined? for PM_DEF_NODEeileencodes
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[Prism] Implement defined? for PM_CLASS_NODEeileencodes
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[Prism] Implement defined? for PM_CASE_MATCH_NODEeileencodes
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[Prism] Implement defined? for PM_CASE_NODEeileencodes
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[PRISM] Refactor keyword hash nodesPeter Zhu
Follow up to #9540.
2024-01-17[PRISM] Remove unnecessary flag settingPeter Zhu
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[Prism] Implement defined? for PM_INDEX_OR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_INDEX_OPERATOR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_INDEX_AND_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CONSTANT_PATH_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CONSTANT_PATH_OR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CONSTANT_PATH_OPERATOR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CONSTANT_PATH_AND_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CALL_OR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CALL_OPERATOR_WRITE_NODEeileencodes
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[Prism] Implement defined? for PM_CALL_AND_WRITE_NODEeileencodes
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[PRISM] Fix indentation in pm_setup_args [ci skip]Peter Zhu
2024-01-17[PRISM] Fix fallthrough for PM_ENSURE_NODEPeter Zhu
This caused it to fall into PM_ELSE_NODE which caused ensure nodes to be compiled twice. Fixes ruby/prism#2176.
2024-01-17[PRISM] Fix memory leak of ST tablePeter Zhu
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[Prism] Fix more method call argumnentseileencodes
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[Prism] Implement defined? for PM_BEGIN_NODEeileencodes
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[Prism] Implement defined? for PM_RETRY_NODEeileencodes
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[Prism] Implement defined? for PM_RETURN_NODEeileencodes
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[Prism] Implement defined? for PM_REDO_NODEeileencodes
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[Prism] Implement defined? for PM_INTERPOLATED_X_STRING_NODEeileencodes
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[Prism] Implement defined? for PM_INTERPOLATED_SYMBOL_NODEeileencodes
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[Prism] Implement defined? for PM_DEFINED_NODEeileencodes
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[Prism] Implement defined? for PM_BREAK_NODEeileencodes
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[Prism] Implement defined for PM_NEXT_NODEeileencodes
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[PRISM] Fix stack inconsistency in MultiWriteNodeMatt Valentine-House
2024-01-16[PRISM] Fix crash with empty ensure blocksPeter Zhu
Fixes ruby/prism#2179.
2024-01-16[PRISM] Replace local lookup recursion with loopMatt Valentine-House
2024-01-16[PRISM] Don't allocate labels when not neededPeter Zhu
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[PRISM] Fix splat assignmentPeter Zhu
Fixes ruby/prism#2177
2024-01-16Rename pm_lookup_local_index_any_scopeMatt Valentine-House
Now it's the only local lookup function we can just call it pm_lookup_local_index
2024-01-16Remove scope_node->local_depth_offsetMatt Valentine-House
2024-01-16Remove pm_lookup_local_index_with_depthMatt Valentine-House
2024-01-16Remove the found_depth pointerMatt Valentine-House
Now that we're returning pm_local_index_t
2024-01-16Return pm_local_index_t when looking up local indexesMatt Valentine-House
instead of returning the index and updating found_depth in the parent scope
2024-01-16Bind index & depth together into pm_local_index_tMatt Valentine-House
2024-01-16Replace pm_lookup_local_index with lookup_local_index_with_depthMatt Valentine-House
2024-01-16[PRISM] Fix defined? for chained callsPeter Zhu
Fixes ruby/prism#2148.
2024-01-15[PRISM] Fix keyword splat inside of arrayPeter Zhu
Fixes ruby/prism#2155.
2024-01-15[PRISM] Fix case without predicatePeter Zhu
Fixes ruby/prism#2149.
2024-01-12Only intern constants upon compilation entryAaron Patterson
Before this commit the Prism compiler would try to intern constants every time it re-entered. This pool of constants is "constant" (there is only one pool per parser instance), so we should do it only once: upon the top level entry to the compiler. This change does just that: it populates the interned constants once. Fixes: https://github.com/ruby/prism/issues/2152
2024-01-12Fix splat assigns with no leftiesAaron Patterson
We still need to emit an expand array even if there's no "left side" variables Fixes: https://github.com/ruby/prism/issues/2153
2024-01-12Always freeze strings that are in the instructionsAaron Patterson
Any objects that the instructions reference should be frozen. Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-12[PRISM] Pre-concatenate Strings in InterpolatedStringNodeJemma Issroff
This commit concatenates String VALUEs within InterpolatedStringNodes to allow us to preserve frozenness of concatenated strings such as `"a""b"` Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>