You should always generate the same code in every pass. i.e. "ALLPASS" is usually the only correct setting (hmm, makes me wonder why it is not "default" if you write just "lua").
The PASS1 / PASS2 / PASS3 are special extras, if you know what you are doing (PASS1 is OK to define global variables and functions in lua, although with ALLPASS you will just redefine them every time = usually works too).
You can create the "pass" variable in lua like this:
Код:
lua pass1
lua_pass = 1
endlua
; ... some code
lua allpass
print("Lua pass: "..lua_pass)
lua_pass = lua_pass + 1
endlua
But you should generate the same code at the same positions in every pass.
If you understand how it internally works, you can get away by generating slightly different code in pass1 (the relative positions of labels must be valid already (and all labels must be emitted), but absolute positions in memory (and machine code emitted between) may change between pass1 and pass2, pass3 should be identical to pass2.
edit:
"приходиться дублировать один и тот же код!!!!!11111одинодинодин"
I think I now better understand what you mean, and you don't understand it correctly, it's not "adding" code, like you can generate some code in pass1, some in pass2 and final in pass3.
The assembler needs pretty much the identical source 3 times to produce correct machine code.
The pass1 can look somewhat different than final one, although already *all* [global] labels and ideally in correct relative order should be defined, only some absolute positions may change. pass2 should produce the same source as pass3, any difference there may cause unexpected results.
My comment about that dynamic allocator was going like this, to remember subroutine sizes from pass1 (where they would be allocated all into the same page, overwriting each other), and using that info at end of pass1 to calculate final positions for pass2 and pass3, but that must be done quite carefully to bend the assembling internal state correctly, to get correct machine code at end of pass3, it's a bit more advanced trick (you should probably read first source code of sjasmplus to understand how it works, before trying these kind of tricks).
edit2:
And if the N-pass will be added, that again does not mean you can add small bits of code in every pass, but it means that the dynamic source, which is seen by assembler (produced by lua/includes/dups/macros/...), must be identical between passN and pass(N-1). If you will keep changing the generated code, the N-pass will never finish assembling, as it waits for identical passes (well, it would error out on max-passes reached). So you need to design the dynamic parts like that, producing same source as early as possible (some difference between pass1 and pass2 are ok, some are not, pass2 and pass3 should be identical to be safe, although for example same-size opcode change like "nop" in pass2 vs "ret" in pass3 don't cause any harm, "ret" is produced in the final binary).