hopscc wrote:Starting from the endP.S. The title for this thread is weird. This isn't about extending the @help concept. It's about new directives for conditional compilation.
If you reread the earlier posts you'll see its more about using the keyword + line (extended to a block) syntax structure concept to provide conditional compilation (rather than an extension to help per se)
As you say: "...provide conditional compilation." So "Conditional compilation" would be a better title for this thread, rather than naming it after the syntax.
hopscc wrote:This is as opposed to implementing the same C-like preprocessor-ancestry general purpose variable set-unset and test branching structure. The problems issues and pitfalls of this are well known and later languages have all moved away from that concept ( at varying rates..)..
C# and D both support it. Python gets it for free as a purely interpreted language with late binding on almost everything. They just use their own if statement.
Who is moving away from it?
hopscc wrote:Actually this is all based loosely on D ( version2 of the lang rather than the 1.0 ref you linked to - not that theres very much difference/change)
Do you plan on supporting a true static-if then that has access to constants and type info?
hopscc wrote:Now to your points:No OR / or ELSE
thats because theres no explicit 'if' or <condition>.
That's like if I said "that car has no steering wheel" and someone said "that's because we didn't put one in." Btw, D does have "else" for their "ver". Maybe what you really meant was what you said next:
hopscc wrote: This is more oriented around a block (or statement or decl(s)- dont worry about the granularity)
thats triggered from a (fixed) condition tag - Its definitely not directed towards arbitrary complex use as a general purpose branch-with-attendant-conditions setup
Well it's a special, limited case of "branch-with-attendant-conditions setup" with no benefits that I can see:
# one line of overhead:
@ver DEBUG
print 'some debugging code'
# still simple with @if:
@if DEBUG
print 'some debugging code'
But @if could express things that @ver will never be able to express. I consider that a good thing. (And yes I switched from the .defined('FOO') in my last post to simply FOO.)
hopscc wrote:The 'conditional' in conditional compilation here is more to 'match' to a situation
( on a particular platform/backend, match to a user setting or a compiler setting) than a binary test of a boolean expressionenv.var.'value' re other comparisons
there are no other comparisons - it matches or it doesnt.
Well sometimes people want the opposite of match. With no "not" and no @else, you could be stuck.
hopscc wrote:(The number versioning was an afterthought - not sure its necessary or if need comparison to version numbers'
but could be done a similar way with something modifying what a match means
- Code: Select all
env.OSVer.'>=1.0'
as a rough (and poor) example.
It will be necessary eventually when we make an incompatible change to Cobra, but some open source project wants to compile on both versions.
hopscc wrote:This is version as in any conditional compilation makes a different version of the executable.
- version for jvm
- version for mono
- version for windows, ...
So no it doesnt describe the mechanism being tested/used, it describes the goal.
'a version specific to something'
I see. Thanks for the clarification.
hopscc wrote:- I'd say static-if in D was more for the benefit of their version of templating than conditional-compilation in that it tests compile time constants and a condCompile is directed by setups/config outside the codebase (target platform, user spec build defn passed into compiler,...)
It's also your escape hatch when you need OR, AND or a comparison in your version() ... which does not support such things.
hopscc wrote:.. description for reinvention of same-old C-preprocessor-like-ifdef for cobra elided....
I dont believe this is a desirable way to go for the most common cases
(code selection for platform, back-end, Debugging, compiler-setups).
At the very least its overly general purpose and complex for the need desired and subject to the same old problems and abuses...
Cobra deserves something simpler and clearer which tag-match-and-block definitely is.
The common case is quite simple:
@if JVM
<some code>
# and if we want a one liner, we could entertain:
@if JVM, <some code>
hopscc wrote:...alternatively compiler could expose major feature items as condCompile match tags same as doing for platform/backend tags
(hasLambda, hasMethodInference, hasLiteralCollectionTyping...) assuming we can get some agreement of what constitutes a new major feature.
Regarding the back-ends, my observation is that words like "lambda" don't give you enough info. For example, if you jot down the characteristics and rules for C# lambdas and Python lambdas, you get different lists. Otherwise, capability-based flags would be nice.
hopscc wrote:I agree that condCompile directives are not arbitrarily positionable - my impl has them only recognised in 3 places
(at statements, BoxMember decls, NSMember decls) - they're not separate from the tokeniser and recognised as unique parser items.
We agree on something!
hopscc wrote:Also, any implementation needs a lot of tests. I found a couple bugs in Cobra just the other day. I'm trying to resolve this situation and get to 1.0 by emphasizing fixes over new features. Adding new features introduces new bugs. Lots of tests will be required
yeees.. There are tests with this covering all the inflection points as per usual - adding 'lots' probably wont improve coverage appreciably. This is same situation as everywhere else.
I'm not sure of your point here: ...
I'm just wary of adding a new feature when the last new bug I found was yesterday.
However, I realize that this is sorely needed for multi-back-end work.
hopscc wrote:I would get @if working first and add convenience forms conservatively.
Aaah - I'm coming from the opposite position.
The 'convenience' forms (as you describe them) aren't - they are are the most-used core for condCompile (at least as it is now).
Only provide @if-@then-@else more general form for situations where the tag-match-and-block forms are totally unworkable.
(I'm not convinced thats the case or that the general form is advantageous in any form)
What do you mean "only provide"? As soon as you provide @if/@else then it's available in general.
And when used in simple cases, it looks simple. And when you need something more, you use the same @if with a richer condition.
hopscc wrote:re OpSys.
For comparison most of the predefined version Identifiers in D are for specific OPSys implementations ( e.g Solaris vs 'unix')
cobra (currently) only supports 3 families (windows, mac and unix)
Will we (eventually perhaps) also need to become exactly platform/hardware/... specific for these builtins also (systems programming)?
We'll need CLR and JVM version numbers. I doubt Cobra will become popular for systems programming. It seems destined for application programming which is what I originally intended anyway.
hopscc wrote:Using @if/@else if/@else and expressions as a foundation seems fundamentally useful and clear
We're agreed on fundamentally useful (some form of condCompile). Clear - no
tagged-match and block-code is definitely clearer, cleaner and also stands out from cobra exec code (compared to cobra if-else branching).
Then we're still in disagreement. You seem allergic to the #if/#define approach found in C# and other languages, but I'm not. You admit it will be needed in some situations.
But then if that's case, I don't see the need for @ver and @debug.
hopscc wrote:I'll post the patch on the ticket and you can see some condCompiled test code.
I asked some specific questions in my earlier post - those were some directions I was wondering about since I thought I'd already clarified the general approach I was heading with this earlier.
(this is probably enough of a post for now - more later if I come up with anything else).
Same here.
I looked at the patch. But after that and our discussion, I'm still favoring:
@if, @else if, @end, @define, @undefine
cobra -define
And yes, I think your list of setups is a great one to start with. I've added a couple more:
CLR, CLR20, CLR40, JVM, JVM16, JVM17, JVM18, OBJC, DOTNET, MONO, WINDOWS, UNIX, MAC, ASSERTS, TESTS, CONTRACTS, DEBUG, DST, ERT
... or we could go all lower case:
clr, jvm, objc, dotnet, etc.
dst = -detailed-stack-trace
ert = -embed-run-time
Btw the other thing that bugs me about @ver is that it doesn't just check for the existence of the symbol, it also has a matching option. Like it's trying to be a half-baked @if.
With "@if FOO" being so simple and "@ver" not being any simpler, plus trying to be like @if with its matching ability, I don't see any need for it. It's adding another way to do something without any benefit that I can identify.