Skip to content

Nested macro definitions #74

Open
Open
@Rhialto

Description

@Rhialto

The docs say:

GENERAL:
    Most everything is recursive.  You cannot have a macro DEFINITION
    within a macro definition, but can nest macro calls, repeat loops,
    and include files.

Actually to have such a facility is useful sometimes. Digital's Macro-11 assembler allows it. One way this is commonly used (well, common for a specific assembler for an obsolete CPU architecture) is use-once macros. A macro, if it is used, re-defines itself to be empty. Something like this: (see also https://gitlab.com/Rhialto/macro11/-/blob/master/tests/test-endm.lst.ok for a listing output)

;;;;;
;
; Test nested macros and name on .ENDM
;

    .macro      M1
    .word       1
    .endm       M1      ; ok

    M1

    .macro      M2
    .word       2
    .macro      M3
    .word       3
    .endm       M3      ; ok
    .endm       M2      ; ok

    M2
    M3

    .macro      M4
    .word       4
    .macro      M4
    .endm       M4      ; ok
    .endm       M4      ; ok

    M4
    M4                  ; should be empty now

    .macro      M5
    .word       5
    .macro      M5
    .endm       notM5   ; wrong; detected when M5 is expanded
    .endm       M5      ; ok

    M5
    M5

    .macro      M6
    .endm       notM6   ; wrong

    .endm               ; end without macro
    .endr               ; end without repetition
    .endc               ; end without condition

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions