Trying to compile some Gameduino code and get an error on this:
class xy {
public:
int x, y;
void set(int _x, int _y);
void rmove(int distance, int angle);
int angleto(class xy &other);
void draw(byte offset = 0);
void rotate(int angle);
int onscreen(void);
class xy operator<<=(int d);
class xy operator+=(class xy &other);
class xy operator-=(class xy &other);
long operator*(class xy &other);
class xy operator*=(int);
int nearer_than(int distance, xy &other);
};
Doesn't like the operator stuff. I imagine that is not implemented, right?
Hopefully, I can rewrite that as a function like:
Eric, I am inputting a line (string) from the command line (w10) terminal and I need my routine to cater for <bs> to edit the line before acceptance/enter. However, the <bs> character is just displaying a character (sort of a house like character) for the <bs> character.
Is there another character or sequence I can use to either move the cursor left or perform a backspace?
Solved. The <bs> is returned as a $7F from the terminal instead of $08. $08 performs a backspace, so the sequence $08,$20,$08 performs a destructive backspace.
So here is my solution
Print.fstr0(string("SD:>")) ' prompt
addr := @commandLine
repeat
ch := Print.rx() ' waits for an input char
if (ch == $08 or ch == $7F) ' <bs> ? (doesn't work in command line terminal!)
ch := $08 ' force <bs>
addr--
if addr < @commandLine ' <bs> and empty buffer?
addr := @commandLine ' y: so back to start of buffer
else
Print.tx(ch) ' <bs>
Print.tx(" ") ' <space>
Print.tx(ch) ' <bs>
else
byte[addr++] := ch ' store char
Print.tx(ch) ' echo
while ch <> _cx._carriageReturnCharacter
Print.tx(_cx._lineFeedCharacter) ' <lf>
byte[addr] := 0 ' store terminating 0
1>Version 5.0.1 Compiled on: Nov 28 2020
1>helloworld.cc
1>GD2.h:721: error: syntax error, unexpected static
I see "static" being using in c.md, so not sure what's going on...
Look on the previous line, that's probably where the error is. flexcc certainly does understand "static", but if it's confused by earlier errors then it might not expect the static where it actually sees it.
Ah, it might be that this declaration is inside a class? If so, flexcc doesn't support static member functions yet ("static" means something quite different in a class).
FlexProp 5.0.3 is available now from the usual places (links are in my signature and in the first post in this thread). There are some Changelog files listing the changes; mainly these are bug fixes, except that:
- loadp2 now accepts a -RTS flag to use RTS for reset instead of DTR
- FlexBasic has a new reserved word, 'private', which isn't used yet but will eventually allow for private methods in classes
Question about the "class" construct using "typedef struct"...
Should it be able to access global variables?
I have x, y, and vxf defined globally, but I get an "unknown symbol" error on this unless they are present in the structure:
typedef struct PolyStruct {
int x0, y0, x1, y1;
int x[8], y[8];
byte n;
int w; //RJA added these locally as FlexSpin does not recognize global variables in this "class"
int h;
byte vxf; // Vertex Format
void restart() {
n = 0;
x0 = (1 << vxf) * w;
x1 = 0;
y0 = (1 << vxf) * h;
y1 = 0;
}
Question about the "class" construct using "typedef struct"...
Should it be able to access global variables?
It "should" in the sense that that's the way it really ought to work. But right now it won't, because in FlexProp the structures are like independent Spin objects and so can't reference global variables. I hope to fix this, but don't have a timeline for it.
int main()
{
int i;
int mask;
int x;
mask = 0x07 << 24;
x = 0;
while (1)
{
__asm volatile {
modz 0 wz
setpat mask, mask
waitpat
mov i, ina
modz 1 wz
setpat mask, mask
waitpat
}
i = i >> 24;
i = i & 0x07;
if ((i & 2) == 0) <-- this doesn't work over optimized
x++;
if ((i & 4) == 0)
x--;
if ((i & 1) == 0)
x = 0;
printf("Count: %d %x\n", x, i & 1);
}
while (1)
{
_waitms(1000);
}
}
Wow, that's a really bad one -- the peephole optimizer has a serious flaw in its AND/TEST optimization. I'm surprised it hasn't shown up earlier. It's fixed now in github.
Thanks for the bug report!
I've released version 5.0.4, which has a number of compiler bug fixes (including a fix for the optimizer bug @iseries mentioned above). It's available at both my patreon page and at github (see my signature or the first post in this thread).
All the source is available in the github flexprop repository... https://github.com/totalspectrum/flexprop
As ersmith stated, you can easily build the whole project (i.e. GUI, all the binaries for compiling & loading) on WIN10, Linux, macOS...
I suggest (on Linux or macOS) something like:
$ mkdir source
$ cd source
$ git clone --recursive https://github.com/totalspectrum/flexprop.git
$ cd flexprop
$ make clean # only if you had previously run make
$ make install
Note: '--recursive' allows git to include all of the projects sub-modules (PropLoader, loadp2, & spin2cpp).
If successful, you'll find a new flexprop directory in your home directory, where you'll find the flexprop.tcl GUI, tools & sample code:
$ cd ~/flexprop
$ ls
License.txt bin doc include src
README.md board flexprop.tcl samples
$ ls bin
fastspin flexcc flexspin loadp2 mac_terminal.sh proploader
Use flexprop.tcl if you like or the tools in the bin directory from the Linux/macOS command line. It's "all there".
Note: flexprop may have some requirements for successful building... If make install does not work, you can probably get help here in the forum...
dgately
Wuerfel, Dgately,
Thanks! this got it working for me (With a couple of side trips, easily solved with a search in the Ubuntu forum...)
I presume that cloning flexprop got me the latest, greatest, right? What would I do when new versions are released? would it be best to follow this process, or just unzip the new zip file over it?
You can just do all that again. In theory you should also be able to just "git pull" the latest changes, but IDK how to do it properly when submodules are involved...
I presume that cloning flexprop got me the latest, greatest, right? What would I do when new versions are released? would it be best to follow this process, or just unzip the new zip file over it?
On my system (my disclaimer), with the loadp2 & spin2cpp sub-modules, a "git pull" within the flexprop directory, has NOT given me a full update. Not sure if this is something to do with my own macOS system, but here's a sure fire way to get updates and build flexprop on macOS & Linux systems:
$ cd flexprop/spin2cpp
$ git pull
... <== resultant git stuff
$ make clean
...
$ make
... <== resultant build stuff, hopefully successful
$ cd ../loadp2
$ git pull
$ make clean
$ make
... <== reluctant build stuff, hopefully successful
$ cd ../ <== back to flexprop directory
$ git pull
$ make clean
...
$ make install
... <== hopefully successful
$ cd ~/flexprop <== should now be ready to execute ./flexprop.tcl
When I previously just exec'd git pull at flexprop's top directory, spin2cpp & loadp2 did not get updated. Maybe there's a missing option (like: "--recursive") that is needed for git pull... I'm not aware of one.
cd source/flexprop
git pull
git submodule update
make clean
make install
should update both the main flexprop and also all submodules (spin2cpp, loadp2, etc.), and then rebuild everything. I have found that the "make clean" seems to be necessary, some dependency isn't quite correct.
FlexProp version 5.0.5 is available now. Changes are detailed in docs/Changelog*.txt. The GUI has tooltips that pop up when you hover over the file name tabs to show the full file name (they're a little bit finicky, so you may have to leave the tab and go back into it a few times to get them to work). The compiler has a few minor bug fixes, including adding some missing EVENT_* symbols for Spin2 and a better procedure for loading objects with no explicit file extension.
For Spin2 in PropellerTool and PNut, getms() is defined, while in flexprop _getms() is defined, which makes it difficult to compile code "as is" between the 2 different compilers/IDEs. Should flexprop provide an alias getms() to _getms()?
We found this during one of JonnyMac's P2 presentations, using example code he had written with PropellerTool 2.4.1.
For Spin2 in PropellerTool and PNut, getms() is defined, while in flexprop _getms() is defined, which makes it difficult to compile code "as is" between the 2 different compilers/IDEs. Should flexprop provide an alias getms() to _getms()?
I didn't realize that Chip had added getms. It's fixed in github now. Thanks!
I've released FlexProp version 5.0.6 on my Patreon page. A public release will follow later this week.
Compiler changes:
- Added cog_* functions from libsimpletools
- Added get_directions() and get_outputs() functions from simpletools
- Added getms() in Spin2
- Documented _pinstart() function for C
- Fixed an off-by-one in the BASIC INSERT$ function.
- Fixed errors in declarations of C modf() and frexp() functions.
- Fixed read() on terminal to break on newline if applicable
- Improved error messages for type mismatches.
- Made libsimpletext text read use _rxraw() to avoid echo.
GUI changes:
- Added links to Parallax documentation under Help menu
- Made help text for GUI wrap
- Removed search hilight when search window is closed
Comments
Doesn't like the operator stuff. I imagine that is not implemented, right?
Hopefully, I can rewrite that as a function like:
Update: Seems to be compiling as long as add the prefix "class" to all references to "xy"
This gives an error:
I am inputting a line (string) from the command line (w10) terminal and I need my routine to cater for <bs> to edit the line before acceptance/enter. However, the <bs> character is just displaying a character (sort of a house like character) for the <bs> character.
Is there another character or sequence I can use to either move the cursor left or perform a backspace?
Solved. The <bs> is returned as a $7F from the terminal instead of $08. $08 performs a backspace, so the sequence $08,$20,$08 performs a destructive backspace.
So here is my solution
Look on the previous line, that's probably where the error is. flexcc certainly does understand "static", but if it's confused by earlier errors then it might not expect the static where it actually sees it.
Ah, it might be that this declaration is inside a class? If so, flexcc doesn't support static member functions yet ("static" means something quite different in a class).
Probably won't work. You'll have to use C style like:
- loadp2 now accepts a -RTS flag to use RTS for reset instead of DTR
- FlexBasic has a new reserved word, 'private', which isn't used yet but will eventually allow for private methods in classes
Should it be able to access global variables?
I have x, y, and vxf defined globally, but I get an "unknown symbol" error on this unless they are present in the structure:
It looks OK to me -- I don't see any unnamed prototype parameters in that snippet. Is there another definition elsewhere in the class?
Think it works though...
Do I use _pinr(x) to read a pin?
Mike
Mike
Yes, for a regular pin. For smartpins use _rdpin.
Thanks for the bug report!
Wuerfel, Dgately,
Thanks! this got it working for me (With a couple of side trips, easily solved with a search in the Ubuntu forum...)
I presume that cloning flexprop got me the latest, greatest, right? What would I do when new versions are released? would it be best to follow this process, or just unzip the new zip file over it?
Thanks again!
dgately
Oops, sorry, yes it should have been "make install" rather than just "make". I'll fix the original post.
The binary has been up on my patreon page for a few days, but is now available to the public. It's also on github: https://github.com/totalspectrum/flexprop/releases.
In simpleIDE the function getStr(Buffer, 200) does not echo characters.
Your code aliased to safe_gets(text_t, Buffer, 200) does echo characters and I would get double if echo was turned on.
I think the code on this line should be changed from:
int ch = text ? text->rxChar(text) : _rx();
To:
int ch = text ? text->rxChar(text) : _rxraw();
Mike
We found this during one of JonnyMac's P2 presentations, using example code he had written with PropellerTool 2.4.1.
dgately
Compiler changes:
GUI changes: