Menu

Unrealistic result; pseudo-goto

razc01na
2025-01-31
2025-01-31
  • razc01na

    razc01na - 2025-01-31

    I have been having trouble trying to figure out the original code for part of this lua file. It contains a "pseudo-goto" to reproduce what seems to be something that can't quite be compiled by normal means.
    Unluac gives the following output:

    if bCounterRunning then
                repeat
                    break -- pseudo-goto
                until true
                if bSkipClose then
                    gGordBlip = AddBlipForChar(gord, 5, 0, 5)
                    gLolaBlip = AddBlipForChar(lola, 4, 0, 5)
                    bCounterRunning = false
                    TextPrint("3_01_OALLEY", 4, 1)
                end
            end
    

    The prolem is, compiling again gives a completely different result.

    This is the disassemble for the original chunk:

    .label  l401
    .line   218 getupval     r12    u0
    .line   218 test         r12   r12     0
    .line   218 jmp         l429
    .line   220 jmp         l408
    .line   220 getupval     r12   u15
    .line   220 test         r12   r12     0
    .line   220 jmp         l429
    .label  l408
    .line   222 getglobal    r12   k94 ; k94 = "AddBlipForChar"
    .line   222 getupval     r13    u8
    .line   222 loadk        r14   k95 ; k95 = 5
    .line   222 loadk        r15   k14 ; k14 = 0
    .line   222 loadk        r16   k95 ; k95 = 5
    .line   222 call         r12     5     2
    .line   222 setupval     r12   u16
    .line   224 getglobal    r12   k94 ; k94 = "AddBlipForChar"
    .line   224 getupval     r13    u9
    .line   224 loadk        r14   k79 ; k79 = 4
    .line   224 loadk        r15   k14 ; k14 = 0
    .line   224 loadk        r16   k95 ; k95 = 5
    .line   224 call         r12     5     2
    .line   224 setupval     r12   u17
    .line   225 loadbool     r12     0     0
    .line   225 setupval     r12    u0
    .line   228 getglobal    r12   k74 ; k74 = "TextPrint"
    .line   228 loadk        r13   k96 ; k96 = "3_01_OALLEY"
    .line   228 loadk        r14   k79 ; k79 = 4
    .line   228 loadk        r15   k21 ; k21 = 1
    .line   228 call         r12     4     1
    .label  l429
    

    There are 2 jmp instructions back-to-back, which wouldn't be a problem if this was not lua5.0.2 and there was support for goto.

    I have searched other topics here related to "pseudo-goto" and even tried to recreate some code I found but nothing seems to get the same bytecode. I just can't figure this out.

    I included the problematic file in attachments and was hoping to find some help if possible. Thank you!

     
  • tehtmi

    tehtmi - 2025-01-31

    I think it should be

    if bCounterRunning then
      if true or bSkipClose then
        --...
      end
    end
    

    Let me know if you think that doesn't match.

    Non-branching conditional is another way of getting a naked jump, probably more common that repeat break. Unluac knows about it and will generate it sometimes, but I think actually it isn't considered for conditional combining which would be the only way for it to end up in an 'or' expression. It might be a pain since unluac's current order of operations would make this a reverse-dependency -- combined branches are used to contextualize the more complicated and subtle unconditional jumps (else/break/goto). I'll be thinking about it, but don't expect quick turnaround for a fix.

     
  • razc01na

    razc01na - 2025-01-31

    That was it!

    It's just weird why anyone would write code like this, not really something one would see everyday so it can be challenging to figure out. There is no problem at all, I just couldn't figure this one out. But now it's done. Thank you!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.