It is currently Wed Feb 26, 2020 8:31 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 2:14 pm 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3361
Code:
Macro TEST_MACRO
  ModuleName
EndMacro

DeclareModule TEST_MACRO
  a.s="Hello!"
EndDeclareModule

;/ [Error] Module Not found: TEST_MACRO.
Debug TEST_MACRO::a.s


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 2:26 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 471
Location: Germany, Saarbrücken
Interestingly it works with UseModule :D
Code:
EnableExplicit
Macro TEST_MACRO
  ModuleName
EndMacro

DeclareModule TEST_MACRO
  a.s="Hello!"
EndDeclareModule
Module TEST_MACRO
EndModule

UseModule TEST_MACRO

Debug a

But of course it is still a bug.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 2:45 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1205
Location: right here
the DeclareModule gets resolved. if you add spaces around :: then at the Debug it get resolved too and then complains about missing Module/Endmodule. if you add those it will output 0, and if you remove the '.s' from a at the Debug you get a syntax error again.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 2:47 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1074
Location: Russia
This is not a bug.
Code:
Macro MessageRequester(x, y, f=0)
  Debug "Macro "+y
EndMacro

MessageRequester("", "1234")

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 2:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 471
Location: Germany, Saarbrücken
@#NULL
This
Code:
Macro TEST_MACRO
  ModuleName
EndMacro

DeclareModule TEST_MACRO
  a.s="Hello!"
EndDeclareModule
Module TEST_MACRO
EndModule

Debug TEST_MACRO ::a.s

only works because of the lack of EnableExplicit. It compiles to this code
Code:
Debug ModuleName
a.s

which outputs the value of a non initialized variable 'ModuleName' and then defines a new variable 'a.s'.

@User_Russian:
What's the point of your code?

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 3:19 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1205
Location: right here
ah, ok.
i also remembered it wrong that spaces before :: are valid, only space after it are valid. at least the compiler handles those.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 4:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 471
Location: Germany, Saarbrücken
The only way one can realise that at the moment would be this one:
Code:
Macro TEST_MACRO_DECL
   ModuleName
EndMacro

Macro TEST_MACRO(a)
   TEST_MACRO_DECL#::a
EndMacro

DeclareModule TEST_MACRO_DECL
  a.s="Hello!"
EndDeclareModule
Module TEST_MACRO_DECL
EndModule

Debug TEST_MACRO(a)

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 7:01 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1074
Location: Russia
NicTheQuick wrote:
What's the point of your code?
Macros have the highest priority, because the preprocessor deploys them before compilation. In this way, can override the functions of PB (as in my example). With name of the module is the same.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Fri Jul 13, 2018 7:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 491
This works with 5.62 (64 Bit):
Code:
DeclareModule Macros
   Macro TEST_MODULE
      ModuleName
   EndMacro
EndDeclareModule
Module Macros
EndModule

DeclareModule Macros::TEST_MODULE
   a.s = "HELLO"
EndDeclareModule
Module Macros::TEST_MODULE
EndModule

Debug Macros::TEST_MODULE::a

_________________
Windows 10 / Windows 7
PB Last Final / Last Beta Testing


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Tue Oct 01, 2019 3:31 am 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3361
This is still a problem.

We can use macros for structures:

Code:
Structure Triangle2i
EndStructure

Macro SHAPE
Triangle2i
EndMacro

Define triangle.SHAPE


But we can't for modules:

Code:
DeclareModule Shape2i
  Interface ITriangle
  EndInterface
EndDeclareModule

Module Shape2i
EndModule

Macro SHAPE
Shape2i
EndMacro

Define triangle.SHAPE::ITriangle


This results in the following error:

Quote:
Module not found: SHAPE.


Last edited by Mistrel on Tue Oct 01, 2019 9:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Tue Oct 01, 2019 6:44 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 995
@Mistrel

Please, can you stop rewarming your old threads and especially your threads in the 'Bug Reports' over and over again?

Maybe you haven't figured it out yet, but you're not the only one here in the forum and not the only one who posted something here in 'Bug Reports'. If everyone here keeps warming up their bug reports, then we don't need to do anything else than read the 'Bug Reports' here.

PLEASE GET IT STRAIGHT, YOUR PROBLEMS AND WISHES ARE NOT MORE IMPORTANT THAN THOSE OF OTHERS !!!

Slowly I'm wondering what's wrong with you. Open one topic after the other to the same problem and don't even try to deal with the answers to your question. Maybe you should try programming it correctly and don't constantly try to find solutions for an obscure programming style.

I wonder, what are you actually doing here at PureBasic. In the past you have so often noticed that PureBasic is not suitable for your distinctive programming style and you have already found a more suitable programming language. So why don't you get out of this forum and torture the people in the forum of the programming language that's right for you?

Three quarters of a year we had rest from you and since five days it's starting again that you spam the forum completely. Maybe the moderators should consider kicking this spamer out of the forum.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Tue Oct 01, 2019 7:54 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1205
Location: right here
Mistrel wrote:
We can use macros for structures:

Should probably be
Code:
Define triangle.SHAPE

Quote:
But we can't for modules:

The analogue would be
Code:
Macro SHAPE
  Shape2i::ITriangle
EndMacro

Define triangleB.SHAPE

The problem is that PB somehow needs to decide what it resolves first, modules-scopes or macros. Since macros can be scoped in a module and used as module::macro it wants to resolve modules first and then macros when they are at the same expression level, at least that's what I see here.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Tue Oct 01, 2019 5:24 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3764
Location: Berlin, Germany
#NULL wrote:
The problem is that PB somehow needs to decide what it resolves first, modules-scopes or macro.

I think macros that are in the global scope (i.e. not inside of any module) should always be resolved. But for macros that are inside of a module, the respective module scope must be resolved first.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Tue Oct 01, 2019 10:12 pm 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3361
Code:
Define triangle.SHAPE::ITriangle


The SHAPE macro should still be pulled from the global scope as it's on the left side of the module scope resolution operator.


Top
 Profile  
Reply with quote  
 Post subject: Re: Can't use macros for module names
PostPosted: Wed Oct 02, 2019 4:52 am 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3361
Here is a demonstration of how I'm trying to use a macro in this instance. We don't have templates or generics in PureBasic so I'm using macros to choose a module-defined type.

For example, I may want to use an integer variant triangle somewhere and a float elsewhere that needs additional precision. Of course, this only covers 2D triangles. I may also want 3D in the future.

Code:
;-- Triangle (2d, long integer)
DeclareModule Triangle2i
  Structure Struct
  EndStructure
 
  Declare new()
EndDeclareModule

Module Triangle2i
  Procedure new()
  EndProcedure
EndModule

;-- Triangle (2d, float)
DeclareModule Triangle2f
  Structure Struct
  EndStructure
 
  Declare new()
EndDeclareModule

Module Triangle2f
  Procedure new()
  EndProcedure
EndModule

;--

Macro TRIANGLE
Triangle2i
EndMacro

Define t.TRIANGLE::Struct

t=TRIANGLE::new()


This goes a step further where I may have procedures for drawing and manipulating lots of different shapes other than triangles such as rectangles, pentagons, hexagons, etc. For this I need a generic way to deal with shapes.

I could have a module which contains "shapes" inheriting from a base "polygon" that I can draw:

Code:
Procedure drawPolyLine(*shape.SHAPE2::Polygon)
  Protected i
  Protected nextPoint
 
  For i=0 To 2
    nextPoint=i+1
    If i=2
      nextPoint=0
    EndIf
   
    LineXY(*shape\point[i]\x, *shape\point[i]\y,
      *shape\point[nextPoint]\x, *shape\point[nextPoint]\y)
  Next i
EndProcedure


Another, much more complex example in pseudocode (note that this will not compile):

Code:
;-- Geometry

DeclareModule Geometry
  Structure Point2i
    x.l
    y.l
  EndStructure
 
  Structure Point2f
    x.f
    y.f
  EndStructure
EndDeclareModule

;-- Triangle

DeclareModule Triangle2i
  Structure Triangle2i
    point.Geometry::Point2i[3]
  EndStructure
 
  Interface IClass
    fromPointXY(x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  EndInterface
 
  Interface IObject
  EndInterface
 
  Global Class
EndDeclareModule

DeclareModule Triangle2f
  Structure Triangle2f
    point.Geometry::Point2f[3]
  EndStructure
 
  Interface IClass
    fromPointXY(x1.f, y1.f, x2.f, y2.f, x3.f, y3.f)
  EndInterface
 
  Interface IObject
  EndInterface
 
  Global Class
EndDeclareModule

;-- Shape

DeclareModule Shape2i
  Interface ITriangle Extends Triangle2i::IObject
  EndInterface
 
  Global Triangle.Triangle2i::IClass=Triangle2i::class
EndDeclareModule

DeclareModule Shape2f
  Interface ITriangle Extends Triangle2f::IObject
  EndInterface
 
  Global Triangle.Triangle2f::IClass=Triangle2f::class
EndDeclareModule

;--

Macro SHAPE
Shape2i
EndMacro

Define triangle.SHAPE::ITriangle

triangle=SHAPE::Triangle\fromPointXY(50,2, 98,86, 2,86)


At some point I have to create a macro for this unless I want to hard-code the type of shape everywhere in my code. Modules cannot be defined within other modules so I'm exposing the type of triangle within the Shape module behind the variable "Triangle" with an interface ITrangle. For any of these interfaces, I only care about the shape (triangle, rectangle, etc); the parent shape module "Shape2i" defines the primitive type being used, 2d long/integer in this case. Once I've chosen the module, I no longer want to deal with the type-specific shape such as Triangle2i but instead just "Triangle".

Shape2i will only have 2i-types. So instead of Shape2i::Triangle2i\new() it's just Shape2i::Triangle\new(). The macro SHAPE is meant to hide the shape's typed module name as I only want to declare it once whenever I need it in scope so that I can use it like SHAPE::Triangle\new(). At this point all of the type information is hidden and I only have to know that SHAPE is available which, no matter the type, has a fixed set of interfaces which are always identical.


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

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