thelink2012 / gta3sc

GTA3script compiler
MIT License
71 stars 13 forks source link

Restore RETURN_TRUE and RETURN_FALSE in SA #113

Open thelink2012 opened 7 years ago

thelink2012 commented 7 years ago

Not sure if that should be done at compile time (translating to other command), or at a runtime implementation.

x87 commented 7 years ago

What do you mean by restore? 00C5/00C6 are functional in III/VC

thelink2012 commented 7 years ago

Opss... I meant VC/SA. It's functional in VC? Nice then.

x87 commented 7 years ago

It is functional in VC via http://www.gtamodding.com/wiki/Opcodes_Restoration_Project or with alternate opcodes 0485, 059A. Those are valid for SA either.

thelink2012 commented 7 years ago

Yes, that's the question in here, Whether RETURN_TRUE should be mapped to those commands, or re-implemented at runtime.

WHILE IS_PC_VERSION is not intuitive e.g.

x87 commented 7 years ago

Do we really need this opcode in such constructions? For example, Sanny Builder treats while true as a single unconditional jump:

:loop
jump @loop

If you want to use return_true/return_false as a result of CLEO functions then they still could be omitted:

if 
   0@ > 0
then
   return_true
else
   return false
end
ret

essentially the same as

0@ > 0
ret

See what I mean? The compiler might do some optimizations to omit useless code, so in runtime there will be no differences, but they will be in the decompiled code (no 1-to-1 match). In general I think it's OK.

thelink2012 commented 7 years ago

Do we really need this opcode in such constructions? For example, Sanny Builder treats while true as a single unconditional jump:

Everything is a command in GTA3script. As such, to have a infinite loop you need an always true command within the while. Such condition is RETURN_TRUE, or even something like x = x.

Indeed, both can be taken out by the optimizer (only if -O), which would be zero-cost, but unfortunately it cannot for multifiles because the determinism of the compilation is compromised by the optimizer.

Yeah, the language do not have any infinite loop construct, Rockstar used labels and gotos when those were needed.

If you want to use return_true/return_false as a result of CLEO functions then they still could be omitted:

But RETURN_TRUE is not a valid command in VC/SA, see? You cannot really write this at the moment, you have to go for the uglier commands that produce the same behaviour.

JuniorDjjr commented 4 years ago

I just add a copy of these commands in cleo.xml, whatever...

<Command ID="0x485" Name="TRUE"/>
<Command ID="0x485" Name="RETURN_TRUE"/>
<Command ID="0x59a" Name="RETURN_FALSE"/>

I taught this in my gta3script tutorial and most people do the same.