Use of spin2cpp
kg1
Posts: 164
in Propeller 2
As a beginner please advise resolution of error:
Kevin
C:\FlexGUI\kgsamples>spin2cpp --main --ccode --files blink_all_cogs.spin blink_all_cogs.spin:33: error: coginit stack is not array line 33: coginit(cognum, doblink(cognum, delay), @stack[cognum*4])Thanks,
Kevin
Comments
edit: found it in the sample dictionary
Use Instead fastspin, this works:
The way I understand it, spin2cpp was made to turn Spin code into something that GCC can compile.
But, GCC for prop2 is not really ready for prime time, I think...
Also note that for converting Propeller 2 code you should give the --p2 command line option to spin2cpp.
What are you trying to accomplish with spin2cpp? From the looks of it you want to convert some Spin code to C, presumably to run with one of the C compilers. Is this for Prop1 (using PropGCC) or for Prop2 (using a different C compiler)?
Also the readme.md file that comes with spin2cpp does lists the parameter -p2.
@ersmith I am a beginner with regard to P2 but looking at my photo I can't claim to be a beginner beginner. I started by looking at Catalina (RossH) due to my interest in C programming and debugging. Here there is a suggestion that one could use spin2cpp to use spin examples in the Catalina system. I have only tried two samples.
What is the current status of the C programming language (relative to P1) in the P2 environment: Is it say 80% on target?
What is the current status of spin2 in the P2 environment? Is it 99% on target?
I am searching for a beginners path. At this moment is the C language a no go area?
Kevin.
Using spin2cpp with Catalina on P2 will work for some things, but it's not a very well supported combination (as you've found) and definitely not a path I'd recommend for beginners. spin2cpp was originally designed for use with PropGCC on P1.
You can use C directly in flexgui (the .c files in the samples directory should all compile and run directly, just load them into the flexgui main window and hit "Compile and Run on P2"). Even some significant programs like the Lisp interpreter in samples/proplisp will work. Your estimate of 80% done for the C language is probably about right for the C support in flexgui. Most simple programs will compile and run just fine, but the C library is still incomplete.
Chip is still designing the Spin2 language. flexgui supports Spin1 even for P2, and has a number of Spin2 features, so it's kind of a Spin1.5. If you're already familiar with Spin then the Spin in flexgui should work well for you.
Kevin.
Couple of thoughts,
Primary education isn't concerned with corporate influence (and its accusations of corruption from angry parents). Teaching the fundamentals is more critical. Variables, branching, loops, input-processing-output, etc.
C isn't a good teaching tool because is it really fair like one person out of a whole class is going to grasp those semicolons and brackets? Where everyone else's code isn't even going to compile at all and they can feel the crushing weight of failure? That's what I've heard from teachers. Too much to do, not enough time. It must be taught in easily digestible blocks.
There's also the problem that whatever tools (IDE, menus, command line) are taught in school, they'll be entirely obsolete in less than a decade. Yes being a master at a certain language gets you hired. But, personally speaking, having been in industry it's a more valuable skill to be able to jump quickly into an obscure tool or language and fix the immediate need.
Seeing a diversity of languages, and never stop learning, that's the ticket to success.
Spin may not be much of that, but it's a very simple way to write code that doesn't obfuscate and undermine the inescapable underlying realities of computing.
They are learning scratch (similar to blocklyprop?). One of the boys made a spaceship, scaled a person and put them inside the spaceship. Added ground, and a flame, and made the rocket launch into space.
I was amazed that a 5yo could do this in just a few lessons.
Kevin.
Very cool...I was wondering where to start with my grandkids :cool:
From an education perspective I think any language that enables kids to quickly learn how to program is a fine choice. I was taught Java in high school, and while it's one of my very least favorite languages, it did the trick and I moved on to better options.
For general industrial use, I believe C/C++ is the most likely to generate customers and widespread adoption. Another interesting option would be a code generator for Matlab/Simulink, though C/C++ would be my personal choice for the generated code.
A combination for P2 that I would love to explore is microPython with easy C++/assembly/Spin loadable modules for the real-time bits. In my day job I code 80% Python with 20% wrapped C++ for desktop code and having that combo at the embedded level would be terrifically fun.
Yes, I would agree. I think that it would be compelling to interact with and should become even easier if we get a full native compiler setup instead of using either Eric's RISC-V translation or the somewhat library limited P2GCC approaches. With additional work something could probably start to become possible using these existing compilers though the interfacing hasn't been fully mapped out quite yet. I'm still hopeful that the official Spin2 code could be launched/called from another language/environment such as C and MicroPython etc however how easily that will be may depend on how Chip does it.
Standard MicroPython only allows loadable modules under Unix. The embedded versions do not have any facility for loading C/C++ code at run time -- I think the design philosophy was that if you wanted to add C/C++ code you'd compile a custom version of the interpreter for those environments.
That said it probably would be feasible to add the ability to load position independent code (e.g. from ELF files) at run time to ports other than Unix. It would require implementing something like the dlopen/dlsym dynamic library interface for a bare metal machine.
The _cnt / _getcnt problem is fixed in github.
Thank you everyone for a very worthwhile discussion.
Kevin.
Regards,
Kevin.
You can build it yourself under Windows with mingw32 or a similar compiler set. Or, just keep using -D_getcnt=_cnt on the compiler command line until the next release.
Kevin.
Which version of spin2cpp are you using? The latest released one is 4.0.6 and that should have the "clkset is not a function" problem fixed. The binary releases are at https://github.com/totalspectrum/spin2cpp/releases.
Thank you
Kevin.
Generally not, fastspin's optimizer is better than Catalina's and is tuned for the P2. On the other hand Catalina is better documented and has a debugger, so there are times when it might be nice to use spin2cpp to convert Spin programs to Catalina compatible C.
Incidentally, spin2cpp can also convert (some) BASIC programs to C as well, although that support is still pretty incomplete (the BASIC library calls tend not to be converted correctly, so it only really works on low level BASIC programs like drivers).
You're trying to compile "blink1.h" and not "blink1.c". Make sure "blink1.c" is the tab you have selected when you press the compile button.