Shop OBEX P1 Docs P2 Docs Learn Events
Best solution for conditional compile? — Parallax Forums

Best solution for conditional compile?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-11-25 19:22 in Propeller 1
I've seen various minor discussions on conditional compile.

Has anyone come up with a "best practice" for conditional compile statements
within their programs besides creating huge {remarked items?}

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just getting started with Propeller?

Propeller Cookbook

PropDOS

Comments

  • J.A.B.J.A.B. Posts: 13
    edited 2007-11-25 13:01
    I'm looking for this also.
    Compile conditions are really a must for managing code for different hardware revisions in larger projects and such.
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-11-25 13:28
    It depends on how clever the compiler is.

    Some compilers (all that do have an optimizer) just dump code like this:

    if <ConstantExpression> == false

    You could find that out by comparing the size of the generated code just by changing ConstantExpression == true and ConstantExpression == false. If the codesize stays the same, that trick doesn't work.

    Wouldn't be too complicated to implement, but of course requires having the source of the compiler.
    Anyhow, a set of #ifdefs and the like would be very handy.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-25 13:40
    LOL
    There is no optimization of any kind in the SPIN compiler - this is considered to be a feature!
  • JoJo Posts: 55
    edited 2007-11-25 14:40
    If the folks at Parallax are listening: please, give us conditional compilation!!!
    SPIN is an interesting language, but let us not forget all that has been learned about programming
    languages since the early days of raw assembler wink.gif
    Personally I'd like something C-like:

    #if expr
    #endif

    #ifdef symbol
    #endif

    #ifndef symbol
    #endif

    where "expr" and "symbol" are all (of course) compile time constants.
    Using c preprocessor syntax should make it very easy to incorporate one of the many existing cpp programs onto the SPIN compiler.

    PS: And since we're talking about enhancements, how about that innovation: the datastructure!!! I miss them so ...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    Jo
  • hippyhippy Posts: 1,981
    edited 2007-11-25 15:47
    I agree; conditional compilation is an extremely useful tool and many people have requested it but pleas for that seem to have fallen on deaf ears. I know Parallax have more to do than just support the Propeller Tool but it is a major omission most programmers expect to have.

    @ OBC : "Best Practice" - I don't think there is any beyond using {..}

    I tried using an external pre-processor but one ends up debugging and altering just one version of the code and changes then have to be folded back into the original source. I tried SCCuM ( and there's nothing wrong with it per se ) but just found that too clunky and ultimately confusing in practice The only real solution is conditional compilation built into the Propeller Tool itself, otherwise it's a maintenance nightmare.

    I have some code which runs in one cog but I want it configurable to optionally have that code split between multiple cogs. Unless I start maintaining two or more near identical source codes there's no easy way to do that. From the number of requests for conditional compilation I presume other people are in similar situations.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-11-25 16:09
    Since spin files are not complicated, why not use a program like OpenOffice's Writer to conditionally write the spin file you need?

    Writer could then launch the propeller IDE to compile your new file.

    Even emacs can do this.
  • SapiehaSapieha Posts: 2,964
    edited 2007-11-25 16:21
    Hi hippy.

    It is not onle processor but processor+Tools to characterize good product.
    So popple in Parallax do have only good Processor but ugly Tools.
    And this not characterize good product.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • AribaAriba Posts: 2,685
    edited 2007-11-25 17:08
    I use my PreSpin Preprocessor for all my projects that must be configurable.
    PreSpin is a little addition to the IDE with many useful functions, not only a Preprocessor. It behave like it is integrated in the IDE. See this thread for more infos:
    http://forums.parallax.com/showthread.php?p=655470

    The only problem that I have with this solution is that Compiler-Errors are shown in the preprocessed version of the source, and I always forget to switch to the original version to edit the code. But in this case you can copy and paste the edited parts to the right place.

    Andy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-25 19:08
    As a priority, I'd be much more in favor of integrated hooks to one's own preprocessor than to any further changes in Spin itself. There's a lot of talent out in the field, as Ariba and others have so ably demonstrated. Parallax would be leaps ahead by making it easy for third parties to incorporate their own features into Spin, rather than enduring the endless drone of requests for changes and additions to the language. To some extent, any reluctance to do so may stem from fear the developers harbor about supporting a more flexible platform. But I think it's time to acknowledge that they can't do everything and that the user community has good ideas for extending the language and should be empowered to run with them.

    At a minimum, the preprocessor hooks should accommodate a mapping from the generated code back to the original program, so errors can be flagged and corrected there. This would avoid the problems that Ariba refers to. Such a mapping can be effected by a callback to the preprocessor with line and column information, along with an error code, that the preprocessor could replace with the source line (and column) that generated the erroneous code, along with its own error message. This information would then be passed up to the editor for highlighting.

    Perhaps something like this is already in the works. I hope so.

    -Phil
  • LeonLeon Posts: 7,620
    edited 2007-11-25 19:22
    I'd use a macro processor like m4 to pre-process the code. SNOBOL would be even better but not many people use it these days.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
Sign In or Register to comment.