Compile Problem? 2 Variables at same location?!???
I have code, and it seems as though 2 variables are at the same location!
In my code, I have the following declared:
VAR
··· Byte ACTIVATE, MODE,BUFFER[noparse][[/noparse]32], LOCK··
in my code, I am using the TV Terminal to output the variable locations:
··········· TV.HEX(@LOCK, 8)
··········· TV.OUT(13)·
Because of other long variables, the address of "Lock" was 29B6.
I ran this code again with "@BUFFER[noparse][[/noparse]32]" and the address was 29BA.
Here are the following Variables I checked, and their addresses:
·29B5··· Buffer[noparse][[/noparse]27]
·29B6····LOCK······ ···· !!!
·29B6··· Buffer[noparse][[/noparse]28]····· !!!
·29B7··· Buffer[noparse][[/noparse]29]
·29B8··· Buffer[noparse][[/noparse]30]
·29B9··· Buffer[noparse][[/noparse]31]
·29BA··· Buffer[noparse][[/noparse]32]
I thought something was funny, and started going through the Array, and Low and Behold, BUFFER[noparse][[/noparse]28] is showing the same location as LOCK!!!
If anybody wants to look at the code, I can email it to you...I just don't want to publicly post it (yet).
Is there an error with the compiler that would allow access to a memory location by 2 different variables?
Shaun
Post Edited (Steel) : 8/21/2007 7:03:07 PM GMT
In my code, I have the following declared:
VAR
··· Byte ACTIVATE, MODE,BUFFER[noparse][[/noparse]32], LOCK··
in my code, I am using the TV Terminal to output the variable locations:
··········· TV.HEX(@LOCK, 8)
··········· TV.OUT(13)·
Because of other long variables, the address of "Lock" was 29B6.
I ran this code again with "@BUFFER[noparse][[/noparse]32]" and the address was 29BA.
Here are the following Variables I checked, and their addresses:
·29B5··· Buffer[noparse][[/noparse]27]
·29B6····LOCK······ ···· !!!
·29B6··· Buffer[noparse][[/noparse]28]····· !!!
·29B7··· Buffer[noparse][[/noparse]29]
·29B8··· Buffer[noparse][[/noparse]30]
·29B9··· Buffer[noparse][[/noparse]31]
·29BA··· Buffer[noparse][[/noparse]32]
I thought something was funny, and started going through the Array, and Low and Behold, BUFFER[noparse][[/noparse]28] is showing the same location as LOCK!!!
If anybody wants to look at the code, I can email it to you...I just don't want to publicly post it (yet).
Is there an error with the compiler that would allow access to a memory location by 2 different variables?
Shaun
Post Edited (Steel) : 8/21/2007 7:03:07 PM GMT
Comments
Give the whole code, please!
-Phil
Stupid of me!
-Phil
There's no constant folding. If you go
a := 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
it will do all the arithmetic at runtime (although there is a constant keyword to
help with this).
Similarly,
a := @v[noparse][[/noparse]30]
will do the subscripting a runtime, despite the use of a constant.
And trying to wrap @v[noparse][[/noparse]30] in constant() won't work either.
Yet another reason I've wanted to write my own Spin compiler.
Although it would be nice to have these kinds of optimizations in the compiler, it might be best to leave them out and do any optimizations in a preprocessor. My reasoning is this: So long as the compiler doesn't optimize, it's easy to predict what kind of code it will produce and design a preprocessor around those assumptions. If the compiler optimizes, but poorly or not to someone's satisfaction, it's much harder to work around those optimizations in a preprocessor. Plus, with a preprocessor, you can actually see the optimizations in the processed source code. This assumes, of course, that for every optimization, there's a canonical source equivalent that compiles optimally. That this is true for constant folding should be obvious. But for other kinds of optimizations, it may not be.
In any event, I hope the next IDE version includes the necessary hooks to make user preprocessor incorporation seamless. That way, you and I, and everybody else who has ideas about how Spin should compile or evolve can either write their own preprocessor or choose someone else's that they like. It's democratic, and Parallax doesn't have to support it; so it's a win for everbody!
-Phil