Shop OBEX P1 Docs P2 Docs Learn Events
Using GNU CPP with SPIN — Parallax Forums

Using GNU CPP with SPIN

jazzedjazzed Posts: 11,803
edited 2010-12-08 15:52 in Propeller 1
GNU cpp is a powerful variant of the C pre-processor. The cpp program can be used with SPIN to generate custom SPIN files that can be compiled with any tool such as Propeller Tool, Propellent, Homespun, and BST/BSTC. Homespun and BST/BSTC have built-in pre-processor ability and should be considered by those who are not held hostage by some notion of maintaining Parallax purity.

Today Homespun supports common pre-processor items such as #define, #define SYMBOL VALUE, #ifdef (but not #ifndef), #ifdef, #elseifdef (but not #elseif), #endif, and #include.

BST/BSTC supports common pre-processor items such as simple #define, #ifdef, #ifndef, #ifdef, #elseifdef (but not #elseif), and #endif. The #include tag is not supported.

Propeller Tool and Propellent does not support any pre-processor syntax at all. Using cpp can help this. There was also another tool that provides some independent pre-processor support, but I can't find it and as I remember, it did not have a good feature set.

Getting CPP

The easiest way to get GNU cpp (and the iconv utility for converting Parallax font spin files to utf8 text) is to install cygwin on your system. Installing MinGW is another option. Generally, one should not install cygwin and MinGW on the same computer.

Cygwin is a unix like environment for Windows computers. Many useful dev tools are available with Cygwin. Go to www.cygwin.com and read about this option.

MinGW is a windows environment that includes GNU tools. It will take as much effort to install MinGW as Cygwin. Go to www.mingw.com to read about this option. MinGW software is downloaded from sourceforge.net/projects/mingw via the mingw-get-inst package.

I don't have time to give detailed instructions for all of this.

Using CPP

Once you have the tools (or patience to get this far), use cpp with SPIN by the command:

cpp -p --traditional-cpp spinfile.spin

If your spinfile has Parallax font, use iconv to make spinfile.spin usable with the command:

iconv -futf16 -tutf8 spinfile.spin > utf8_spinfile.spin

The documentation for GNU CPP is found here: http://gcc.gnu.org/onlinedocs/cpp

GNU CPP is powerful because of support for many options. The most common items mentioned above for Homespun and BST/BSTC are supported by GNU CPP, but there is so much more. It's best to focus on using the common items if possible.


Searching for simpler solutions?

Catalina has a cpp.exe, but it does not provide a way to suppress "#line" messages.
Catalina install is much faster than Cygwin or MinGW.

The source for a version of cpp used in Catalina is here: https://github.com/drh/lcc/tree/master/cpp
The adventurous could probably make a stand-alone windows application with this to save lots of pain. I would do it, but don't have time just now.

Linux offers the simplest solution of all. Just install the program :D

Comments

  • kuismakuisma Posts: 134
    edited 2010-12-08 13:00
    The C preprocessor is intended to be used only with C, C++, and Objective-C source code. In the past, it has been abused as a general text processor. It will choke on input which does not obey C's lexical rules. For example, apostrophes will be interpreted as the beginning of character constants, and cause errors. Also, you cannot rely on it preserving characteristics of the input which are not significant to C-family languages.
    [...]
    Wherever possible, you should use a preprocessor geared to the language you are writing in.
    [...]
    If all else fails, try a true general text processor, such as GNU M4.

    http://gcc.gnu.org/onlinedocs/cpp/Overview.html#Overview
  • LeonLeon Posts: 7,620
    edited 2010-12-08 13:34
    m4 is very good, I use it as a general macro-processor.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-12-08 13:52
    Do any of these tools support macros?
  • LeonLeon Posts: 7,620
    edited 2010-12-08 14:46
    m4 is a very powerful macro-processor! The other tools have a limited macro capability, it isn't very useful.
  • jazzedjazzed Posts: 11,803
    edited 2010-12-08 15:52
    Since we're not afraid of new syntax around here (Spin anyone?), I guess m4 is worth a look.

    I'm very happy with cpp using the "-p --traditional" flags. You can't please everyone though. Of course some folks don't really want to be pleased in the first place. It's easy to come up with excuses, solutions take effort. Since we have the source to cpp ala lcc, there is no risk in making that fit our needs if it can be built.

    Cluso99, #define SYMBOL with cpp is a macro for string replacement. In the case of #define SYMBOL, the string is nothing. "#define PMOV(d,s) mov d, s" should of course look familiar.

    I'm sure m4 can do more.

    Leon you should provide some interesting m4 examples for us since you are keen on the solution.
Sign In or Register to comment.