z00m128 / sjasmplus

Command-line cross-compiler of assembly language for Z80 CPU.
http://z00m128.github.io/sjasmplus/
BSD 3-Clause "New" or "Revised" License
382 stars 54 forks source link

lua block parsing inside macro is not aware of being inside lua block, applying sjasmplus parsing rules (colons!) #224

Open ped7g opened 11 months ago

ped7g commented 11 months ago

v1.20.3 all platforms

when colon is used inside lua code which is defined inside macro, it doesn't work (probably the line gets split as macro parser is not sensitive to lua blocks).

Needs example, there is 7.4 in docs with colons, something similar, using same block of lua inside/outside of macro to verify the bug exists and to debug it (I'm too busy/lazy to write it now).

specke commented 8 months ago

This is a simple example to illustrates the issue above:

        DEVICE ZXSPECTRUM48

        ORG 32768

        ; three ways to detect length of a file using LUA

        ; 1. direct LUA (this works)
    LUA PASS3
        local f = io.open("macro_lua.asm", "rb")
        local file_len = f:seek("end")
        f.close(f)
        print("'macro_lua.asm' is " .. file_len .. " bytes long")
    ENDLUA

        ; 2. LUA inside of macro (this does not work)
    MACRO LUA.FileLength1
    LUA PASS3
        local f = io.open("macro_lua.asm", "rb")
        local file_len = f:seek("end")
        f.close(f)
        print("'macro_lua.asm' is " .. file_len .. " bytes long")
    ENDLUA
    ENDM
        ; LUA.FileLength1

        ; if line above is uncommented, the following error message is generated:
        ; macro_lua.asm(20): error: [LUA] attempt to call a nil value (global 'seek')
        ; macro_lua.asm(24): ^ emitted from here

        ; 3. a temporary work around for the above problem (it works)
    MACRO LUA.FileLength2
    LUA PASS3
        local f = io.open("macro_lua.asm", "rb")
        local file_len = f.seek(f, "end")   --; explicit call to the class method avoids using colon
        f.close(f)
        print("'macro_lua.asm' is " .. file_len .. " bytes long")
    ENDLUA
    ENDM
        LUA.FileLength2

(Please note that I assume that the whole of the above snippet of code is residing in a file named macro_lua.asm).