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

Macro: parameter types and variadic arguments #150

Open
NYYR1KK1 opened this issue Aug 23, 2021 · 1 comment
Open

Macro: parameter types and variadic arguments #150

NYYR1KK1 opened this issue Aug 23, 2021 · 1 comment
Milestone

Comments

@NYYR1KK1
Copy link

NYYR1KK1 commented Aug 23, 2021

Hi,

First of all I must say SjASMPlus is currently my favorite assembler. It can compile a lot of existing sources and it has even some quite unique features I enjoy... How ever it does not mean that I don't still keep dreaming about new stuff. :)

I've been wondering that it would be really nice, if the macros could have free amount of parameters (I believe this has been requested already) and they could behave differently based on parameter types given...

I did put most of my dreams to this one over complicated pseudo code macro... I know it is a bit tall order, but maybe something to think about:

      MACRO PRINT 1..2 ; (parameter format loaned from Sjasm)

        IF TYPE(@1)==FLAG
          JP NOT(@1),.SKIP
          ROTATE 1 ; from Sjasm (@1=@2)
        ENDIF

        IF TYPE(@1)==STRING
          IF LEN(@1)==1
            LD A,@1
            CALL CHRPUT
          ELSE
            CALL PRINT_PC
            DB @1, 0
          ENDIF
        ENDIF

        IF TYPE(@1)==REGISTER
          IF @1 <> A
            LD A,@1
          ENDIF
          CALL CHRPUT
        ENDIF

        IF TYPE(@1)==REGISTERPAIR
          IF @1 == IX | @1 == IY
            PUSH @1
            POP HL
          ELSE
            IF @1 <> HL
              LD L,@1.LOW
              LD H,@1.HIGH
            ENDIF
          ENDIF
          CALL PRINT_HL
        ENDIF

        IF TYPE(@1)==REGISTERPAIRPOINTER ; () automatically removed
          IF @1 == HL
            LD A,(HL)
            INC HL
            LD H,(HL)
            LD L,A
            CALL PRINT_HL
          ELSE
            LD A,(@1)
            LD L,A
            INC @1
            LD A,(@1)
            LD H,A
            DEC @1
            CALL PRINT_HL
          ENDIF
        ENDIF

        IF TYPE(@1)==POINTER ; () automatically removed
          LD HL,(@1)
          CALL PRINT_HL
        ENDIF

        IF TYPE(@1)==NUMBER
          IF @1 > 255
            LD HL,@1
            CALL PRINT_HL
          ELSE
            IF @1 <> 0
              LD A,@1
            ELSE
              XOR A
            ENDIF
            CALL CHRPUT
          ENDIF
        ENDIF

 .SKIP:
      ENDM

PRINT_PC:
        POP HL
        LD A,(HL)
        INC HL
        PUSH HL
        AND A
        RET Z
        CALL CHRPUT
        JP PRINT_PC

PRINT_HL:
        LD A,(HL)
        INC HL
        AND A
        RET Z
        CALL CHRPUT
        JP PRINT_HL 

@ped7g ped7g changed the title Feature request: Macros and their parameter types. Macro: parameter types and variadic arguments Aug 28, 2024
@ped7g
Copy link
Collaborator

ped7g commented Aug 28, 2024

Some thoughts while cleaning up issues:

types:

I don't think the types make much sense here, the whole macro system in sjasmplus is based on source code processing (as string, before parsing it), but because of that, you get into macro value "as was typed in source", so technically the macro itself could check for your own convention how to distinguish between type.

Right now that means you have to go straight into lua scripting inside macro, as the there are no string operators in the macro language itself, but I can imagine the lua script checking if the value is enclosed in quotes (string type), or does match keyword string (hl,bc,de,..), or evaluate it as expression otherwise to get 16bit value, etc. You can even devise your own way of marking special types in macro values, like adding =X= ahead of the argument value to mark it as your own type "X" and detect such prefix inside lua script.

So I believe you can implement most of this yourself, although the lua script implementing it would be non-trivial, probably worth of some functions library, so I'm curious if it's worth the effort.

variadic arguments:

now this IMHO does make sense even with text preprocessor nature of macros, and I believe it's slightly related also to #103 (as variadic arguments would need similar changes/extensions to code base as macro overloading - with few extras on top of it to handle variadic arguments somehow).

(I have right now no plans to work on enhancement of this scope, but this could hang around with other ideas, just in case somebody ever will start to change sjasmplus a bit more)

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