Giter Site home page Giter Site logo

totalspectrum / spin2cpp Goto Github PK

View Code? Open in Web Editor NEW
46.0 12.0 17.0 18.79 MB

Tool to convert Parallax Propeller Spin code to PASM, C++ or C

License: Other

Propeller Spin 3.97% C++ 7.37% Makefile 0.15% C 82.27% Shell 0.23% Yacc 3.06% Parrot 1.82% Tcl 0.22% Lex 0.06% Python 0.02% FreeBasic 0.82% Pawn 0.01% Visual Basic 6.0 0.01%
propeller propeller-spin propeller2

spin2cpp's Introduction

Spin2cpp is a program for converting Spin, BASIC, or C code to binary, PASM (Parallax Propeller 1 assembly), P2ASM (Parallax P2 assembly), Spin1 bytecode, C, or C++.

flexspin is a slightly different front end to the same functionality, designed to be compatible with other spin compilers.

flexcc is a third front end designed to accept the arguments normally given to C compilers (cc). Like the others, it can actually accept Spin and BASIC input as well as C.

The command line options for spin2cpp and flexspin are documented in Spin2cpp.md and Flexspin.md respectively.

Documentation for the various front ends (languages accepted as input) are in doc. The BASIC language is the best documented. The C and Spin documentation just cover extensions and deviations from the standard (C99 in the case of C, and the original Propeller compiler in the case of Spin).

BUILDING

On most Linux installations you should be able to build with "make", which will place binaries in the "build" folder.

On macOS the procedure is similar, but you'll probably have to manually install a newer version of bison (the one that comes with macOS is too old). You'll need at least bison 3.0.

On Windows it should be possible to build using msys or a similar gcc based build environment, but you'll need to install bison 3.0 or later, flex, gcc, and make.

Tips and Tricks

Executable Name

If you name your executable "bstc.exe", it will try to act like the BSTC compiler (so it can be used in build scripts and IDEs that use bstc style command lines). For example, flexspin will work this way as the back-end assembler for PropBasic.

If you name your executable something that ends in "spin2" (like "flexspin2.exe") it will compile for P2 by default.

Credits

Most of spin2cpp was written by Eric R. Smith. The bytecode back end and many other improvements and bug fixes were contributed by Ada Gottensträter. The C preprocessor was written by Kiyoshi Matsui. Many people have contributed bug fixes, suggestions, and library files; see the COPYING and COPYING.LIB files for the full list of contributors.

spin2cpp's People

Contributors

avsa242 avatar dbetz avatar drawkula avatar reltham avatar totalspectrum avatar wuerfel21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spin2cpp's Issues

_FREE / _STACK don't work

Seems like a really trivial feature...
This should not compile:

CON
_FREE = 7000
PUB NO
	OUTA := mygunk[INA]
DAT
mygunk
long 0[2000]

(OUTA := mygunk[INA] added to work around optimization)

spin2cpp fails to build Pasm variant of .spin that includes reference to an object's var

EDIT: Bug report title refers to an object's var, but I realize that these are object constants...

Fails to build Pasm on use of an included object's constant of the form: object_name#constant_name

Source:

OBJ
  pst : "Parallax Serial Terminal"

PUB start

  if ina[31] == 1                            'Check if we're connected via USB
    pst.start(115200)
    pst.Clear

  pst.str(string(" test...",pst#NL))    ' FAILS ( error: Unable to emit string)

Results:

spin2cpp --noheader -g --asm --code=cog --data=hub -L /SpinObjects -o testObjVar.spin
testObjVar.spin:10: error: Unable to emit string
child killed: segmentation violation

frequent explicit orgh warnings

Every Spin2 program seems to result in the same warnings:

warning: orgh with explicit origin does not work if Spin methods are present

fastspin/spin2cpp crashes on recent Mac OS X versions

I know, I'm kicking-over an old issue here, but I do think this is a real issue for spin2cpp on Mac OS X. Hopefully another Mac OS X user will have run into this as well and may have more info...

When I run fastspin or spin2cpp on any .spin file, I get a crash at the same place in assemble_ir.c (@ line: 127). The error occurs in this code:

`void
PrintOperandAsValue(struct flexbuf *fb, Operand *reg)
{
Operand *indirect;

switch (reg->kind) {   // reg->kind is pointing to some 'illegal' location in memory`

The error in Mac OS X crash-speak is:
`Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000011628be0

VM Regions Near 0x11628be0:
-->
__TEXT 000000010e6cc000-000000010e712000 [ 280K] r-x/rwx SM=COW /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 fastspin 0x000000010e6f0c40 PrintOperandAsValue + 16 (assemble_ir.c:127)
1 fastspin 0x000000010e6f19a8 DoAssembleIR + 3016 (assemble_ir.c:511)
2 fastspin 0x000000010e6f210b IRAssemble + 139 (assemble_ir.c:569)
3 fastspin 0x000000010e6eb0af OutputAsmCode + 1023 (outasm.c:3841)
4 fastspin 0x000000010e6ce23c main + 5084 (fastspin.c:559)
5 libdyld.dylib 0x00007fff973d45ad start + 1`

I have tried to debug this problem with lldb and what I see is that that bit of code runs without issue through a number of iterations of parsing through the source until what I think is the last operand, before failing. Is the code perhaps falling through the end of the source? I have tried numerous lldb runs to determine where in source the parsing process is when the failure occurs but am not able to decipher that location.

Is it possible that the compiler (clang) version on Mac OS X 10.11.6 defines some variable at a different size, that may allow this issue to arise?

Possible buffer overrun?

I'm hitting an odd error here that looks like it could be a buffer overrun since it goes away when I stop using absolute paths.

david@balrog:~/reusable/Documents/Programming/PropellerProjects/PropWare/bin$ /usr/bin/spin2cpp --dat '/home/david/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound/audiosynth.spin'
WARNING: EOF seen inside comment
/home/david/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound/audiosynth.spin:552: syntax error
david@balrog:~/reusable/Documents/Programming/PropellerProjects/PropWare/bin$ cd '/home/david/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound'
david@balrog:~/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound$ /usr/bin/spin2cpp --dat audiosynth.spin 
david@balrog:~/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound$ ls audiosynth.*
audiosynth.dat  audiosynth.spin
david@balrog:~/reusable/Documents/Programming/PropellerProjects/PropWare/.external_downloads/propsideworkspace/Learn/Simple Libraries/Audio/libsound$ 

spin2cpp.c - array index out of bounds error

As compiled on os x:

spin2cpp.c:717:13: error: array index 3 is past the end of the array (which contains 3 elements) [-Werror,-Warray-bounds]
optchar[3] = 0;
^ ~
spin2cpp.c:713:13: note: array 'optchar' declared here
char optchar[3];
^
1 error generated.

FlexC ignores local var re-declaration

This code compiles without error:

#include "simpletools.h"

int  main()
{
  int f = 2;
  for (int i = 0; i < 10; i++)
  {
	print("f = %d\n", f);
	f += 1;
  }
  int f = 20;
  for (int i = 0; i < 9; i++)
  {
	print("f = %d\n", f);
	f += 10;
  }
  int f = 200;
  for (int i = 0; i < 9; i++)
  {
	print("f = %d\n", f);
	f += 100;
  }
}

I would have expected an error on the "int f = 20;" line and the "int f = 200;" line.
The above code outputs this:

f = 2
f = 3
f = 4
f = 5
f = 6
f = 7
f = 8
f = 9
f = 10
f = 11
f = 12
f = 22
f = 32
f = 42
f = 52
f = 62
f = 72
f = 82
f = 92
f = 102
f = 202
f = 302
f = 402
f = 502
f = 602
f = 702
f = 802
f = 902

So you can see it's just completely ignoring those lines with the re-declarations with assignments.
It works correctly if I fix the code to be proper, of course.

Error: Source operand too big for add

The attached application should (I think) work on the P2, but instead errors on compile.

Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.23 Compiled on: Mar 16 2019
Blinker2.spin
|-Output.spin
Blinker2.p2asm
Done.
./Blinker2.p2asm(129) error: Source operand too big for add
./Blinker2.p2asm(139) error: Source operand too big for add
./Blinker2.p2asm(149) error: Source operand too big for add
./Blinker2.p2asm(159) error: Source operand too big for add
./Blinker2.p2asm(169) error: Source operand too big for add
./Blinker2.p2asm(179) error: Source operand too big for add
./Blinker2.p2asm(189) error: Source operand too big for add
./Blinker2.p2asm(199) error: Source operand too big for add

Here's the source:
Blinker2 - Archive [Date 2019.03.22 Time 16.35].zip

Output filename not updating properly

When in pasm output mode with "make binary" checked if the compile fails then a different file is loaded/compiled the saved binary name for the new/working file is the name of the original/broken file.

fastspin & spin2cpp fails to assemble local PASM labels for P2

Local labels in PASM code cause an error, when building for P2. When building Phil Pilgrim's PWMx8.spin for P2, with fastspin (& spin2cpp), the following errors display:
$ fastspin -2 PWMx8.spin Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc. Version 3.9.14-beta-1162b0d3 Compiled on: Jan 2 2019 PWMx8.spin PWMx8.spin(140) error: syntax error, unexpected ':' PWMx8.spin(146) error: syntax error, unexpected ':' PWMx8.spin(155) error: syntax error, unexpected ':' PWMx8.spin(158) error: syntax error, unexpected ':' PWMx8.spin(163) error: syntax error, unexpected ':' PWMx8.spin(178) error: syntax error, unexpected ':' PWMx8.spin(180) error: syntax error, unexpected identifier pwmbits'
PWMx8.spin(181) error: syntax error, unexpected ':'
PWMx8.spin(190) error: syntax error, unexpected ':'
PWMx8.spin(194) error: syntax error, unexpected ':
`
From the Propeller Manual v1.2:

Local labels are similar to global separated from other same-named example:
labels except they start with a colon ‘:’ and must be local labels by at least one global label.

PWMx8.spin.zip

Also note: the error on line 180, where pwmbits gets an unexpected identifier error.

This code builds with fastspin & spinb2cpp for P1, without issue...

spin2pasm branch won't compile on Mac OS X

Although the master branch of spin2cpp builds on Mac OS X, the spin2pasm branch gives the following error(s) on 'make all':

$ make all
mkdir -p ./build
bison -t -b ./build/spin -d spin.y
spin.y:204.1-11: error: invalid directive: ‘%precedence’
spin.y:205.1-11: error: invalid directive: ‘%precedence’
make: *** [build/spin.tab.h] Error 1

No CASEs match

Hi Eric,

In the attached code, I'm calling the Line method with the 'c' parameter set to -1, but the case inside never seems to match. If I place some debugging code inside the method to print the value of c out to the display/terminal before the case block is evaluated, it shows c indeed equals -1. If I place that same debug code inside the -1 case, it never executes. If I comment out the case block completely, and just paste the code from the -1 case, the code executes properly. If I replace the case block with if..elseif (commented out therein), the code also executes.

Thanks!

display.gfx.bitmap.spin2.zip

Debian9/amd64/GCC built fastspin fails.

(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ git pull
Already up-to-date.
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ git log --max-count=1
commit 192b89c9c3ce491a32a81b1bd77a5a3b172d17d2
Author: Eric Smith <[email protected]>
Date:   Thu Jan 11 13:20:34 2018 -0400

    fixed a typo in the documentation
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ quiet make clean
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ quiet make || echo errors.
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ # so none...
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ cd /tmp
(yeti@kumari:12)/tmp$ echo pub main >test.spin
(yeti@kumari:12)/tmp$ /opt/spin2cpp/src/spin2cpp/build/fastspin test.spin       
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2016 Total Spectrum Software Inc.
Version 3.6.4 Compiled on: Mar 17 2018
test.spin
Segmentation fault

My default CC is Debian9's current GCC:

(yeti@kumari:12)/tmp$ gcc -v |& tail -1
gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) 

Building with make CC=clang...

(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ quiet make clean
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ quiet make CC=clang
(yeti@kumari:12)/opt/spin2cpp/src/spin2cpp$ cd /tmp
(yeti@kumari:12)/tmp$ /opt/spin2cpp/src/spin2cpp/build/fastspin test.spin 
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2016 Total Spectrum Software Inc.
Version 3.6.4 Compiled on: Mar 17 2018
test.spin
Done.
Program size is 328 bytes

...yields a working fastspin.

A fastspin binary built on Debian8 with GCC works on Debian9 too.


Edit 20170317-1251-GMT: Maybe similar to #24.

Make C/C++ inline assembly more legible by adding whitespace

What do you think about adding lots of whitespace to the end of every inline-assembly line? Make this:

"       .section .FullDuplexSerial.cog, \"ax\"\n"
"       .equ    EOL, $a\n"
"       .compress off\n"
"..start\n"
"       .org    0\n"
"\n"
"entry\n"
"       mov t1, PAR\n"
"       add t1, #(4 << 2)\n"
"       rdlong  t2, t1\n"
"       mov rxmask, #1\n"
"       shl rxmask, t2\n"

become this

"               .section .FullDuplexSerial.cog, \"ax\"                    \n"
"               .equ    EOL, $a                                           \n"
"               .compress off                                             \n"
"..start                                                                  \n"
"               .org    0                                                 \n"
"                                                                         \n"
"entry                                                                    \n"
"               mov     t1, PAR                                           \n"
"               add     t1, #(4 << 2)                                     \n"
"               rdlong  t2, t1                                            \n"
"               mov     rxmask, #1                                        \n"
"               shl     rxmask, t2                                        \n"

This copy/paste exercise has also made me aware that tabs are being used in the inline assembly section instead of spaces. I suspect changing that would be a prereq, or else trying to line up the newline and closing quote characters at the end of the lines won't be possible on different editors.

Using getcnt() builtin function for fastSpin BASIC gives compile error: Expected integer type for parameter of operator

The following .bas program fails to build in fast spin:
`rem simple program to toggle a pin
const pin = 16

let mscycles = clkfreq / 1000
direction(pin) = output

do
output(pin) = not output(pin)
pausems 1000
loop

sub pausems(ms)
waitcnt(getcnt() + ms * mscycles)
end sub`

$ fastspin fsTest.bas Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc. Version 3.9.5-beta Compiled on: Oct 2 2018 fsTest.bas fsTest.bas(15) error: Expected integer type for parameter of operator

This fails for P1 and P2 ("-2" option)...

For P1, getcnt() can be replaced with "cnt", similar to .spin, but that fails with the "-2" option...

$ fastspin fsTest.bas Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc. Version 3.9.5-beta Compiled on: Oct 2 2018 fsTest.bas fsTest.pasm Done. Program size is 572 bytes
$ fastspin -2 fsTest.bas Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc. Version 3.9.5-beta Compiled on: Oct 2 2018 fsTest.bas fsTest.bas(16) error: Expected integer type for parameter of operator

`rem simple program to toggle a pin
const pin = 16
let mscycles = clkfreq / 1000
direction(pin) = output

do
output(pin) = not output(pin)
pausems 1000
loop

sub pausems(ms)
REM waitcnt(getcnt() + ms * mscycles)
waitcnt(cnt + ms * mscycles)
end sub`

spinconvert does not allow non-constants in "dirA[range_start..range_end]"

Using a local var or var that was a parameter to a function inside DirA[range_start..range_end] causes the following failure:

spin2cpp --noheader -g --asm --code=cog --data=hub -o {/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.pasm} {/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.spin}
/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.spin:80: error: Symbol in1 is not constant
/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.spin:80: error: Symbol in4 is not constant
/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.spin:80: error: Symbol in4 is not constant
/Users/altergator/PropSpinCode/Avoid Objects/Avoid Objects.spin:80: error: Symbol in1 is not constant

Example code (from: Duane Degn's "Avoid Object.spin"):

PUB TwoStepper (in1,in2,in3,in4,in5,in6,in7,in8,direction,cycles) | pos0,pos1

  if direction == 1
     pos0:=0
     pos1:=3
  if direction == 0
     pos0:=3
     pos1:=0

  BitPattern[ 0 ] := %1100 '%1000
  BitPattern[ 1 ] := %0110 '%1100
  BitPattern[ 2 ] := %0011 '%0100
  BitPattern[ 3 ] := %1001 '%0110

  DirA[ in1..in4 ] := %1111                       ' FAILS
  DirA[ in5..in8 ] := %1111                       ' FAILS
  repeat cycles
    repeat count from pos0 to pos1 
      OutA[ in1..in4 ] := BitPattern[count]
      Outa[ in8..in5 ] := BitPattern[count]
      waitcnt(cnt+(clkfreq>>8))

PASM output lacks a pub

There should at least be an option to produce the

pub main
   coginit(0, @entry, 0)

that openspin and probably other spin compilers need to compile the PASM output.

Error: Request for member...

Here's an example where fastspin fails to compile an existing Spin application.

It appears to fail on an object constant reference: pst#CS

Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.23 Compiled on: Mar 16 2019
StackLengthDemoModified.spin
|-Stack Length.spin
|-|-Parallax Serial Terminal.spin
C:/Temp/_propeller_experiments/fastspin/Library/Stack Length.spin(70) error: request for member cs in something not an object
C:/Temp/_propeller_experiments/fastspin/Library/Stack Length.spin(70) error: request for member cs in something not an object

Here's an archive of the files involved:
StackLengthDemoModified - Archive [Date 2019.03.22 Time 13.52].zip

Called spin2 method doesn't return

HexToStr-Test.zip
In the attached test (top-level object is HexToStr-Test.spin2), the called method HexToStr should return the address of a VAR and the program should print out the number given in hex, but it never seems to return and the program hangs there. However, if some debugging output is added to the method (anywhere), the method then functions properly and returns.
I don't know enough PASM to fully understand the produced p2asm, but without the printf, there's no code generated that looks stack-related (push, pop), whereas if the printf is included, there's this code (among a few other additional lines) produced at the beginning of the subroutine:

mov COUNT_, #7
calla #pushregs_

and at the end:

calla #popregs_

BTW the code is actually an excerpt of a child object in the archive, string.integer.spin2, which is a port of Parallax's original Simple_Numbers.spin from the Propeller Tool lib.

Any ideas? Are there better spin2-specific ways of doing anything that stand out to you?
Hope you're feeling better!

spinconveri (spinpasm) should handle 'reboot' symbol as does C & C++

Just another unhandled-by-PASM issue... Appears that reboot is not handled only for PASM. C & C++ work!

code (from Cluso's demo code for P8XBlade2/CpuBlade7):

  if (ina[3] ==1)
    reboot

output:

spin2cpp --noheader -g --asm --code=cog --data=hub -o /Users/altergator/PropSpinCode/LEDOnOffCluso/cylonLED.pasm /Users/altergator/PropSpinCode/LEDOnOffCluso/cylonLED.spin
/Users/altergator/PropSpinCode/LEDOnOffCluso/cylonLED.spin:32: error: Symbol reboot is of a type not handled by PASM output yet
child process exited abnormally

multiple return values

Can you please have a look at this?

$ cat multi-assign-demo.spin 
con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "SimpleSerial.cog"

pub main | ix,xi

  ser.__cognew
  ser.start(115200)

  ix,xi := mad

  ser.dec(ix)
  ser.tx("/")
  ser.dec(xi)
  ser.tx(13)
  ser.tx(10)

  waitcnt(clkfreq+cnt)
  ser.__cogstop

pub mad : x,y
  x := 13
  y := 31
$ make
/opt/spin2cpp/bin/fastspin -O multi-assign-demo.spin
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.8.0 Compiled on: May 17 2018
multi-assign-demo.spin
|-SimpleSerial.cog.spin
multi-assign-demo.spin:13: error: Expected multiple values
multi-assign-demo.spin:13: error: Not enough elements on right hand side of assignment
Makefile:8: recipe for target 'multi-assign-demo.binary' failed
make: *** [multi-assign-demo.binary] Error 1

Changing the definition of mad...

$ cat multi-assign-demo.spin 
con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "SimpleSerial.cog"

pub main | ix,xi

  ser.__cognew
  ser.start(115200)

  ix,xi := mad(0)

  ser.dec(ix)
  ser.tx("/")
  ser.dec(xi)
  ser.tx(13)
  ser.tx(10)

  waitcnt(clkfreq+cnt)
  ser.__cogstop

pub mad(d) : x,y
  x := 13
  y := 31
$ make
/opt/spin2cpp/bin/fastspin -O multi-assign-demo.spin
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
Version 3.8.0 Compiled on: May 17 2018
multi-assign-demo.spin
|-SimpleSerial.cog.spin
multi-assign-demo.pasm
Done.
Program size is 1916 bytes
/opt/spinsim/bin/spinsim multi-assign-demo.binary -b | tee multi-assign-demo.log
13/31

...this really has driven me mad until I had the idea with the dummy parameter for mad...

Fastspin segfaults when an enum used in a struct

Fastspin 3.9.23 segfaults when compiling a C file where an enum is used in a struct.

Code that triggers the segfault:

enum SomeEnum { V1, V2 };

struct SomeStruct {
  enum SomeEnum e;
};

int main(void) {}

Fastspin invoked as follows: fastspin -2 -O2 bug.c produces the following output

$ fastspin -2 -O2 bug.c
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.23 Compiled on: Mar 17 2019
bug.c
fish: “fastspin -2 -O2 bug.c” terminated by signal SIGSEGV (Address boundary error)

Fastspin was built with GCC 8.3.1 on Fedora 29

*.o needs depenency on `spin.tab.h`

The makefile needs a dependency added on spin.tab.h so that it can be reliably run with parallel jobs. Specifically, line 78. Without the dependency, it is possible to begin compiling some of the source code prior to spin.tab.h being generated.

error: Internal Error: emitting move to immediate

Hi Eric,

When building the attached (top-level object is LEDMatrix1.spin2), fastspin aborts with the subject error. Bisecting finds this issue was introduced in 33caf96

I find that a workaround is to change line 209 of display.gfx.bitmap.spin2 from -1 to TRUE, and the source builds successfully.

Any ideas if this is a bug or a feature? :)

Thanks!
Jesse
LEDMatrix1.zip

Chip Cracey's VGA Driver v1.1 crashes spin2cpp when building for Pasm

When building VGA Driver v1.1 (from Parallax website, ChipsVGADriver.spin) as C or C++, I get success ( basically just builds the DAT assembly part into a static uint8_t dat[] = { ..} ) in my C or C++ files. But, when building as Pasm, spin2cpp crashes with a segmentation fault on Mac OS X v10.11.4.

The crash appears at the function PrintOperandAsValue, on line 93 of p1ir.c:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   spin2cpp                        0x0000000100f697d0 **PrintOperandAsValue + 16 (p1ir.c:93)**
1   spin2cpp                        0x0000000100f6a355 P1AssembleIR + 2517 (p1ir.c:447)
2   spin2cpp                        0x0000000100f6a94a IRAssemble + 106 (p1ir.c:480)
3   spin2cpp                        0x0000000100f648b3 OutputAsmCode + 755 (outasm.c:3359)
4   spin2cpp                        0x0000000100f4a8e0 main + 5600 (spin2cpp.c:1334)
5   libdyld.dylib                   0x00007fff8533c5ad start + 1

The full Mac OS X crash result:
spin2cppCrash.txt

A .zip of the Spin source:
ChipsVGADriver.spin.zip

It would be interesting if spin2cpp crashes on this same file on Windows...

VGA_HiRes_Text.spin breaks spin2cpp

nice work, but:

The (pretty amazing) VGA_HiRes_Text.spin that is one of the standard objects gives spin2cpp a bit of trouble.

copies available lots of places:
https://github.com/alamorobotics/W65c816_VGA/blob/master/VGA_HiRes_Text.spin
http://www.brielcomputers.com/files/VGA_HiRes_Text.spin
http://obex.parallax.com/object/650
https://github.com/parallaxinc/spin-standard-library/blob/master/library/display.vga.text.hires.spin

  1. spin2cpp --asm VGA_HiRes_Text.spin SEGV's.

  2. spin2cpp --gas VGA_HiRes_Text.spin does not produce a compilable file, as the
    assembly overflows the 9 bit offsets. this is probably because org does not work on gas
    like it does on pasm.

  3. spin2cpp --gas --dat VGA_HiRes_Text.spin hangs in an infamous loop.

all this on mac and linux (64) using the current source.

spin2cpp with --asm should handle spr[..] (Special Purpose Register Array) expression

spin2cpp with --asm option cannot handle the Special Purpose Register array of Spin. C & C++ builds work, but not PASM... Should be a simple fix as SPR array elements exist in PASM already, just need to relate them to the str array elements.

Source:
temp := spr[8+module] ' Copy existing CTR register

Error:
SquareWave.spin:32: error: Cannot handle expression yet

Prop Manual SPR Details:
spr

listing file problems

labels show up on the last line of hex output rather than first

label at end of file doesn't show up at all

spinconvert should allow lib file input from other than the current source directory

I keep all/most of my spin library files in a single directory. spin2cpp allows the "-I" option to declare directories where those libs can be found. spinconvert should be able to assist in declaring directories for libraries and then passing those declarations on to spin2cpp.

The following code gives an error when the file "I2C_ROMEngine.spin" is not in the same directory as the current source:

OBJ
    ROM:     "I2C_ROMEngine"

the error:

spin2cpp --noheader -g --normalize --code=cog --data=hub -o
/Users/altergator/PropSpinCode/clearMem.cpp
/Users/altergator/PropSpinCode/clearMem.spin
I2C_ROMEngine: No such file or directory
child process exited abnormally

[Q] Multi assign in e.g. CON sections too?

After adding multi value assigning and multi value returns from functions in v3.8.0 allowing the same in constant definitions looks like a logical extension.

Are there reasons not to do this?

spin2cpp --asm error "CogInit target must be in hub memory" on Propeller BOE ADCTest code

This project (ADCTest for Propeller BOE downloaded from Parallax) fails to build as PASM, but builds fine for C & C++.

With the --asm option of spin2cppm this fails on the line: "success := cog := (cognew(AdcLoop(chlist), @stack) + 1)" inside the file "PropBOE ADC.spin" which is an object used by the ADCTest.spin file (see the attached ADCTest.zip file for all project files).

Unzip the following and open ADCTest.spin with spinconvert.tcl, set Options to "Pasm Output":
ADCTest.zip

Result:

spin2cpp --noheader -g --asm --code=cog --data=hub -o ADCTest.pasm ADCTest.spin
PropBOE ADC.spin:86: error: Coginit target must be in hub memory
child process exited abnormally

Running binary does not work on Propeller Chip - 40-Pin DIP Chip

I tested a blink.spin which blinks LED and uploaded it to the Propeller 40 pin DIP chip using the Prop USB plug and it blinks the LED just fine. But running the .binary file does not seem to work after I transform the file blink.spin to blink.binary. The upload is fine but nothing happens once the blink.binary is uploaded. Does the Propeller Chip 40 pin DIP not support Propeller C? I originally tried getting this to work in SimpleIDE using C code and it had the same problem so it led me down to this path.

size modifiers not supported in DAT section

DAT
byte long $aa, $bb

should produce some byte aligned data. openspin, homespun, and bstc differ as to what should be produced: openspin produces $aa, $00, $00, $00, $bb, $00, $00, $00 whereas homespun and bstc produce $aa, $00, $00, $00, $bb.

Spin2cpp failing to convert Scribbler S3 code

Scribbler Default V2579.zip

I ran spin2cpp over each of the source files in the attached zip: find . -name '*.spin' -exec spin2cpp --gas {} \;.

This fails on scribbler_test.spin, first at line 121:

david@balrog:~/Desktop/S3 Open Source/Software$ find . -name '*.spin' -exec spin2cpp --gas {} \;
./scribbler_test.spin:121: error: Unknown symbol TEST_LED
./scribbler_test.spin:121: error: Unknown symbol TEST_LED

It seems to require that TEST_LED be defined before its usage on 121. I moved it up above it's usage on 121 and life is good. Upon trying to rerun spin2cpp over the file, I get a new error:

david@balrog:~/Desktop/S3 Open Source/Software$ spin2cpp --gas scribbler_default.spin 
scribbler_test.spin:1365: error: expected identifier after '.'
scribbler_test.spin:1366: error: expected identifier after '.'
scribbler_test.spin:1367: error: expected identifier after '.'

At this point, C++ source code is generated, but is faulty. The original Spin on lines 1365-1367 is

    print_dec_word(constant(GRAPH_COL_START+9),constant(TOP_MARGIN+1),left[index] := scribbler.light_sensor_raw(scribbler#LEFT))     
    print_dec_word(constant(GRAPH_COL_START+9),constant(TOP_MARGIN+2),center[index] := scribbler.light_sensor_raw(scribbler#CENTER))
    print_dec_word(constant(GRAPH_COL_START+9),constant(TOP_MARGIN+3),right[index] := scribbler.light_sensor_raw(scribbler#RIGHT))           

But the generated C++ does not pass the scribbler#LEFT parameter to the light_sensor_raw() method:

    print_dec_word(0x9, 0x5, (left[index] = scribbler.light_sensor_raw()));
    print_dec_word(0x9, 0x6, (center[index] = scribbler.light_sensor_raw()));
    print_dec_word(0x9, 0x7, (right[index] = scribbler.light_sensor_raw()));

include/libc.a

Is there a reason that libc.a is checked into the spin2cpp/include directory?

Enhancement request: spin2cpp flag '-f' list #included files as well?

@totalspectrum
I noticed this handy flag today:
[ -f ] output list of file names

Would it be practical to add support for adding files to that list that are included by the preprocessor (or is there a way to switch that on, currently?). This flag is handy for writing a script to package up everything into an archive, but it misses #included files. Low-priority request as it isn't something I use very often.

Thanks!

Error: illegal array reference

Here's another example where fastspin fails to compile an existing Spin application.

Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.23 Compiled on: Mar 16 2019
SingingDemoSeven.spin
|-VocalTract.spin
|-StereoSpatializer.spin
./SingingDemoSeven.spin(88) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//VocalTract.spin(122) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//VocalTract.spin(122) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//VocalTract.spin(125) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//VocalTract.spin(125) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(110) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(110) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(110) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(110) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(111) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(111) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(113) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(113) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(113) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(113) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(114) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(114) error: illegal array reference
C:/Temp/_propeller_experiments/fastspin/Library//StereoSpatializer.spin(114) error: illegal array reference

Here's an archive of the files involved:
SingingDemoSeven - Archive [Date 2019.03.22 Time 14.31].zip

DAT array with negative constant

spin2cpp v1.91 on OS X 10.9.5, but should go for any OS:

Write a valid declaration:

DAT
buf byte -1[100]

throws an error message: syntax error
The translator chokes on the negative constant

Problem solved:

spin.y 867a868,879

| '-' integer '[' expr ']'
{
AST *op = $2;
op->d.ival = -op->d.ival;
$$ = NewAST(AST_EXPRLIST, NewAST(AST_ARRAYDECL, op, $4), NULL);
}
| '-' float '[' expr ']'
{
AST *op = $2;
op->d.ival ^= 0x80000000U;
$$ = NewAST(AST_EXPRLIST, NewAST(AST_ARRAYDECL, op, $4), NULL);
}

spin: return value not passed if inline expression given

Hi Eric @totalspectrum
I'm finding return behaves a little differently using fastspin vs openspin.
In my method below:

PUB AutoRetransmitCount(tries) | tmp
' Setup of automatic retransmission - Auto Retransmit Count
' Defines number of attempts to re-transmit on fail of Auto-Acknowledge
'   Valid values: 0..15 (0 disables re-transmit)
'   Any other value polls the chip and returns the current setting
    readReg (core#NRF24_SETUP_RETR, 1, @tmp)
    case tries
        0..15:
        OTHER:
'            return (tmp & core#BITS_ARC)    ' <- Using return with an inline expression returns 0 (yields expected return value using OpenSpin)
            result := (tmp & core#BITS_ARC)  ' Pre-defining result and returning on the next line yields the expected return value
            return
    tmp &= core#MASK_ARC
    tmp := (tmp | tries) & core#NRF24_SETUP_RETR_MASK
    writeReg (core#NRF24_SETUP_RETR, 1, @tmp)

in the OTHER case, if I attempt to return an expression, nothing is returned, but if I pre-define a variable with the expression, and return that variable (or just return, if the variable is defined as the return var in the method definition line), the expected value is returned.
Is this expected behavior or do you think it's a bug? It's dead simple to work around, either way.
This is in a child object, in case it's significant. EDIT: Also, this is spin2 on a P2.

Thanks!
Jesse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.