Re: Rob: Q: Re: Major Bug in Interpreter [Attn: Robert Craig]

new topic     » goto parent     » topic index » view thread      » older message » newer message

Vincent wrote:
> 
> 
> Couldnt you just have made foo[$] translate to foo[length(foo)] in the
> Euphoria IL?

This would be much less efficient for cases where '$' is really useful
(and is actually more than simple syntactic sugar).  I used my IL code
disassembler to show you why:

For your simple case, you can see that identical code is emitted:

     5: 042 103 105                      # LENGTH: [foo:103] => [_temp_:105]
8: 025 103 105 105                  # RHS_SUBS: [foo:103] sub [_temp_:105]
     =>
                                         #     [_temp_:105]
    12: 036 104 105                      # QPRINT: [_temp_:105]

    15: 058 4                            # STARTLINE: 4 <<? foo[length(foo)] >>
    17: 042 103 105                      # LENGTH: [foo:103] => [_temp_:105]
20: 025 103 105 105                  # RHS_SUBS: [foo:103] sub [_temp_:105]
    =>
                                         #     [_temp_:105]
    24: 036 104 105                      # QPRINT: [_temp_:105]

If there is some additional subscripting, however, you can see that a simple
translation of $ to length(foo[3][4]) results in more code, and therefore
slower execution:

? foo[3][4][$]:

    27: 058 6                            # STARTLINE: 6 <<? foo[3][4][$] >>
29: 025 103 106 105                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:105]
33: 092 105 107 105                  # RHS_SUBS: [_temp_:105] sub [LIT
    4:107] =>
                                         #     [_temp_:105]
    37: 042 105 108                      # LENGTH: [_temp_:105] => [_temp_:108]
40: 092 105 108 108                  # RHS_SUBS: [_temp_:105] sub
    [_temp_:108]
                                         #     => [_temp_:108]
    44: 036 104 108                      # QPRINT: [_temp_:108]

? foo[3][4][length(foo[3][4]):
47: 058 7                            # STARTLINE: 7 <<?
    foo[3][4][length(foo[3][4])]
                                         #     >>
49: 025 103 106 108                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:108]
53: 092 108 107 108                  # RHS_SUBS: [_temp_:108] sub [LIT
    4:107] =>
                                         #     [_temp_:108]
57: 025 103 106 105                  # RHS_SUBS: [foo:103] sub [LIT 3:106]
    => [_temp_:105]
61: 092 105 107 105                  # RHS_SUBS: [_temp_:105] sub [LIT
    4:107] =>
                                         #     [_temp_:105]
    65: 042 105 105                      # LENGTH: [_temp_:105] => [_temp_:105]
68: 092 108 105 108                  # RHS_SUBS: [_temp_:108] sub
    [_temp_:105]
                                         #     => [_temp_:108]
    72: 036 104 108                      # QPRINT: [_temp_:108]

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu