It is currently Sun Mar 07, 2021 11:11 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Expanded View of Macros
PostPosted: Thu Nov 14, 2013 9:34 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
TI-994A wrote:
To reiterate, if anyone knows of a way, or has some utility that could expand PureBasic macros within the source listing, please do share.


PB macros don't always expand the way one would expect. The PB macro processor has some interesting "features", so it's likely that no one has made the effort to write the kind of program you're looking for. Of course, you could write your own, but it seems like a lot of effort for very little return.

Other than doing what luis and I have suggested, your best bet might be to wait for Fred to update the compiler.

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Thu Nov 14, 2013 11:40 am 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy
BorisTheOld wrote:
Actually, it's PB's macro feature which is antiquated. It's close to being non-existant.


I agree, it's very 'basic'. A stronger macro language or the ability to have some kind of template coding would be very nice.

BorisTheOld wrote:
your best bet might be to wait for Fred to update the compiler


viewtopic.php?p=312230#p312230

Let's hope. After all PB does all the work already, it should just need to collect the pieces and spit out a file.

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Thu Nov 14, 2013 1:43 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2443
Location: Singapore
BorisTheOld wrote:
Actually, it's PB's macro feature which is antiquated. ...
BorisTheOld wrote:
PB macros don't always expand the way one would expect. The PB macro processor has some interesting "features"...
Hi BorisTheOld. I don't know enough about the inner workings of PureBasic's macro system to comment on you earlier remark, but what do you mean when you say the way one would expect? :?

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Sat Nov 16, 2013 5:09 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
TI-994A wrote:
Hi BorisTheOld. I don't know enough about the inner workings of PureBasic's macro system to comment on you earlier remark, but what do you mean when you say the way one would expect? :?


I don't know anything about PB's macro processor. :) Two weeks ago I reported what looks like a bug in the macro processor, but Fred said it's not, and moved me to Feature Requests.

Here's the problem I reported. The first block of code works, but the second block fails.

The "Field" statement expands as follows: Field(x, typInt32) --> x.typInt32 --> x.i

Code:
Macro typInt32
  i
EndMacro

Macro Field (DataName, DataType)
  DataName.DataType
EndMacro

Field(x, typInt32)   ; x.i


With this next block of code, the compiler complains about a missing structure named, "typInt32".

The "Field" statement expands as follows: Field(x, typInt32) --> x.typInt32 , then stops

This time the "typInt32" is not recognized as a macro, but in the first block of code the compiler appeared to continue scanning the text to resolve the "typInt32" macro. Obviously, under certain conditions, something is going on in the macro processor to terminate parsing before all possible macro references have been resolved.

Code:
Macro typInt32
  i
EndMacro

Macro Field (DataName, DataType)
  DataName.typ#DataType
EndMacro

Field(x, Int32)   ; structure not found: typint32


All other macro processors I've worked with keep parsing the text until all macro references have been resolved. PB seems to be working only with the parameters, then dropping the expanded text into the macro body as a final step. This unusual behaviour severely limits what can be done with PB macros, and makes it difficult to write utility programs to expand macros the way PB does.

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Sat Nov 16, 2013 4:53 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2443
Location: Singapore
BorisTheOld wrote:
The "Field" statement expands as follows: Field(x, typInt32) --> x.typInt32 , then stops...
Code:
Macro typInt32
  i
EndMacro

Macro Field (DataName, DataType)
  DataName.typ#DataType
EndMacro

Field(x, Int32)   ; structure not found: typint32

Hello BorisTheOld. That's because concatenation in macros will only work with labels and keywords, and not data types.
The PureBasic Manual (Macros) wrote:
The special concatenation character '#' can be used to create new labels or keyword...

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Sat Nov 16, 2013 10:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
TI-994A wrote:
Hello BorisTheOld. That's because concatenation in macros will only work with labels and keywords, and not data types.
The PureBasic Manual (Macros) wrote:
The special concatenation character '#' can be used to create new labels or keyword...


The "#" can be used to create data types, I do it all the time. In the following example, "QQBlock" is a dynamically created macro that specifies the class name. So I don't see "labels or keyword" as excluding data types.

Code:
Macro BeginClassData
  Structure str#QQBlock
EndMacro


Also, the help file also says:

Quote:
When a macro has some parameters, they are replaced in the macro code by the literal expression which is passed to the called macro. No evaluation is done as this stage, which is very important to understand: the evaluation of a line is started once all the macros found on this line are expanded.


This would imply that both my examples should work, not just the first. And that's why I say the behaviour is strange, since PB does not always seek out all macros before it compiles the code. But Fred says this behaviour is by design, so I just work around it.

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Sun Nov 17, 2013 3:14 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2443
Location: Singapore
BorisTheOld wrote:
The "#" can be used to create data types, I do it all the time. In the following example, "QQBlock" is a dynamically created macro that specifies the class name. So I don't see "labels or keyword" as excluding data types.
Code:
Macro BeginClassData
  Structure str#QQBlock
EndMacro
Hello again. In the example above, the concatenation str#QQBlock is for a structure, and not a native data type. Rather than debating the ambiguity of the PureBasic manual, bottom line is, have you been able to define a native data type through the use of a concatenated macro?

Or perhaps, could it be that the macro names themselves could not be called by such concatenations?

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Expanded View of Macros
PostPosted: Sun Nov 17, 2013 5:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
TI-994A wrote:
Rather than debating the ambiguity of the PureBasic manual, bottom line is, have you been able to define a native data type through the use of a concatenated macro?


Only by sleight of hand. :)

Since the anomalous behaviour is hard coded into the macro processor, the only way around the problem is to fake it.

So, although this doesn't work:

Code:
Macro typInt32
  i
EndMacro

Macro Field (DataName, DataType)
  DataName.typ#DataType
EndMacro

Field(x, Int32)   ; structure not found: typint32


This does:

Code:
Macro typInt32
  i
EndMacro

Macro FieldTyp (DataName, DataType)
  DataName.DataType
EndMacro

Macro Field (DataName, DataType)
  FieldTyp (DataName, typ#DataType)
EndMacro

Field(x, Int32) ; x.i


This allows me to dynamically combine text, such as "Int32", with other text so as to reference specific macros, such as "typInt32". It's not the most elegant solution, but it allows me to do what I want. Luckily, there are only a few macros where I have to use this technique.

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye