thpatch / thtk

Touhou Toolkit
https://thtk.thpatch.net/
Other
307 stars 43 forks source link

Restore original loop syntax in ECLs #26

Open ghost opened 7 years ago

ghost commented 7 years ago

Looking at the NHK World interview with ZUN, you can get a glimpse of what the ecl scripts look like when ZUN is working on them himself. I was able to find a similar piece of code in the final game.

In ZUN's engine loops work in a very simple and straightforward manor

Times(iterations)
{
inner code
}

In the ecl disassembly it looks like

$variable = iterations;
goto endofloop;

startofloop:
inner code

endofloop:
decrement $variable
is the result greater than 0? goto beginofloop;

I was wondering if the original syntax can be restored? It might conflict with if statements as there doesn't seem to be any instruction specifically for these instructions and the compiler ZUN uses just generates the logic for them.

Maybe some mechanic that can peek ahead and do some pattern matching to figure out what is and is not a loop? I see some things that resemble while() loops as well but I am not entirely sure about that.

ManDude commented 7 years ago

This is being worked on right now, actually. The ECL scrips will have while(true) loops, for loops, ifs, elses, etc. (I think) to get rid of gotos.

ghost commented 7 years ago

I see, well this is great news then so I'll be on the look out for updates.

32th-System commented 4 years ago

The described has been implemented in thtk 12 https://github.com/thpatch/thtk/releases/tag/12

ManDude commented 4 years ago

Keeping this open because decompilation does not restore the syntax.