Homespun Spin compiler 0.31: Now open source
mpark
Posts: 1,305
From the "The wonder of the dancing bear" department:
Surprising myself, I've managed to write a command-line Spin compiler. It takes Spin source and generates a .eeprom file.
It runs on Windows with the .Net framework (and on Linux with Mono).
At the moment, I think it will parse anything that Proptool will, and it should generate identical bytecode (except for maybe the least-significant bit in floating-point constants).
If you have nothing better to do, please try it out on some of your Spin files and let me know if it chokes on them. (Note: Error messages may be very cryptic!)
This post is updated with the most recent version.
For more information, see the Homespun page on the Propeller wiki: http://propeller.wikispaces.com/Homespun+Spin+Compiler
Edit: Version 0.16
Edit: Version 0.17
Edit: Version 0.18
Edit: Version 0.19
Edit: Version 0.20
Edit: Version 0.21
Edit: Version 0.22
Edit: Version 0.23
Edit: Version 0.24
Edit: Version 0.25x
Edit: Version 0.27
Edit: Version 0.28
Edit: Version 0.29
Edit: Version 0.30
Edit: Version 0.31
Edit: 2013-05-27
Details here: http://propeller.wikispaces.com/Homespun+Spin+Compiler
Attached to this post are the executable and source files (C#).
Post Edited (mpark) : 10/5/2009 5:06:00 AM GMT
Surprising myself, I've managed to write a command-line Spin compiler. It takes Spin source and generates a .eeprom file.
It runs on Windows with the .Net framework (and on Linux with Mono).
At the moment, I think it will parse anything that Proptool will, and it should generate identical bytecode (except for maybe the least-significant bit in floating-point constants).
If you have nothing better to do, please try it out on some of your Spin files and let me know if it chokes on them. (Note: Error messages may be very cryptic!)
This post is updated with the most recent version.
For more information, see the Homespun page on the Propeller wiki: http://propeller.wikispaces.com/Homespun+Spin+Compiler
Edit: Version 0.16
- added "@@@" (absolute hub address) operator
- corrected object ordering bug
Edit: Version 0.17
- presence of @@@ disables duplicate object elimination
Edit: Version 0.18
- Library search paths: /L option and SPINLIB environment variable
- #define/#ifdef etc.
- /d option now produces listing file with SPIN opcodes
- warns on data truncation
Edit: Version 0.19
- experimental support for multidimensional VAR arrays
Edit: Version 0.20
- changed array syntax from a[noparse][[/noparse]i][noparse][[/noparse]j][noparse][[/noparse]k] to a[noparse][[/noparse]i,j,k]
Edit: Version 0.21
- command line options now must start with -, not /
- -L option and library path must now be separated (-L path, not -Lpath as in previous versions)
- -i0, -i1, -i2, -i3 options to control informational messages
- output file no longer contains ".out" in its name (e.g. now test.eeprom, not test.out.eeprom)
- -b option writes .binary file instead of .eeprom file
- various cosmetic changes requested by Praxis
- experimental object sharing
Edit: Version 0.22
- bug fixes
Edit: Version 0.23
- bug fix: now appends '\' to library paths if necessary.
Edit: Version 0.24
- bug fix: "NOT x := y" now parses as "NOT (x := y)" to match Proptool.
- now supports "0x" prefix for hex numbers in addition to "$".
Edit: Version 0.25x
- new -M option for Catalina/XMM.
- new -o option to specify output filename.
- bug fix: alignment bug discussed in http://forums.parallax.com/showthread.php?p=805522
- bug fix: PASM listing occasionally omitted padding bytes.
Edit: Version 0.27
- fixed listing bug.
- fixed code generation for NEXT/QUIT inside CASE.
Edit: Version 0.28
- Added #include directive.
- Can #define symbols on command line (-D option).
- #defined symbols are visible to sub-objects.
- Added TESTN instruction.
- -L now appends \ or / as appropriate.
- Prints size of output file.
Edit: Version 0.29
- Added -c option to write .dat file.
Edit: Version 0.30
- Added #ifndef condition.
Edit: Version 0.31
- Corrected #elseifdef code; added #elseifndef condition.
Edit: 2013-05-27
- Released source under MIT license.
Details here: http://propeller.wikispaces.com/Homespun+Spin+Compiler
Attached to this post are the executable and source files (C#).
Post Edited (mpark) : 10/5/2009 5:06:00 AM GMT
Comments
I'm a pretty trusting person, but not so trusting that I'd download and run an executable.
Another warning you may add is for djnz/tjz/tjnz without #. Today I thought I found a bug in pPropellerSim till I found that I just forgot a '#' in a djnz
A listing output would be really useful, for me at least.
I am curious if You have ORG X for Variables to place it with any HUB address.
Samt place PASM DAT in end of byte code to relase place after start COGs that RUN continuously.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
Sapieha
I've attached screenshots of the error in both windows and linux.
Works fine on Vista [noparse];)[/noparse]
Great job.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
Ale -- good idea! And·a listing file is on my to-do list.
Sapieha -- could you explain a little more?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
I think what Sapieha wants is for all the assembly code to be grouped together. That way, once all the cogs have been loaded and started then that memory space can be put to some other use.
Did you use Propellent? or did you write a spin parser/compiler from scratch.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Is that "em_pee" phonetic or actual ? Anyway, no email client on this OS and it's not too big and I can delete it when you've got it - This one confused it ...
C:\User\Lcc>homespun x
Homespun Spin Compiler 0.10
parsing x.spin
x.spin (1364, 17): Origin exceeds FIT limit by 1312
Could you also make it ignore EOF characters ( Ctrl-Z ) at end of file ?
I would like a way in PASM to use a hub address like
Currently you have to define and add the object offset as follows (but the address is known by the compiler)
Note: z_ENTER is located in hub somewhere below $0200.
What output form (data) would you like from a (live) spin debugger?? For example...
·See PASM debug with Zero Footprint··http://forums.parallax.com/showthread.php?p=748420
·
Mirror -- from scratch in C#.
Hippy -- thanks, I got x.spin and will look into the bug tonight. Btw,·"em-pee" was supposed to be phonetic:·m p _ _ @ etc.
Cluso99 -- you mean "@@@" is like "@" but increased by $10?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
You said
"Sapieha -- could you explain a little more?"
My Engish is not good but.
If You can place VARiables freely in HUB with marked address it is more reliable to write program snipets that have same VAR area to load from SD/EEprom from another program.
CodeStart
· pub 1
· pub 2
· xxxx
· xxxx
· xxxx
DAT
·Pasm 1
DATTR.ansparent
·Pasm 2 < To load one time .... >
·Pasm 3 < To load one time .... >
·Pasm 4 < To load one time .... >
·Pasm 5 < To load one time .... > HUB mem to reuse after COG inits
·Pasm 6 < To load one time .... > 7x2 Kb extra RUN time MEM
·Pasm 7 < To load one time .... >
·Pasm 8 < To load one time .... >
...
... Free HUB
...
VARorg 0XX00000
·VAR 1
·VAR 2
·VAR X
End of HUB.mem
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
Sapieha
Post Edited (Sapieha) : 9/9/2008 12:33:52 AM GMT
That's a nice feature, but you want it to be optional. It's not unreasonable to have some ASM sections that are one-time only and others that need to be kept around because they really are shared variable areas or are assembly code that needs to be reloaded periodically. You need some kind of option or keyword that indicates which area the DAT section should be allocated in.
By the way, anyone have a link to a known good Mono version for the current MacOS?· I tried compiling it from source once and couldn't get it to work.
Yes but I have very big problem to explain it in english.
I have reedited my post a bit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
Sapieha
This can get complicated; the offset isn't always +$10, that depends on which object the PASM is in.
I don't like triple-@ myself. Which brings us to a related issue of coming up with some standardised naming and conventions for enhancements before it gets out of control.
Your English is much much better than my Swedish.
I'd also like to see a specific operator for indirect jumps e.g. jmp @ptr
@Sapieha: I like your idea of being able to tell the compiler where to place the routines (be they VAR, DAT, PUB, PRI). My debugger requires a DAT data block to be in hub memory below $200. A hub org statement may be all that is required (I think) and an option to place the routines in the order the compiler sees them.
This would place the routines in hub in the following order... xyz, def, abc. Note xyz, abc, def can be anything (DAT, VAR, PUB, PRI).
Michael, Now you have let the cat out of the bag I am sure you are going to get lots of requests.
That space would have to be after the object link table for the top-most object because the Propeller itself needs the link table for top-most object to be at $0010. It would effectively be a "PRI Dummy" in the top-most object with a lot of zero bytecodes.
Not knowing where that space is exactly ( depends on how many link there are ) isn't a problem because a quick peek into $0010..$0013 and its location can be determined easily. Anything which needs to free up memory elsewhere can copy PASM/data to there then do whatever it does.
Not perfect for every case but should be an easy to implement hack. Padding out "PUB Main" with dummy code is how I've reserved similar space in the past. This just goes one step further and more elegantly.
parsing FLOATMATH32A.spin
FLOATMATH32A.spin (238, 36): Can't mix int and floating-point
Can you add to stdout a compile success or completed OK message?
Cheers
C:\>spin ClusoDebugger_251.spin
Homespun Spin Compiler 0.10
parsing ClusoDebugger_251.spin
parsing FullDuplexSerial.spin
ClusoDebugger_251.spin, line 290: no Nud
other :
^
ClusoDebugger found here:
http://forums.parallax.com/showthread.php?p=748420
Update: Further testing indicates that the problem is with "Other"
Post Edited (Praxis) : 9/9/2008 7:26:41 AM GMT
It doesn't seem to like the "other" keyword in a case statement.
Otherwise it works great, especially under mono for linux.
Compiles "much" faster than propellent under wine....
Great Work ..... now just the bugs
Post Edited (bmentink) : 9/9/2008 7:05:07 AM GMT
Just gave it a whirl under Mono v1.2.4 on my ubuntu setup which resulted in a "Number Overflow" error.
The file CON_test.spin (attached) is not any kind of real program just a mess of things I was trying out a while ago when I was just trying to get my PASM assembler to understand various twisty parts of the CON and DAT syntax.
I was trying to duplicate all the spin tool compilation error messages so there's a lot of weird stuff in that file but it does compile cleanly under spin tool.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
This another "non-program" just messing around with the spin syntax. It has no actual spin code in it only assembler. Well apart from an empty PUB main.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Thanks for the encouragement and the bug reports. I've attached a new version of homespun to the first post in this thread. It's mostly bug fixes for things you found (except for heater's, which I only just saw).
Right now I'm mostly trying to achieve parity with the proptool, so extensions to Spin will have to wait. Maybe by the time you decide what symbol to use for "@@@" I'll be able to implement it. Maybe.
This version·does implement one simple extension that hippy suggested: if you define a CON named _SPACE, the compiler will reserve _SPACE bytes between the .eeprom header and the first object. I don't know what good it'll do you, but have at it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
In first plase do it bug free.
In next stage it is many ideas to discus with all if You will to do that extensions.
In my opinion that extensions is very useful to save HUB memory space and have more posiblites to advanced programing.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
Sapieha
Cheers
Slight implementation flaw there ... The insert has to be after the first object link table. The Propeller Chip itself requires word[noparse][[/noparse]$0006] holds $0010 or it halts on download. And word[noparse][[/noparse]$000C] must be adjusted to first PUB address ...
Hence the space can be reserved by an invisible 'PRI Dummy' which te compiler generates N x zero bytes but doesn't link it into the object link ptr table.
Another bug for you, untrapped exception ...
You can add Win98SE to the list of OS's it works with.
Added : And thanks for the bug fixes. Brilliant.
Post Edited (hippy) : 9/9/2008 11:21:38 PM GMT
I'm more worried about the bug that Praxis reported. I must meditate on it now...
Oh, hippy, I've always wondered: how do you draw all those nice ASCII box diagrams? They're very helpful.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Michael Park
PS, BTW, and FYI:
To search the forum, use search.parallax.com (do not use the Search button).
Check out the Propeller Wiki: propeller.wikispaces.com/
Hippy's suggestion reserves the space in lower hub ram. This can be accessed neatly by PASM in rd/wr byte/word/long access using immediate values (without seperate pointers. This will allow incrementing/decrementing cog and hub addresses in 1 instruction and will hit the sweet spot.
PS Works on Vista
Post Edited (Cluso99) : 9/10/2008 1:36:13 AM GMT
This is truly awesome...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...
Experience level:
[noparse][[/noparse] ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[noparse][[/noparse] ] OK, I got my resistors hooked up with the LEDs.
[noparse][[/noparse]X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[noparse][[/noparse] ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[noparse][[/noparse] ] I dream in SX28 assembler...
/Bamse