santiontanon / mdlz80optimizer

MDL (a Z80 assembler optimizer)
Apache License 2.0
81 stars 6 forks source link

Preliminary tniASM syntax support #4

Closed theNestruo closed 4 years ago

theNestruo commented 4 years ago

Preliminary tniASM syntax support. It is not completely functional yet!

This pull request is a little/bit rough around the edges because Dialect cannot contain entire definition of a dialect (some parts of tniASM syntax support ended up in ExpresisonParser and PreProcessor/SourceMacro...)

At the moment, lib/msx/cartridge.asm cannot be parsed. But I have been unable to understand the exact cause of problem... so I guess I'll make the pull request now and investigate further later O:-)

ERROR: File lib/msx/cartridge.asm ended while inside a macro definition of "if" at #12:
        org     $4000, $4000 + (CFG_INIT_ROM_SIZE * $0400) - 1
ERROR: Problem expanding macros after loading all the source code!
santiontanon commented 4 years ago

Nice! Thanks a lot for the initial tniasm support theNestruo!!! I see a couple of things that might be the cause of the problem, let me merge and check it out! I see the parseLine method of the tniasm dialect class does something different from what the code actually expects. So, will do a couple of fixes after I merge :)

santiontanon commented 4 years ago

Ok, I figured out what was happening. The bug was not on your side, but on the preProcessor. I just fixed it and it works. Sorry for the bug!!! cartridge.asm is properly parsed now :)

santiontanon commented 4 years ago

Btw, when defining a dialect, you only need to worry about the keywords that are not already parsed by MDL. No need for "org", "db", "dw", etc. as those will never be passed to the dialect. You only need to add support for the dialect specific keywords.

About spilling into the ExpressionPaser, (for XOR, AND, etc.). It's totally ok! If we have a similar issue with some other dialect, we can generalize and add a "synonym" hashMap like in the LineParser and PreProcessor classes that the Dialect classes can fill in. But for now, I think it's ok :)