EEC-Developers / eec

Enhanced E Compiler - AmigaE programming
Other
12 stars 3 forks source link

Assembly Macro enhancements #10

Closed SamuraiCrow closed 2 years ago

SamuraiCrow commented 4 years ago

I noticed that ECX implements only a subset of the macro functions of VAsm. Adding the capabilities of VAsm would allow some constructs to be re-implemented as macros, thus simplifying the parser greatly. For example, VAsm has macro functions for accessing an internal context stack that could be used to store parameters and solve the problem illustrated in the documentation of the Macro command:

myforloop: MACRO \1 WHILE \2 ENDM

myendfor: MACRO \1 ENDWHILE ENDM

In this example the step increment of the FOR loop macro has to be passed to the myendfor macro instead of being applied as a third parameter in myforloop. Using the stack, that could be avoided completely.

As a stretch goal, we could even make the macro definitions nestable so that loops could be rearranged so that the exit point will always be at the end, thus moving the unconditional branch outside the loop as invariant.

Hypexed commented 2 years ago

I've seen those extra macro functions doing loops and stuff in early 68K days. So would this be to help the compiler and offer features to the user as a side effect? This reminds me of a quote in one of the EC guides, since macro ability was brought up and to paraphrase it, there's the rest of the E language to do all that. :-)

SamuraiCrow commented 2 years ago

The entire rest of the E language doesn't support variadic macros. (That's macros with variable number of parameters.) As a comparison, VAsm supports as many as 35 positional parameters and a SHIFT command to shift all the macros a specified number of parameters. Anything more is a bonus, but VAsm has a stack access macro definitions also.

SamuraiCrow commented 2 years ago

Adding to what I said yesterday, variadic macro definitions would be the tool that could be used to implement multi-dimensional arrays and other capabilities that couldn't have easily been added to the language without altering it otherwise.

Hypexed commented 2 years ago

Does C support variadic macros? I see a few defines used in E code which I consider "wrong" as E should use built in CONST. It just doesn't look right seeing hashes in E code. Doesn't look built in like MACRO is.

I had forgot about multi-dimensional arrays. I haven't looked into the ECX code but I don't see why it would be a big problem nor why it wasn't put into ECX. Given an array has an index it would make sense to expand it as a list. The "C" way could work but it gets annoying typing [x][y][z] when [x,y,z] would work just as well and looks clear enough. At the end of the day, you multiply the coordinates with an object size to get an offset, just like with one index and object size, so I don't see this as an impossible E language feature.

SamuraiCrow commented 2 years ago

Yes C11 supports variadic macros. The earlier versions didn't. The current trend is away from preprocessors altogether. If we want to incorporate multi-dimensional arrays in the language, we might as well incorporate Rust-style slices. (Partial evaluation of the index leaving other dimensions for parameter passing.)

SamuraiCrow commented 2 years ago

I'm closing this issue for now. I'll open up a separate issue for multi-dimensional arrays.