Homespun Spin compiler 0.31: Now open source

mparkmpark Posts: 1,146
edited October 2011 in Propeller 1 Vote Up0Vote Down
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
  • 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

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
«13456712

Comments

  • 335 Comments sorted by Date Added Votes
  • PraxisPraxis Posts: 333
    edited September 2008 Vote Up0Vote Down
    Sweet!
  • rokickirokicki Posts: 1,000
    edited September 2008 Vote Up0Vote Down
    Can we get source, and not an executable?

    I'm a pretty trusting person, but not so trusting that I'd download and run an executable.
  • AleAle Posts: 2,277
    edited September 2008 Vote Up0Vote Down
    Well done !,

    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 wink.gif

    A listing output would be really useful, for me at least.
  • SapiehaSapieha Posts: 2,964
    edited September 2008 Vote Up0Vote Down
    Hi mpark

    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
    Regards
    Sapieha
    _____________________________________________________
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it as simple as possible yet as versatile/usable as possible.
  • Harrison.Harrison. Posts: 484
    edited September 2008 Vote Up0Vote Down
    It seems to run fine in linux with mono. It failed compiling one of my projects (the error seems to be a .NET exception or something like that). I'll post / send you a copy of the project that fails if you want to test it out some more.

    I've attached screenshots of the error in both windows and linux.
    825 x 463 - 63K
    670 x 340 - 22K
  • BaggersBaggers Posts: 2,965
    edited September 2008 Vote Up0Vote Down
    mpark,
    Works fine on Vista [noparse];)[/noparse]
    Great job.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • mparkmpark Posts: 1,146
    edited September 2008 Vote Up0Vote Down
    Harrison -- yes, please post or PM or e-me (em-pee-underscore-underscore-at-hotmail.com).

    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/
  • mirrormirror Posts: 322
    edited September 2008 Vote Up0Vote Down
    Michael,
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • hippyhippy Posts: 1,977
    edited September 2008 Vote Up0Vote Down
    Excellent stuff. Actually, above excellent.

    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 ?
  • Cluso99Cluso99 Posts: 12,515
    edited September 2008 Vote Up0Vote Down
    Nice work Michael jumpin.gif

    I would like a way in PASM to use a hub address like
    D_LMM_BOOT              rdlong  X_ENTER, [url=mailto:#@@@z_ENTER]#@@@z_ENTER[/url]   '\ copies Debug code
    

    Currently you have to define and add the object offset as follows (but the address is known by the compiler)
    CON
    ' The following is the object offset needed to be added to [url=mailto:#@xxxx]#@xxxx[/url] in Debug_Block pasm instructions (compiler restriction)
      DB            = $10                                          '<=====
      
    
    DAT                   
    
    D_LMM_BOOT              rdlong  X_ENTER, [url=mailto:#DB+@z_ENTER]#DB+@z_ENTER[/url]   '\ copies Debug code
    
    

    Note: z_ENTER is located in hub somewhere below $0200.

    What output form (data) would you like from a (live) spin debugger?? For example...
    pcurr            dcurr      
    addr   bytecode  stack  -0         -1         -2         -3  
    $xxxx  xx xx xx  xxxx = xxxx_xxxx  xxxx_xxxx  xxxx_xxxx  xxxx_xxxx
    
    
    

    ·See PASM debug with Zero Footprint··http://forums.parallax.com/showthread.php?p=748420
    ·
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • mparkmpark Posts: 1,146
    edited September 2008 Vote Up0Vote Down
    Sapieha·-- If mirror is correct, have you seen this thread: http://forums.parallax.com/showthread.php?p=670353?

    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/
  • SapiehaSapieha Posts: 2,964
    edited September 2008 Vote Up0Vote Down
    Hi mpark.

    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
    Regards
    Sapieha
    _____________________________________________________
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it as simple as possible yet as versatile/usable as possible.
  • Mike GreenMike Green Posts: 22,377
    edited September 2008 Vote Up0Vote Down
    Sapieha,
    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.
  • SapiehaSapieha Posts: 2,964
    edited September 2008 Vote Up0Vote Down
    Hi Mike Green.

    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
    Regards
    Sapieha
    _____________________________________________________
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it as simple as possible yet as versatile/usable as possible.
  • hippyhippy Posts: 1,977
    edited September 2008 Vote Up0Vote Down
    Cluso99 said...
    I would like a way in PASM to use a hub address like
    D_LMM_BOOT              rdlong  X_ENTER, #@@@z_ENTER
    

    mpark said...
    Cluso99 -- you mean "@@@" is like "@" but increased by $10?

    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.
  • Mike GreenMike Green Posts: 22,377
    edited September 2008 Vote Up0Vote Down
    Sapieha,

    Your English is much much better than my Swedish.
  • Cluso99Cluso99 Posts: 12,515
    edited September 2008 Vote Up0Vote Down
    @Hippy & @mpark: Yes it is not always +$10 so that was my point. I don't like @@@ either - just used it to signify something in it's place.
    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.
     
    xyz  huborg 0
    .....
    xyz_end
     
    abc  huborg var_end
    .....
    abc_end
     
    def  huborg $
    .....
    def_end
     
    

    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.smile.gif
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • hippyhippy Posts: 1,977
    edited September 2008 Vote Up0Vote Down
    The easiest solution for needing a fixed-position data block would be to use a /SPACE:n switch or a "_SPACE n" directive ( preferable both ) which works similar to _STACK but reserves some space at the start of Eeprom image.

    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.
  • PraxisPraxis Posts: 333
    edited September 2008 Vote Up0Vote Down
    Testing so far OK but it chokes on this:

    PI2                     LONG    PI / 2.0
    
    



    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
  • PraxisPraxis Posts: 333
    edited September 2008 Vote Up0Vote Down
    I tried it with the ClusoDebugger_251.spin

    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
  • bmentinkbmentink Posts: 107
    edited September 2008 Vote Up0Vote Down
    I got the same with i2c.spin:
    Homespun Spin Compiler 0.10
    parsing i2c.spin
    i2c.spin, line 213: no Nud
          other: ' any other value passed! 
    
    



    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 burger.gif

    Post Edited (bmentink) : 9/9/2008 7:05:07 AM GMT
  • heaterheater Posts: 3,370
    edited September 2008 Vote Up0Vote Down
    mpark: This is truly impressive!

    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.
  • heaterheater Posts: 3,370
    edited September 2008 Vote Up0Vote Down
    mpark: Here is another test file that does compile with out error in homespun but produces a different eeprom file than the spin tool.

    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.
    808 x 604 - 24K
  • mparkmpark Posts: 1,146
    edited September 2008 Vote Up0Vote Down
    Hi guys,

    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/
  • SapiehaSapieha Posts: 2,964
    edited September 2008 Vote Up0Vote Down
    Hi mpark.

    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
    Regards
    Sapieha
    _____________________________________________________
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it as simple as possible yet as versatile/usable as possible.
  • PraxisPraxis Posts: 333
    edited September 2008 Vote Up0Vote Down
    I tried it with the ClusoDebugger_251.spin again, now it hangs until I terminated the process.

    Cheers
  • hippyhippy Posts: 1,977
    edited September 2008 Vote Up0Vote Down
    mpark said...
    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.

    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 ...

    Genuine Prop Tool Image
    
          .-------.
    $0000 |       |
          |       |
    $0006 | $0010 |         Ptr to main object ( must be $0010 )
          |       |
    $000C | $0018 |----.    Ptr to first PUB to execute after boot
          |_______|    |
    $0010 |_______|----|--> Next Obj
          | $0018 |----.    Ptr to first PUB within object
          |       |    |
          |       |    |
          |_______|    |  <<<=== Insert space here
    $0018 | First |<---'
          |  PUB  |
          |       |
    
    With 16 bytes inserted
    
          .-------.
    $0000 |       |
          |       |
    $0006 | $0010 |         Ptr to main object ( must be $0010 )
          |       |
    $000C | $0028 |----.    Ptr to first PUB to execute after boot
          |_______|    |
    $0010 |_______|----|--> Next Obj
          | $0028 |----.    Ptr to first PUB within object
          |       |    |
          |       |    |
          |_______|    |
    $0018 |XXXXXXX|    |
          |XXXXXXX|    |  <<<=== Inserted 16 bytes here
          |XXXXXXX|    |
          |XXXXXXX|    |
    $0028 | First |<---'
          |  PUB  |
          |       |
    
    
    


    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 ...

    CON
      _space
    PUB Main
    
    
    



    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
  • mparkmpark Posts: 1,146
    edited September 2008 Vote Up0Vote Down
    Oops, OK, don't use _SPACE until further notice.

    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/
  • Cluso99Cluso99 Posts: 12,515
    edited September 2008 Vote Up0Vote Down
    Michael,
    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.

          mov    num,#10        'set number of ongs to transfer
    loop  rdlong cog-0,#hub-0   'reads into 'cog' address from '#hub' address (no indirect hub pointer, hub <$200)
          add    loop,X_204     'increments 'cog' by 1 and '#hub' by 4
          djnz   num,#loop      'hits the 'sweet spot' (16 clock loop)
     
    num   long   0-0
    X_204 long   $204           ' %000000001_000000100 (+1 to destination, +4 to source)
     
    

    PS Works on Vista

    Post Edited (Cluso99) : 9/10/2008 1:36:13 AM GMT
    My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBlade
    Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    Prop Tools (Index) , Emulators (Index) , ZiCog (Z80)
  • BamseBamse Posts: 561
    edited September 2008 Vote Up0Vote Down
    Got it to work on Ubuntu 8, awesome job...

    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
Sign In or Register to comment.