Why is "with" not permitted in a macro?

Everything else that doesn't fall into one of the other PB categories.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Why is "with" not permitted in a macro?

Post by jassing »

Since a macro just replaces the code, and if/endif is allowed, why isn't with/endwith allowed in a macro?

Code: Select all

EnableExplicit

Macro that()
  If b
    With a
      \bite = 1
    EndWith
  EndIf
EndMacro
Structure other
  bite.l
  bot.l
EndStructure

Procedure this()
  Protected b,a.other
  that()
EndProcedure
that should just translate, before compile, to

Code: Select all

EnableExplicit

Structure other
  bite.l
  bot.l
EndStructure

Procedure this()
  Protected b,a.other
  If b
    With a
      \bite = 1
    EndWith
  EndIf
EndProcedure
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why is "with" not permitted in a macro?

Post by Fred »

Internally With is already handled as a macro, that's why it's not allowed.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Why is "with" not permitted in a macro?

Post by jassing »

Fred wrote: Tue Apr 18, 2023 3:36 pm Internally With is already handled as a macro, that's why it's not allowed.
Thanks! I understand how recursive macro's are a problem...
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why is "with" not permitted in a macro?

Post by Fred »

To handle it, the compiler should be changed into a multi-pass one, until it produces a stable output (ie: no more macro expanded) which can dramatically reduce perfs.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Why is "with" not permitted in a macro?

Post by jassing »

Fred wrote: Tue Apr 18, 2023 4:08 pm To handle it, the compiler should be changed into a multi-pass one, until it produces a stable output (ie: no more macro expanded) which can dramatically reduce perfs.
Like I said, I get it, I'd rather not use 'With' than take a multi-pass compiler hit. I was simply curious.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Why is "with" not permitted in a macro?

Post by skywalk »

Is multi-pass compiler being considered for the future?
Is it not worth the small time hit for the added features?
I prefer the C backend compiler despite the delay over ASM.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why is "with" not permitted in a macro?

Post by Fred »

No, it's not planned. Here, I use the asm compiler to dev and the C one to generate the final exe and it works pretty well :)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Why is "with" not permitted in a macro?

Post by Tenaja »

You can implement single pass macro expansion with recursion for nested macros... Not too tricky, just need to watch what's happening.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 385
Joined: Thu Jul 09, 2015 9:07 am

Re: Why is "with" not permitted in a macro?

Post by pf shadoko »

@Fred:
Internally With is already handled as a macro, that's why it's not allowed.
and you have no shame!!!
(the worst is that you admit it in the doc (I just saw it)
I had soupsons for a while

on the one hand, it prevents the use of macro but especially in the case of table, it is not optimized

in the following example, I go almost 2x faster by using a pointer

I warn you, if you don't fix this right away, I'll organize a manifestation against the "with" of PB

Code: Select all

Structure ss
  v.i
EndStructure

Dim a.ss(0,0,0,0)
*pa.ss

OpenConsole()

n=100000000

t=ElapsedMilliseconds()
With a(0,0,0,0)
  For i=0 To n
    \v+1
  Next
EndWith
PrintN("with     : "+Str(ElapsedMilliseconds()-t))

a(0,0,0,0)\v=0
t=ElapsedMilliseconds()
*pa=@a(0,0,0,0)
With *pa
  For i=0 To n
    \v+1
  Next
EndWith
PrintN("pointeur : "+Str(ElapsedMilliseconds()-t))
Input()
CloseConsole()

Last edited by pf shadoko on Tue Apr 18, 2023 7:55 pm, edited 1 time in total.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Why is "with" not permitted in a macro?

Post by Caronte3D »

pf shadoko wrote: Tue Apr 18, 2023 7:46 pm I warn you, if you don't fix this right away, I'll organize a manifestation against the "with" of PB
:lol: :lol:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why is "with" not permitted in a macro?

Post by Fred »

With is a compiler directive to save some typing, it's not a runtime keyword like select, so go in strike it won't change :) :D
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Why is "with" not permitted in a macro?

Post by skywalk »

Haha, I have long deleted With from all my source code.
It complicates my code automation tools when parsing variables.
And I cannot "see" \myVar values during debug hovers. :(
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Why is "with" not permitted in a macro?

Post by jacdelad »

Caronte3D wrote: Tue Apr 18, 2023 7:54 pm
pf shadoko wrote: Tue Apr 18, 2023 7:46 pm I warn you, if you don't fix this right away, I'll organize a manifestation against the "with" of PB
:lol: :lol:
Fred is French, so a strike won't scare him, he is used to that.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 385
Joined: Thu Jul 09, 2015 9:07 am

Re: Why is "with" not permitted in a macro?

Post by pf shadoko »

@skywalk
you have to put the mouse on the structured variable to see the content of these elements (and not on its elements)

@jacdelad
maybe, but I'm french too, he knows that I'm not hesitating ! ^^

I am nevertheless (a little) surprised by Fred's answer, in the case of tables, it is a considerable drop in performance
Post Reply