Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elseif and switch Support #160

Open
HzanRsxa2959 opened this issue Jul 24, 2021 · 6 comments
Open

elseif and switch Support #160

HzanRsxa2959 opened this issue Jul 24, 2021 · 6 comments

Comments

@HzanRsxa2959
Copy link

HzanRsxa2959 commented Jul 24, 2021

If elseif support is added first, then switch support could be derived from that.
Otherwise switch support could be added using opcodes 0871 and 0872 (only support integers, though).
GTA3Script already has nested switch support using opcodes 0871 and 0872.

@x87 x87 added this to the Language Specification milestone Jul 25, 2021
@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Jul 26, 2021

Maybe it is better with conditional jump opcodes

switch 0@
    case 1
        [...]
    end
    case "2"
        [...]
    end
    case Actor.IsDead()
        [...]
    case 0x4
        [...]
    end
    default
        [...]
    end
end

TO COMPILE AND DECOMPILE

:LABEL_1X // begin SWITH
XXXX: if
XXXX: 0@ == 1  // CASE 1
XXXX: jf @LABEL_2X
[...]
XXXX: goto @LABEL_7 // exit SWITH
:LABEL_2X
XXXX: if
XXXX: 0@ == "2"  // CASE 2
XXXX: jf @LABEL_3X
[...]
XXXX: goto @LABEL_7 // exit SWITH
:LABEL_3X
XXXX: if
XXXX: actor 0@ is_dead  // CASE 3
XXXX: jf @LABEL_5X
[...]
:LABEL_4X
XXXX: if
XXXX: 0@ == 0x4  // CASE 4
XXXX: jf @LABEL_5X
[...]
XXXX: goto @LABEL_7X // exit SWITH
:LABEL_5X
[...]          // DEFAULT
XXXX: goto @LABEL_7X
:LABEL_7X // end SWITH

@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Jul 26, 2021

The same I think could be applied to ELSE-IF

if 0@ == 1
    [...]
else if 0@ == "5"
    [...]
else
    [...]
end

TO COMPILE AND DECOMPILE

:LABEL_1X // begin ELSE-IF
XXXX: if
XXXX: 0@ == 1   // if
XXXX: jf @LABEL_2X
[...]
XXXX: goto @LABEL_4X // exit ELSE-IF
:LABEL_2X
XXXX: if
XXXX: 0@ == "5"   // else if
XXXX: jf @LABEL_3X
[...]
XXXX: goto @LABEL_4X // exit ELSE-IF
:LABEL_3X
[...]           // else
:LABEL_4X // end ELSE-IF

@XMDS
Copy link
Member

XMDS commented Jul 27, 2021

Maybe it is better with conditional jump opcodes

switch 0@
    case 1
        [...]
    end
    case "2"
        [...]
    end
    case Actor.IsDead()
        [...]
    case 0x4
        [...]
    end
    default
        [...]
    end
end

TO COMPILE AND DECOMPILE

:LABEL_1X // begin SWITH
XXXX: if
XXXX: 0@ == 1  // CASE 1
XXXX: jf @LABEL_2X
[...]
XXXX: goto @LABEL_7 // exit SWITH
:LABEL_2X
XXXX: if
XXXX: 0@ == "2"  // CASE 2
XXXX: jf @LABEL_3X
[...]
XXXX: goto @LABEL_7 // exit SWITH
:LABEL_3X
XXXX: if
XXXX: actor 0@ is_dead  // CASE 3
XXXX: jf @LABEL_5X
[...]
:LABEL_4X
XXXX: if
XXXX: 0@ == 0x4  // CASE 4
XXXX: jf @LABEL_5X
[...]
XXXX: goto @LABEL_7X // exit SWITH
:LABEL_5X
[...]          // DEFAULT
XXXX: goto @LABEL_7X
:LABEL_7X // end SWITH

It is best for SA to give priority to 0871 and 0872.
Conditional opcodes need to be distinguished,
But the latter is more suitable for VC and 3. Because VC and 3 do not have these commands

@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Jul 27, 2021

0871 & 0872 could be used in the case that the SWITCH only contains INTERGERS and if it is also the same as the one with which it is compared.
You couldn't tell if one number is greater than another or something else :(

@wmysterio
Copy link

wmysterio commented Jul 28, 2021

@MatiDragon-YT

0871 & 0872 could be used in the case that the SWITCH only contains INTERGERS and if it is also the same as the one with which it is compared.
You couldn't tell if one number is greater than another or something else :(

It looks more like "expressions (mapping)" than a classic "switch". However, design compatibility across all games would be a priority for me over a limited case jump table.

@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Jul 29, 2021

It looks more like "expressions (mapping)" than a classic "switch".

Exactly @wmysterio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants