Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested macroses #143

Open
nihirash opened this issue Apr 4, 2021 · 1 comment
Open

Nested macroses #143

nihirash opened this issue Apr 4, 2021 · 1 comment
Milestone

Comments

@nihirash
Copy link

nihirash commented Apr 4, 2021

Feature request
Implement feature that allow define macros inside macros.

It can be cool for meta-programming and implementing DSLs inside sjasmplus(it really can be useful).

For example:

      macro def_proc name
      macro name
      dw name_proc
      endm
name_proc:
      endm

and later

   def_proc cls
   xor a
   ld hl, #4000, de, #4001, bc, 6911, (hl), a
   ldir
   next ; some macros to change to next instruction

and in part where interpreter work

    call kernal.run
    cls
    loop 10
    someproc_1
    vsync
    end_loop
    cls

Cause I'm making some interpreter engine it will be very useful for me.

@ped7g
Copy link
Collaborator

ped7g commented Apr 6, 2021

In your example case (work-around proposal), you could do this:

    macro def_proc name
        define do_name dw name_proc
name_proc:
    endm

   def_proc cls
   xor a
   ld hl, #4000, de, #4001, bc, 6911, (hl), a
   ldir

   do_cls
  ; must have the "do_" or some other prefix
  ; can't define just "cls" without recursion accident

(it's actually kinda funny you can define do_cls inside the macro, outside of macro you would define do_name as the substitution would not touch the define identifier, but because it's inside macro and macro argument, it gets substituted even there, producing final line define do_cls dw cls_proc, I didn't expect it to work like this, just tried it blindly if it does anything)

This issue is still valid enhancement proposal, even if the workaround is good enough for your project, as the workaround can cover only very limited cases, so leaving it open.

I was also trying to produce some more clever lua workaround, but actually you can't define macros from lua either, not even outside of macro, because there is no way to parse multi-line piece of source from lua, and macro can't be defined by single statement (the colons are treated like end-of-line internally, so that can't be used to avoid the limitation).

@ped7g ped7g added this to the v2.x milestone Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants