OpenSpin Spin/PASM compiler in C/C++
Roy Eltham
Posts: 3,000
Updated: 10/13/2014
To report issues, browse the documentation, or access the latest source, go here: https://github.com/reltham/OpenSpin
Windows binary builds are provided by me, you'll need to build binaries yourself for other platforms. It's recommended that you build from the latest release version of the source instead of using the head revision, unless something in a pre-release source update fixes an issue you are having.
Releases are at: https://github.com/reltham/OpenSpin/releases
You can browse the changes I've made in the source commits at github. In the future, I'll list significant changes/fixes in the release descriptions.
To report issues, browse the documentation, or access the latest source, go here: https://github.com/reltham/OpenSpin
Windows binary builds are provided by me, you'll need to build binaries yourself for other platforms. It's recommended that you build from the latest release version of the source instead of using the head revision, unless something in a pre-release source update fixes an issue you are having.
Releases are at: https://github.com/reltham/OpenSpin/releases
You can browse the changes I've made in the source commits at github. In the future, I'll list significant changes/fixes in the release descriptions.
Comments
Any chance it'll compile in GCC on the Prop itself in the future?
OBC
Could you also include a downloadable zip of the source so that lurkers like me don't have to go through the subversion stuff just to look at it?
Thanks,
-Phil
The propgcc guys have already brought that up as a possibility using one of the XMM models. I think it would be awesome, and I'll help make it happen if it can.
Phil,
I'll do that tonight when I get home (will be late, so check back in the morning).
It's here (in case you haven't found it yet):
http://code.google.com/p/open-source-spin-compiler/source/browse/
Fantastic work, Roy - another missing piece of the puzzle falls into place!
Will you be doing the Prop 2 version? Any date for release of that yet?
Thanks,
Ross.
I believe I will be involved with the Prop2 version. I don't have any information on any release dates, sorry.
Thinking ahead about self compilation on the propeller, boot into a command line operating system like kyedos, run a text editor (there are a few possibilities), save the file, go back to the operating system, run a precompiled GCC program to process the file and produce a .binary output, rename that .binary as a .exe and then run it.
Any idea (roughly) how long it would take to compile a 1000 line program on the propeller itself?
re Compiling on the prop...
For now, we can use wordstar under ZiCog & CPM. I am working on file transfer between cpm and the prop FAT16/32 using Kyes SD driver. I am well on the way with this and hope to have the cpm->FAT working in the next day or two. Currently I am limited to 4KB transfers (1 block) and am testing up to 32KB (8 block) which is 1 directory entry on cpm. Then I have to check multiple Dir entries that larger files use. I can detect eof with text files but not with binaries so I am presuming that it really does not matter on the FAT side. Time will tell.
-Phil
Phil! Noooo.... Just walk away! ... Walk away NOW! ....
-Phil
Be aware, that this codebase is not the best representation of C++ (yet). It's really more like C with a few classes sprinkled in. Plus I take advantage of a few C++ features like references.
Over time, I plan to do more cleanup that will reduce the amount of globals, and likely increase the amount of classes and C++ features. I will NOT be using STL.
Of course, nothing is stopping anyone from taking this code and converting it to plain old C, Java, C#, or any other language really. At least nothing but time and effort.
Roy
Did you or Chip ever produce a formal grammar for Spin syntax? If not, is there any plan to? Just curious ...
Thanks,
-Phil
It's been a long road....
The ASM appears to be decently documented, is there any chance we will see the source of that?
The port appears to be exactly that, was there consideration given to writing it as a LEX/YACC proper grammar compiler, or was porting the only desired option?
Floating point in Spin is implemented via method calls. The floating point methods are written in Spin and PASM. Overloading the standard operators to perform floating-point arithmetic would require a FLOAT type, which Spin does not have. Floating point numbers are stored as longs and how they are treated is specific to whether the FP methods are invoked overtly in the Spin source or not.
-Phil
That floating point code is only used at compile time for float constants. I implemented most of the via just using C/C++'s build in float support. That is one area where this compiler might not being 100% binary matching with the x86 code, because occasionally the lowest bit(s) of precision in a float number might differ. We opted to go with standard C/C++ float support because it follows the IEEE standard.
I actually had not intended to include that file, and it'll be taken down when I get home, since it's not needed. I have removed the contents already since I could do that easily from here.
What determined the decision to do a port versus rewriting it and using the original code as a guide?
Is there a chance we will see the original x86 code?
EDIT: The manual would seem to suggest that FLOAT was originally intended to be implemented as part of SPIN, but left out due to size constraints? You can do a 32bit single precision float, and having FLOAT in SPIN would potentially eliminate the need for a dedicated COG for that. With an LMM model, SPIN could do float natively I would think.
I updated the executable download to a new version that should not have any external dependencies. This was build with VS2008 in release mode and static linking of the runtimes.
I also added a zip containing the source code as of r24, so you can download it without having to install svn.
pedward:
Sorry for my confusion. Yeah, float support in spin would be really nice. However, with the Prop 1, the spin interpreter is in the rom. Yes, there are tricks to work around that and get custom ones running, but I can't imagine one doing float plus everything else without using 2 cogs (at least). On the Prop 2, I think it should be quite reasonable to do though.
Just have to point out here that Catalina supports basic FP operations (add, sub, mul, div) as fast implementations within the LMM kernel cog. This makes it the fastest floating point programming option available for the Propeller. You don't need any external cogs (i.e. the the whole standard C FP library is emulated in software) but if that's not fast enough for you you can add either one external cog (i.e. simple FP library functions done in a fast cog implementation, complex FP functions emulated in software) or two external cogs (all FP functions done in two fast cog implementations) depending on your speed and space requirements.
And the next version of Catalina will be even faster!
Ross.
I was speaking only of Spin when I was talking about requiring more than one cog for FP.
Yes, I know ... but it never hurts to advertise!
Ross.
The tricky part will be parameter passing, since all parameters are assumed to be longs. This could be accommodated by allowing a method's formal parameters to be declared with the FLOAT modifier. It would then be up to the compiler to apply float or int to the results of any expressions passed as parameter values, depending upon the target method's formal parameter declarations. The same would also have to apply to any values returned, where the method could apply the FLOAT modifier to its result variable.
I've used the word "modifier" instead of "type" because Spin is an inherently typeless language and, IMO, should stay that way. That may be a distinction without a difference, though, except that the default "type" for all longs, including formal parameters and local variables, will still be integer unless modified. The modifier could be as simple as a trailing decimal point in the variable name where it's declared, in order to avoid syntactic clutter.
-Phil
In the role of ginny pig I tried executing spin.exe and got a missing dll message.
What are the minimum things that need to be installed on a PC to run the program.
Tom
That was the issue where the previous version required MinGW. I updated it last night. If you get spin-r24.zip it should not need anything else installed to work.
I added a -d option to spin.exe that will dump out the results of CompileDoc (it's the same is documentation mode in the Prop Tool).
Now it's just any bugs that our found, and then on to new features and changes.
Can we talk about Spin/PASM language extensions here, or would you prefer devoting a different thread to that?
-Phil