Best solution for conditional compile?
Oldbitcollector (Jeff)
Posts: 8,091
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
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
Compile conditions are really a must for managing code for different hardware revisions in larger projects and such.
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
There is no optimization of any kind in the SPIN compiler - this is considered to be a feature!
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
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
@ 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.
Writer could then launch the propeller IDE to compile your new file.
Even emacs can do this.
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
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
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
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle