Skip to content
  • eileencodes's avatar
    049a9bd6
    [PRISM] Fix `compile_prism` when src is a file · 049a9bd6
    eileencodes authored
    `compile_prism` can take a source and file (and other arguments) or a
    file as the source. `compile` checks if the source is a file and if it
    is converts it. `compile_prism` is now doing the same thing.
    
    On the Ruby side `compile` handles a file
    [here](https://github.com/ruby/ruby/blob/master/iseq.c#L1159-L1162).
    
    Before:
    
    ```
    "********* Ruby *************"
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  25)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  26)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave
    hello, Prism
    
    "********* PRISM *************"
    ./test.rb:13:in `compile_prism': wrong argument type File (expected String) (TypeError)
    	from ./test.rb:13:in `<main>'
    make: *** [run] Error 1
    ```
    
    After:
    
    ```
    "********* Ruby *************"
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  25)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  26)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave
    
    "********* PRISM *************"
    == disasm: #<ISeq:<compiled>@test_code.rb:24 (24,0)-(25,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  24)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  25)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave                                                            (  24)
    ```
    
    Fixes ruby/prism#1609
    049a9bd6
    [PRISM] Fix `compile_prism` when src is a file
    eileencodes authored
    `compile_prism` can take a source and file (and other arguments) or a
    file as the source. `compile` checks if the source is a file and if it
    is converts it. `compile_prism` is now doing the same thing.
    
    On the Ruby side `compile` handles a file
    [here](https://github.com/ruby/ruby/blob/master/iseq.c#L1159-L1162).
    
    Before:
    
    ```
    "********* Ruby *************"
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  25)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  26)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave
    hello, Prism
    
    "********* PRISM *************"
    ./test.rb:13:in `compile_prism': wrong argument type File (expected String) (TypeError)
    	from ./test.rb:13:in `<main>'
    make: *** [run] Error 1
    ```
    
    After:
    
    ```
    "********* Ruby *************"
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(26,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  25)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  26)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave
    
    "********* PRISM *************"
    == disasm: #<ISeq:<compiled>@test_code.rb:24 (24,0)-(25,21)>
    local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
    [ 1] name@0
    0000 putstring                              "Prism"                   (  24)[Li]
    0002 setlocal                               name@0, 0
    0005 putself                                                          (  25)[Li]
    0006 putobject                              "hello, "
    0008 getlocal                               name@0, 0
    0011 dup
    0012 objtostring                            <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>
    0014 anytostring
    0015 concatstrings                          2
    0017 send                                   <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, nil
    0020 leave                                                            (  24)
    ```
    
    Fixes ruby/prism#1609
Loading