Page 1 of 1

Why is "with" not permitted in a macro?

Posted: Tue Apr 18, 2023 3:29 pm
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

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

Posted: Tue Apr 18, 2023 3:36 pm
by Fred
Internally With is already handled as a macro, that's why it's not allowed.

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

Posted: Tue Apr 18, 2023 4:04 pm
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...

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

Posted: Tue Apr 18, 2023 4:08 pm
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.

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

Posted: Tue Apr 18, 2023 4:34 pm
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.

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

Posted: Tue Apr 18, 2023 6:30 pm
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.

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

Posted: Tue Apr 18, 2023 6:40 pm
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 :)

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

Posted: Tue Apr 18, 2023 7:23 pm
by Tenaja
You can implement single pass macro expansion with recursion for nested macros... Not too tricky, just need to watch what's happening.

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

Posted: Tue Apr 18, 2023 7:46 pm
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()


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

Posted: Tue Apr 18, 2023 7:54 pm
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:

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

Posted: Tue Apr 18, 2023 10:45 pm
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

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

Posted: Tue Apr 18, 2023 10:58 pm
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. :(

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

Posted: Wed Apr 19, 2023 4:31 am
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.

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

Posted: Wed Apr 19, 2023 9:54 am
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