Hello,
A construct like:
[IFDEF] CONFIG_PPC [IFDEF] CONFIG_PPC64 5 [ELSE] 4 [THEN] [ELSE] [IFDEF] CONFIG_SPARC64 6 [ELSE] 3 [THEN] [THEN]
has been seen to return, e.g., 4 3 according to the debug word.
Is this nesting forbidden in Forth? Easily fixable? A better way to do this? I do want a final catch-all since returning no value would have unexpected results, and we currently do not have a define CONFIG_PPC32 so that a concatenation of independent [IFDEF]...[THEN]s wouldn't work.
TIA,
Andreas
Andreas Färber wrote:
Hello,
A construct like:
[IFDEF] CONFIG_PPC [IFDEF] CONFIG_PPC64 5 [ELSE] 4 [THEN] [ELSE] [IFDEF] CONFIG_SPARC64 6 [ELSE] 3 [THEN] [THEN]
has been seen to return, e.g., 4 3 according to the debug word.
Is this nesting forbidden in Forth? Easily fixable? A better way to do this? I do want a final catch-all since returning no value would have unexpected results, and we currently do not have a define CONFIG_PPC32 so that a concatenation of independent [IFDEF]...[THEN]s wouldn't work.
IIRC [IFDEF] [ELSE] and [THEN] are simply Forth words that swallow the input unless the condition is met.
I suspect it will be similar to the bbranch & friends Fcode instructions whereby at compile time the current nested state is held on the dstack.
HTH,
Mark.
Am 02.12.2010 um 12:25 schrieb Mark Cave-Ayland:
Andreas Färber wrote:
Hello, A construct like: [IFDEF] CONFIG_PPC [IFDEF] CONFIG_PPC64 5 [ELSE] 4 [THEN] [ELSE] [IFDEF] CONFIG_SPARC64 6 [ELSE] 3 [THEN] [THEN] has been seen to return, e.g., 4 3 according to the debug word. Is this nesting forbidden in Forth? Easily fixable? A better way to do this? I do want a final catch-all since returning no value would have unexpected results, and we currently do not have a define CONFIG_PPC32 so that a concatenation of independent [IFDEF]... [THEN]s wouldn't work.
IIRC [IFDEF] [ELSE] and [THEN] are simply Forth words that swallow the input unless the condition is met.
I suspect it will be similar to the bbranch & friends Fcode instructions whereby at compile time the current nested state is held on the dstack.
I don't really understand the code in forth/lib/preprocessor.fs but it looks as if some state is held in three variables. Also the [ELSE] case handling in the [IF] loop looks unintuitive...
http://repo.or.cz/w/openbios/afaerber.git/blob/HEAD:/forth/lib/preprocessor....
Andreas
I don't really understand the code in forth/lib/preprocessor.fs but it looks as if some state is held in three variables. Also the [ELSE] case handling in the [IF] loop looks unintuitive...
It looks like a bastardised version of the example code in the standard. It only handles nested [IF] , not [IFDEF] etc. It wouldn't be hard to add it (just add and extra case, where it does a string compare for [IF] ).
Segher
I don't really understand the code in forth/lib/preprocessor.fs but it looks as if some state is held in three variables. Also the [ELSE] case handling in the [IF] loop looks unintuitive...
It looks like a bastardised version of the example code in the standard. It only handles nested [IF] , not [IFDEF] etc. It wouldn't be hard to add it (just add and extra case, where it does a string compare for [IF] ).
Or, write it as
[DEFINED] bla [IF] [DEFINED] blub [IF] ... [ELSE]
etc.
Segher
Am 04.12.2010 um 03:16 schrieb Segher Boessenkool:
I don't really understand the code in forth/lib/preprocessor.fs but it looks as if some state is held in three variables. Also the [ELSE] case handling in the [IF] loop looks unintuitive...
It looks like a bastardised version of the example code in the standard. It only handles nested [IF] , not [IFDEF] etc. It wouldn't be hard to add it (just add and extra case, where it does a string compare for [IF] ).
Thanks for the hint, working nicely now!
Andreas