zilch-lang/nstar

Copy/paste macros

Opened this issue · 0 comments

Most commonly used assembly languages support copy/paste macros, i.e. macros as in C, where a piece of the input code is basically replaced by either a tool or a compilation step.
This is useful as we could, with targets (see #37), define architecture-specific macros for e.g. print or this sort of function.
We could also automatically (well, there's a limit here, but at least a little) handle calling conventions using macros.


Proposed experimental syntax:

macro <macro-name> (<macro-params>...) {
    macro-body
}

where expanding a parameter is done by prefixing an identifier with @, and calling the macro is the same as writing an instruction (<macro-name> param1, ..., paramN)

We could, as an example, define this:

macro pop (reg) {
    mov (%sp), @reg
    sub %sp, 8          # or 4 depending on the target
}

This is obviously not valid N* code (because of %ip, and the sub instruction on a pointer) but is used as an example of the grammar given earlier.