Shop OBEX P1 Docs P2 Docs Learn Events
Application-like code structure — Parallax Forums

Application-like code structure

ChrisCantrellChrisCantrell Posts: 25
edited 2011-07-01 07:39 in Accessories
Forgive me if this is a newbie question. I promise, I have spent considerable time searching for the answers.

SPIN seems very good in building individual objects, but it doesn't seem to provide for large application development.

For instance, I want to isolate the filesystem code in one module and the HTTP request handling in another. Both objects need the common string-engine. It seems I have to list the "STREngine" in every object that needs it. That seems to make several copies of the code.

I encounter the same problem with the PST serial terminal. If I want to put "print(HERE)" in different modules then I have to include PST in all modules and it makes copies of the code.

Am I doing something wrong? Is there a better pattern for sharing libraries and code between modules? Am I just really, really new to SPIN?

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-06-28 09:24
    Objects function as written by the author. Some objects might require multiple instances while others can be shared.

    Let's take PST... you have PST fired up in your top level object but you're trying to debug values in a child object. Simply expose the child member through a getter. If you need a memory block, return a pointer.
    PUB GetMyValue
      return value
    

    I'm not sure about "STREngine" but I wrote a string parsers that spins up in a COG from the top level object and is available to any object through pointers.
    http://www.agaverobotics.com/spinneret/source/
  • ChrisCantrellChrisCantrell Posts: 25
    edited 2011-06-28 10:15
    That makes sense. Thanks for the help!

    Let me try my question a different way. I have object "HTTPProcessor" written in SPIN that uses several of the string functions in "STREngine" (compare strings, strings-to-upper-case, etc). I have object "ConfigFileParser" written in SPIN that also uses the same string functions in "STREngine".

    It seems that I must add "STREngine" to every object that needs the string functions. And the compiler makes a copy of "STREngine" code for each object. It would be nice to share a single copy of the string functions across all objects that use it. Maybe this is just a limitation of SPIN. But I hope I am just missing something simple and fundamental.

    Thanks again for your help, Mike.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-28 10:36
    The only things that get multiple copies in the compiled code are the VAR variables. The code itself and anything in the DAT section are included in the compiled code just once.

    -Phil
  • ChrisCantrellChrisCantrell Posts: 25
    edited 2011-07-01 05:58
    Thanks, Phil. Sorry to clutter the forum with stupid questions. I feel better about SPIN now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-01 07:39
    Chris, there are no stupid questions. The only thing that's stupid would be to wallow in ignorance because one is afraid to ask. :)

    Good luck with your project!

    -Phil
Sign In or Register to comment.