Beebasm macro scoping

handy tools that can assist in the development of new software
Post Reply
User avatar
hjalfi
Posts: 175
Joined: Sat May 13, 2017 11:17 pm
Location: Zürich, Switzelrand
Contact:

Beebasm macro scoping

Post by hjalfi »

Is there any way to make Beebasm macros without having them create an automatic scope? I want to do something like this:

Code: Select all

macro startthing
    {
endmacro

macro endthing
    }
endmacro
(simplified example, of course. I'm intending to do something more complex than this, honest.)
David Given
http://cowlark.com
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Beebasm macro scoping

Post by Rich Talbot-Watkins »

Not unless something has changed recently. BeebAsm macros are really better described as functions - they are instanced with a fake scope so that the parameter symbols disappear on exit.
User avatar
hjalfi
Posts: 175
Joined: Sat May 13, 2017 11:17 pm
Location: Zürich, Switzelrand
Contact:

Re: Beebasm macro scoping

Post by hjalfi »

I'm just wondering if there's a way to suppress that scope creation, to make them work like (conventional!) text substitution macros.
David Given
http://cowlark.com
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Beebasm macro scoping

Post by Rich Talbot-Watkins »

The way that BeebAsm works internally means that when you call

MACRO BLAH var1, var2

like this:

BLAH 1, 2

it really just creates a new scope, assigns var1 and var2 to the passed parameters, and then instances the macro body:

{
var1=1
var2=2
; rest of macro
}

So the scope is kind of an important part of how parameters are assigned. I know this is not like the more regular text substitution which most assemblers perform, but it was what seemed easiest and most useful to me when I knocked this together all those years ago.

From distant memory, it might just be possible to allow a new scope to be opened (but not closed) inside a macro, with no bad side-effects. It just seemed like ill-defined behaviour at the time which I made a point of checking for, and prohibiting!
User avatar
TobyLobster
Posts: 622
Joined: Sat Aug 31, 2019 7:58 am
Contact:

Re: Beebasm macro scoping

Post by TobyLobster »

hjalfi wrote: Mon Oct 09, 2023 12:47 pm I'm just wondering if there's a way to suppress that scope creation, to make them work like (conventional!) text substitution macros.
Alternatively, If you have some coding ability it should be possible to write a preprocessor that handles text substitution, whose output is then fed into beebasm.
User avatar
hjalfi
Posts: 175
Joined: Sat May 13, 2017 11:17 pm
Location: Zürich, Switzelrand
Contact:

Re: Beebasm macro scoping

Post by hjalfi »

I've looked at using a preprocessor, but unfortunately beebasm doesn't seem to have a way to set the current file and line number (equivalent to C's

Code: Select all

# "filename" 1234
directives), which means that error messages are always reported at the wrong place.
David Given
http://cowlark.com
User avatar
tricky
Posts: 7712
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Beebasm macro scoping

Post by tricky »

You should be able to sneak, or sledgehammer a label out of a macro with .*label but without the text concatenation from the other thread it probably won't help.
If you made your macros a single line, the CPP should work ok shouldn't it?
User avatar
TobyLobster
Posts: 622
Joined: Sat Aug 31, 2019 7:58 am
Contact:

Re: Beebasm macro scoping

Post by TobyLobster »

hjalfi wrote: Mon Oct 09, 2023 2:42 pm I've looked at using a preprocessor, but unfortunately beebasm doesn't seem to have a way to set the current file and line number (equivalent to C's

Code: Select all

# "filename" 1234
directives), which means that error messages are always reported at the wrong place.
Sounds like a useful future feature for Beebasm...?
Post Reply

Return to “development tools”