PDA

View Full Version : Why does Spin interpret instead of compiling?



Electronegativity
11-08-2010, 09:27 PM
The title pretty much says it all.

If the Spin code compiled into machine language we could have our cake and eat it too.

Leon
11-08-2010, 09:35 PM
It would use too much memory.

Dave Hein
11-08-2010, 09:40 PM
It would use too much memory.
But, it would be faster. Unfortunately, we cannot have our cake and also eat it, except for very small pieces of cake.

wjsteele
11-08-2010, 09:48 PM
If the Spin code compiled into machine language we could have our cake and eat it too.

Actually, it's not hard at all to compile spin... the problem is much deeper than that, however.

All program execution runs in a cog. Spin is interpreted because one or more cogs have a spin intrepreter running in it. That program fits nicely into the cog memory. The actual spin code resides in the 32k of HUB memory. 32k > 512. If you compiled it, it would have to run in 512 instructions... which makes for a small program.

There is an alternative... mostly referred to as LMM (Large Memory Model,) in which code is compiled and stored in the HUB memory. Then the only thing in the cog memory is a bit of code that reads instructions from HUB memory and executes them. Naturally, it's slower than pure PASM, but it is still faster than SPIN.

So... you can eat your cake if your prefer small cupcakes... or you can have someone just bring you your cake a byte at a time. :-)

Bill

Campeck
11-08-2010, 10:02 PM
Haha!
Nice explanation steele.

Electronegativity
11-09-2010, 12:50 AM
Thanks for the explanations.

This whole thing is giving me flashbacks to the Apple IIC computers I used in high school.
They ran interpretive BASIC, but you could write assembly subroutines.

evanh
11-09-2010, 01:51 AM
Spin and LMM are both virtual machines.

I'd fallen into the same thinking, that Spin is interpreted, until it was pointed out that the Spin source is not the same program as it's compiled binary counterpart.

The other factor is addressing, Hub space is treated as main memory in Spin. In native Cog coding Hub space has special instructions to access it.

Peter Jakacki
11-09-2010, 01:52 AM
Thanks for the explanations.

This whole thing is giving me flashbacks to the Apple IIC computers I used in high school.
They ran interpretive BASIC, but you could write assembly subroutines.

Yes, I think you are forgetting that the Propeller is actually 8 microcontrollers (cogs) on a chip with a common (but slow) 32KB hub RAM. Each cog only has <512 words of memory for program and data so any "assembly" language would have to fit in that small space. Assembly code cannot run directly from the hub RAM either so it makes sense then to "interpret" code from there in much the same way a VM (virtual machine) works.

Don't confuse a Basic interpreter with a VM runtime interpreter which reads virtual opcodes which have been compiled, in this case with the Spin tool. Spin byte code could be considered the machine code of the Spin VM.

It is also not possible for the cog to directly address more than 512 words of instruction memory either as this is a feature (and a limitation) of the instruction set.

evanh
11-09-2010, 01:59 AM
Having said that, there are big differences between the two though. Spin is a high level language that compiles to a simpler library based binary. Where as LMM tries to be a virtual Cog.

ericball
11-09-2010, 02:56 AM
In addition to everything said above, the Propeller Tool compiles the SPIN source code to a bytecode - similar to how Java source is compiled into Java bytecode. The bytecode instructions are often more functionally complex than machine code - again reducing the size of the code required to express a given function.

william chan
11-09-2010, 03:33 AM
It would use too much memory.

Does this mean that PropBasic also uses too much memory?

potatohead
11-09-2010, 03:59 AM
Propbasic can compile to a COG, where the program needs to fit into the ~500 cog longs.

It can also do LMM, where additional longs are fetched from the HUB, then executed, at a lower speed. This speed is higher than SPIN, but lower than the native COG speed.

LMM is larger than SPIN, for most things. Maybe all things, but I've not really looked at it closer.