restrictions on macro usage?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

restrictions on macro usage?

Post by Jerry Messina » Wed Aug 07, 2013 2:16 pm

I was trying to come up with a way of displaying various messages in the IDE Results window,
and wanted to be able to turn them on and off so they don't clutter up the window if not desired.

This is what I came up with -

file: idemsg.bas

Code: Select all

//
//---------------------------------------------------------------------------
//  this module is used to display messages to the compiler Results window
//  it uses macros and the 'checkparam' display feature to show the message 
//  note: since macros can't be nested, these can't be used inside another macro
//
//  set '#option SHOW_IDE_MSG = false' to disable the message display
//---------------------------------------------------------------------------
//
module IDEmsg

// enable messages to the IDE results window
// setting the option false will disable all messages (except errors)
#option SHOW_IDE_MSG = true

public const
    etError              = 0,
    etWarning            = 1,
    etMessage            = 2,
    etHint               = 3

// display [Message] to results window
public macro IDE_MSG(s)
  #if (SHOW_IDE_MSG)            // msgs are enabled...
    checkparam(etMessage, s)
  #endif  
end macro

// display any type [Message, Hint, Warning, Error] to results windows
public macro IDE_MSG(et, s)
  if (et = etError) then            // always display error msgs
      checkparam(etError, s)
  else
    #if (SHOW_IDE_MSG)              // msgs are enabled...
      if (et > etHint) then         // invalid etXXXX type...
          checkparam(etWarning, s)  // show it with a warning
      else                          // else show given msg type
          checkparam(et, s)         
      endif
    #endif  
  endif
end macro

// examples
'IDE_MSG("this is a msg")
'IDE_MSG(etMessage, "this is also a msg")
'IDE_MSG(etWarning, "this is a warning")
'IDE_MSG(etHint, "this is a hint")
'IDE_MSG(etError, "this is a fatal error")

end module
It seemed to work fine until I actually went to use them in some code. It appears the compiler won't allow
certain statements after the macros. This is what I used to test the above

file: main.bas

Code: Select all

device = 18F4620
clock = 10

// you can set 'SHOW_IDE_MSG = false' to disable ide results window messages
// they are enabled by default in idemsg.bas
'#option SHOW_IDE_MSG = false
include "idemsg.bas"

// enable fatal error msg test (stops compiler if set true)
#option ENABLE_etERROR = false

IDE_MSG("generic message")
IDE_MSG(etMessage, "this is a message")
IDE_MSG(etWarning, "this is a warning")
IDE_MSG(etHint, "this is a hint")
IDE_MSG(10, "this is an unknown 'etXXX' type (should show as a warning)")

// test a condition compile message
#option CONDITIONAL_COMPILE = true
#if (CONDITIONAL_COMPILE)
  IDE_MSG("this is a conditional msg")
#endif

// test fatal error message generation
#if (ENABLE_etERROR)
  IDE_MSG(etError, "this is a fatal error")
#endif

// uncommenting any of these will generate a 'Symbol not expected' error
// it's fine if they're located BEFORE any of the IDE_MSG statements
// regular executable statements seem ok (ie ' sub1(), b = 1, etc')

'dim b as byte

'config wdt = on

{
sub sub1()
    dim b as byte
    b = 1
end sub
}

// these are ok (assuming you declare them before the IDE_MSG statements)
'b = 1
'sub1()
Am I out of luck here?

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Wed Aug 07, 2013 3:44 pm

I'm afraid so. The macros in Swordfish are pretty basic (as you know). Keep it simple...

Post Reply