Shop OBEX P1 Docs P2 Docs Learn Events
What are the necessary filename extensions for P2 code? — Parallax Forums

What are the necessary filename extensions for P2 code?

Programming for the P1, I think I always used the extension of ".spin" for all my source code. A lot of the code files were actually PASM, with a little bit of Spin, as is common on both P1 and P2.

I would sort of like to continue this simple naming with P2 development, but most samples I see use the ".spin2" extension. Additionally, I have seen extensions like ".p2asm" and (perhaps?) ".pasm2". Are these real conventions for the source code, and/or necessary for the P2 compiler tools?

In an ideal world, simply using a compiler that supports PASM2/Spin2 ought to be all that is needed to compile such code. But, maybe, the tools are being designed to handle both P1 code and P2 code and it needs these extensions as clues to pick the right compiler internally?

If someone could elaborate on what the conventions are and why they exist, I'd be grateful for the clarity.



  • JonnyMacJonnyMac Posts: 8,809
    edited 2022-12-17 18:37

    Propeller Tool uses .spin for P1 files which can contain Spin 1 and PASM 1 code. It uses .spin2 for Spin 2 files that contain Spin 2 code and PASM 2 code. If one uses the FILE directive, one can embed anything. For example, you might hold a string in an external text file that can be included into your Spin (1 or 2) code like this:

      Version       file    "version.txt"
                    byte    0

    Appending the 0 allows Version to be used with .str() methods.

    It's possible that some programmers use external files for pure PASM code and embed it in a listing with the FILE directive. Their choice of extension doesn't matter to Propeller Tool as the raw text of the file is being embedded into the listing (like include in other languages).

    There are other file types, but they cannot be edited: .binary (P1 and P2), .eeprom (P1), and .flash (P2). If you're not using the latest version of Propeller Tool, you should; it knows how to handle all legal file extensions.

    If you're using FlexProp, you need to direct it to the compiler of your choice based on the syntax you're using.

  • @JonnyMac That's helpful. The fact that Propeller Tool is sort of the "canonical" tool, and that this is how it chooses to differentiate Spin1/Spin2 (while compiling either), makes for a necessary convention.

  • Note that -- for the time being, anyway -- you have to save a file before compiling it. I put the tags {$P1} and {$P2} into my files hoping that a future version of the compiler can use them (the way the Parallax BASIC Stamp editor did with the different versions of the Stamp).

  • Jon has already answered this, but to expand a little upon it here is what FlexProp uses for file extensions:

    .spin for Spin 1 (original Spin language)
    .spin2 for Spin 2
    .bas for BASIC
    .c for C
    .cpp or .cc for C++ (only a very little bit of C++ is handled)

    Note that in all cases the extension only sets the language, not the processor. You'll have to select which processor you're compiling for from the Commands > Configure Commands menu. (the default is the P2). That's because FlexProp can compile spin1 code for the P2, and spin2 code for the P1; in both cases of course any embedded assembly code will have to be for the appropriate processor.

    Some temporary files produced by FlexProp have a .pasm (for P1 assembly) or .p2asm (for P2 assembly) extension. These are not intended to be edited by humans and the extensions aren't accepted in general for input.

Sign In or Register to comment.