summaryrefslogtreecommitdiff
path: root/test/ruby/test_compile_prism.rb
AgeCommit message (Collapse)Author
2023-12-07[PRISM] Account for multiple arguments when compiling ArgumentsNodeJemma Issroff
BreakNode, ReturnNode and NextNode all compile the ArgumentsNode directly, but we weren't accounting for multiple arguments. If there is more than one argument, we need to also emit a newarray instruction to put the arguments onto the stack
2023-12-07[PRISM] Stop catch table entries being deleted by the optimiserMatt Valentine-House
2023-12-07[PRISM] Don't pop arguments on a return nodeJemma Issroff
Since ReturnNodes don't get popped, their arguments shouldn't either
2023-12-07[PRISM] Rescue should set correct end_labelMatt Valentine-House
In order for a break inside the rescue to have the correct jump target
2023-12-06[PRISM] Correct depth offset for block local varsMatt Valentine-House
Blocks should always look at their own local table first, even when defined inside an ensure/rescue or something else that uses depth offset. We can ignore the depth offset if we're doing local lookups inside a block
2023-12-06[PRISM] Fix ReturnNodesJemma Issroff
This code is almost exactly the same (fixed variable names) as what exists already in compile.c
2023-12-06[PRISM] Account for nil parent in Call{Operator,And,Or}PathWriteNodesJemma Issroff
Prior to this commit, we were not accounting for the case of a nil parent in a CallXPathWriteNode, for example ::A ||= 1. This commit checks if the parent exists, and if not, uses Object as the inferred parent
2023-12-06[PRISM] Implement `PM_MATCH_PREDICATE_NODE` for `defined?`eileencodes
Ruby code: ```ruby defined? 1 in 1 ``` Instructions: ``` "********* 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 ```
2023-12-06[PRISM] Implement `PM_KEYWORD_HASH_NODE` for `defined?`eileencodes
Ruby code: ```ruby defined? [a: [:b, :c]] ``` Instructions (without optimizations): ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,23)> == catch table | catch type: rescue st: 0001 ed: 0007 sp: 0000 cont: 0009 | == disasm: #<ISeq:defined guard in <compiled>@<compiled>:0 (0,0)-(-1,-1)> | local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) | [ 1] "$!"@0 | 0000 putnil | 0001 leave |------------------------------------------------------------------------ 0000 putnil 0001 putobject true 0003 branchunless 9 0005 putobject "expression" 0007 swap 0008 pop 0009 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,23)> == catch table | catch type: rescue st: 0000 ed: 0009 sp: 0000 cont: 0009 | == disasm: #<ISeq:defined guard in <compiled>@<compiled>:0 (0,0)-(-1,-1)> | local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) | [ 1] "$!"@0 | 0000 putnil | 0001 leave |------------------------------------------------------------------------ 0000 putnil 0001 putobject true 0003 branchunless 9 0005 putobject "expression" 0007 swap 0008 pop 0009 leave ``` Instructions (with optimizations): ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,23)> == catch table | catch type: rescue st: 0001 ed: 0003 sp: 0000 cont: 0005 | == disasm: #<ISeq:defined guard in <compiled>@<compiled>:0 (0,0)-(-1,-1)> | local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) | [ 1] "$!"@0 | 0000 putnil | 0001 leave |------------------------------------------------------------------------ 0000 putnil 0001 putobject "expression" 0003 swap 0004 pop 0005 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,23)> == catch table | catch type: rescue st: 0000 ed: 0005 sp: 0000 cont: 0005 | == disasm: #<ISeq:defined guard in <compiled>@<compiled>:0 (0,0)-(-1,-1)> | local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) | [ 1] "$!"@0 | 0000 putnil | 0001 leave |------------------------------------------------------------------------ 0000 putnil 0001 putobject "expression" 0003 swap 0004 pop 0005 leave ```
2023-12-06[PRISM] Implement `PM_SPLAT_NODE` for `defined?`eileencodes
In an array for `defined?` we need to check if there is a `contains_splat` flag, if so bail early. Ruby code: ```ruby defined?([[*1..2], 3, *4..5]) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,29)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,29)> 0000 putobject "expression" 0002 leave ```
2023-12-06[PRISM] Implement `PM_SOURCE_LINE_NODE` for `defined?`eileencodes
Ruby code: ```ruby defined?(__LINE__) ``` 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 ```
2023-12-06[PRISM] Implement `PM_SOURCE_FILE_NODE` for `defined?`eileencodes
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 ```
2023-12-06[PRISM] Implement `PM_SOURCE_ENCODING_NODE` for `defined?eileencodes
Ruby code: ```ruby defined?(__ENCODING__) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,22)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,22)> 0000 putobject "expression" 0002 leave ```
2023-12-06[PRISM] Implement `PM_IMAGINARY_NODE` for `defined?`eileencodes
Ruby Code: ``` defined?(1i) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putobject "expression" 0002 leave ```
2023-12-06[PRISM] Compile Rescue Modifier nodesMatt Valentine-House
2023-12-05[PRISM] Implement Retry node.Matt Valentine-House
2023-12-04[PRISM] Fixed redo nodeJemma Issroff
2023-12-04[PRISM] Handle percent literals for `defined?`eileencodes
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 ```
2023-12-04[PRISM] Implement `PM_INTERPOLATED_REGULAR_EXPRESSION_NODE`eileencodes
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 ```
2023-12-04[PRISM] Implement `PM_INTERPOLATED_STRING_NODE`eileencodes
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 ```
2023-12-04[PRISM] Fix `PM_PARENTHESES_NODE`eileencodes
In #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 ```
2023-12-04[Prism] Implement backref and numbered reference for `defined?`eileencodes
This PR implements `PM_BACK_REFERENCE_READ_NODE` and `PM_NUMBERED_REFERENCE_READ_NODE` for `defined?`. The following now works: * `PM_NUMBERED_REFERENCE_READ_NODE` ``` defined? $1 defined? $2 ``` Instructions: ``` "********* RUBY *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putnil 0001 defined ref, :$1, "global-variable" 0005 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putnil 0001 defined ref, :$1, "global-variable" 0005 leave ``` * `PM_BACK_REFERENCE_READ_NODE` ``` defined? $' defined? $` defined? $& ``` Instructions: ``` "********* RUBY *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putnil 0001 defined ref, :$`, "global-variable" 0005 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,12)> 0000 putnil 0001 defined ref, :$`, "global-variable" 0005 leave ```
2023-12-04[PRISM] Fix compilation for NextNodeJemma Issroff
This code was almost enitrely the same as the existing compiler's code for its NextNode.
2023-12-01Implement paren node for `defined?`eileencodes
Implements and adds a test for passing a parentheses node to `defined?`.
2023-12-01Implements missing literals for `defined?`eileencodes
This PR implements the following literals: - String - Symbols - Integers - Floats - Regexs - Ranges - Lambdas - Hashes and tests for them.
2023-12-01[PRISM] Account for RescueNodes with no statementsJemma Issroff
We need a PUTNIL if a RescueNode has no statements.
2023-12-01[PRISM] Fix behavior of BlockParameters with only one parameterJemma Issroff
This commit sets the ambiguous param flag if there is only one parameter on a block node. It also fixes a small bug with a trailing comma on params.
2023-12-01[PRISM] Restructure parametersJemma Issroff
Prior to this commit, we weren't accounting for hidden variables on the locals table, so we would have inconsistencies on the stack. This commit fixes params, and introduces a hidden_variable_count on the scope, both of which fix parameters.
2023-12-01[PRISM] Compile RescueNodeMatt Valentine-House
2023-11-30[Prism] Fix local variable access for POST_EXECUTION_NODEMatt Valentine-House
2023-11-30Store depth offset inside the scope node.Matt Valentine-House
Instead of incrementing the depth using call by reference as we're recursing up the stack we could instead store an offset for each known scope where we know the depth is going to represented differently in the Prism ast.
2023-11-30Add a rescue for `defined?(A::B::C)`Aaron Patterson
It's possible for `defined?(A::B::C)` to raise an exception. `defined?` must swallow the exception and return nil, so this commit adds a rescue entry for `defined?` expressions on constant paths
2023-11-29[PRISM] Implement CallNodes with splat followed by argsJemma Issroff
2023-11-29[PRISM] Account for ImplicitRestNodeJemma Issroff
Prism introduced a new ImplicitRestNode. This adds tests for the ImplicitRestNode cases, and changes one assert which is no longer accurate.
2023-11-29[PRISM] Fix EnsureNode, pass depth to get localsJemma Issroff
This commit fixes a bug with locals in ensure nodes by setting the local tables correctly. It also changes accessing locals to look at local tables in parent scopes, and account for this correctly on depths of get or setlocals.
2023-11-28[PRISM] Don't calculate params size based on localsJemma Issroff
Prior to this commit, we were conflating the size of the locals list with the number of parameters. This commit distinguishes the two, and fixes a related bug which would occur if we set a local that was not a parameter
2023-11-28[PRISM] Implement more compilation of SplatNodesJemma Issroff
There was a bug with the rest argument in SplatNodes, this commit fixes it, and adds more tests illustrating the behavior of SplatNodes
2023-11-28[PRISM] Compile YieldNode with different argumentsJemma Issroff
2023-11-28[PRISM] Run test setting global constant separatelyAlan Wu
This impacted other tests. Please mind the commons. /home/runner/work/ruby/ruby/src/test/ruby/test_compile_prism.rb:394: warning: already initialized constant Bar /tmp/test_reline_config_60145/bazbarbob.rb:6: warning: previous definition of Bar was here 1) Failure: TestModule#test_const_get_evaled [/home/runner/work/ruby/ruby/src/test/ruby/test_module.rb:1239]: NameError expected but nothing was raised.
2023-11-27[PRISM] Small fixes to parameters ordering and methodsJemma Issroff
2023-11-27[PRISM] Compile IndexOperatorWriteNodeJemma Issroff
2023-11-27[PRISM] Compile IndexAndWriteNodeJemma Issroff
2023-11-27[PRISM] Compile IndexOrWriteNodeJemma Issroff
2023-11-27[PRISM] Fix compilation for SplatNodes within ArrayNodesJemma Issroff
SplatNodes within ArrayNodes (e.g. [*1..2, 3]) need to be special cased in the compiler because they use a combination of concatarray and newarray instructions to treat each sequence of splat or non-splat elements as independent arrays which get concatenated. This commit implements those cases.
2023-11-27[PRISM] Don't pop several args related nodesJemma Issroff
2023-11-21Remove string concat node in prismKevin Newton
2023-11-20[PRISM] Updated LocalVariableTargetNodes tooJemma Issroff
2023-11-20[PRISM] Fix LocalVariableWriteNodes within blocksJemma Issroff
Prior to this commit, we weren't recursing up scopes to look for the local definition. With this commit, we do so, fixing local writes within blocks
2023-11-20[PRISM] Implement once node for interpolated regexeileencodes
This PR implements the once node on interpolated regexes. There is a bug in Prism where the interpolated regex with the once flag only works when there is not a local variable so the test uses a "1". We'll need to fix that.
2023-11-20[PRISM] Don't pop args to YieldNodeJemma Issroff