Shop OBEX P1 Docs P2 Docs Learn Events
Proper Spin Structure — Parallax Forums

Proper Spin Structure

James LongJames Long Posts: 1,181
edited 2007-03-25 14:44 in Propeller 1
I've noticed a large number of post like this....but I don't think this will be a repeat question.



Ok.......I want to start a "cognew" but I want to make sure what this cog can address.

(obj....file)

cognew(real world value(parameters)@stack)

PUB real world value(Parameters)

·· repeat
···· method call
···· method call

The above is what I would like to do....my question. Can the method calls be in the same object file(cognew object file).....or should the methods called from this new cog be in a separate daughter object, or does it matter?

I would like to know what methods are included with the cognew command.......if any. I know the target method is included......are any listed (in the same object) included as well.

I know this is a confusing post.....I'm trying to insure my spin code is structured correctly....before I rewrite.....My cognew command (the structure called) has gotten too complex...and I need to break it down into method calls.

I know all of this would probably be much simpler in assembly.....but I have a dead line....and don't have time to learn assembly at the moment. That will come later.

·James L

Comments

  • cgraceycgracey Posts: 14,133
    edited 2007-03-24 17:19
    James Long said...


    Ok.......I want to start a "cognew" but I want to make sure what this cog can address.

    (obj....file)

    cognew(real world value(parameters)@stack)· -- Be sure to put a comma before [url=mailto:'@stack']'@stack'[/url]

    PUB real world value(Parameters)

    ·· repeat
    ···· method call
    ···· method call

    The above is what I would like to do....my question. Can the method calls be in the same object file(cognew object file).....or should the methods called from this new cog be in a separate daughter object, or does it matter?

    The Spin method that is launched with COGNEW must be in the same object as the COGNEW. However, that launched method can call both local methods and those of child objects.

    I would like to know what methods are included with the cognew command.......if any. I know the target method is included......are any listed (in the same object) included as well.

    COGNEW is just an instruction that launches a cog. It invokes no special scope, or anything.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Jeff MartinJeff Martin Posts: 755
    edited 2007-03-24 17:21
    James Long said...

    Can the method calls be in the same object file(cognew object file).....or should the methods called from this new cog be in a separate daughter object, or does it matter?
    Hi James,

    The method calls (you mean from inside the method you "launched" into another cog) can be to methods within the same object, or within another object... it doesn't matter.· What DOES matter, however, is that the method you are launching into another cog "real world value" is within the same object as the cognew that is launching it... if it is within another object, the Propeller will actually execute that method and wait for the return value from it and use that return value as the address of the code to launch (that's not what you want to do).
    James Long said...

    I would like to know what methods are included with the cognew command.......if any. I know the target method is included......are any listed (in the same object) included as well.
    When launching Spin code with cognew, the code itself doesn't get moved anywhere, but rather the new cog gets loaded with the Spin Interpreter code (from ROM) and then it simply starts executing your Spin method from Main RAM.· Effectively, that new cog can execute any Spin code contained within that object that it was launched from (what gets called depends totally on what you've written in the Target Method.
    James Long said...
    I know this is a confusing post.....I'm trying to insure my spin code is structured correctly....before I rewrite.....My cognew command (the structure called) has gotten too complex...and I need to break it down into method calls.

    I know all of this would probably be much simpler in assembly.....but I have a dead line....and don't have time to learn assembly at the moment. That will come later.

    No problem.· That's what Spin is for... quick coding that doesn't necessarily have to run as fast as possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Jeff Martin

    · Sr. Software Engineer
    · Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-03-24 19:52
    Wow....too Parallax responses....I feel special. burger.gif


    Chip said...
    The Spin method that is launched with COGNEW must be in the same object as the COGNEW. However, that launched method can call both local methods and those of child objects.

    That is exactly what information I was looking for. I wanted to insure the newly started cog could call and use information from (using the parameters) the local object file (in which the cognew command is in).

    I wasn't exactly sure of this....and hadn't started my rewrite ......I wanted to make sure before I went and messed up my working code.
    Chip said...
    cognew(real world value(parameters)@stack)· -- Be sure to put a comma before [url=mailto:'@stack']'@stack'[/url]
    Yea...I was justbeing lazy.....I have comma's where they belong.
    Jeff said...
    The method calls (you mean from inside the method you "launched" into another cog) can be to methods within the same object, or within another object... it doesn't matter.· What DOES matter, however, is that the method you are launching into another cog "real world value" is within the same object as the cognew that is launching it... if it is within another object, the Propeller will actually execute that method and wait for the return value from it and use that return value as the address of the code to launch (that's not what you want to do).
    That is basically what Chip said.
    Jeff said...
    When launching Spin code with cognew, the code itself doesn't get moved anywhere, but rather the new cog gets loaded with the Spin Interpreter code (from ROM) and then it simply starts executing your Spin method from Main RAM.· Effectively, that new cog can execute any Spin code contained within that object that it was launched from (what gets called depends totally on what you've written in the Target Method.
    I just wanted to ensure what was loaded into the cognew....and what it could actually call from the new cog.

    Thanks all,
    James L
  • Stan671Stan671 Posts: 103
    edited 2007-03-25 14:44
    Thanks, James for asking that question ... I was curious about the same stuff.· And thanks to Chip and Jeff for such clear answers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski
Sign In or Register to comment.