I'm trying to compile xlisp with flexcc and ran into a puzzling error. I've attached the two files required to reproduce this.
The command I used was:
flexcc -c xlapi.c -o xlapi.o
The errors are:
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:213: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:216: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:239: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:243: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:277: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:331: error: Array dereferences a non-array object
/Users/dbetz/Dropbox/xlisp/tmp/xlapi.c:373: error: Array dereferences a non-array object
Ah, that's a bug in flexC -- it was completely ignoring "extern" declarations, which is fine when everything is being compiled at the same time, but doesn't work for .o output where only one file is available initially.
I've updated spin2cpp so it shouldn't do this any more. It's very possible I've introduced a new bug with this though, since it's a fairly big change.
Thanks for the bug report, David!
I am trying to just build all of the sources at once and now I get this error:
/Users/dbetz/Dropbox/xlisp/include/xlisp.h:1306: error: global array xlosSubrTab declared with no size and no initializer
This refers to this line:
extern xlSubrDef xlosSubrTab;
This is supposed to work, of course -- it's another FlexC bug. For now the work-around would be to modify the definition to include a definite size for the array.
EDITED to add: I have checked in a hack to just ignore extern x declarations (which is what the compiler used to do, since it ignored all externs before). This should get you past that specific problem.
I added a size to those arrays and got past that problem for now. Unfortunately, I have another issue and I'm not really sure it's a FlexC bug. I have lots of functions that take char* arguments and I sometimes call them with literal strings. That results in this warning:
This is the offending line:
And this is the declaration of xlError:
I guess they should all be changed to accept const char* parameters but I haven't had to do that on any other compiler I've used.
Also, after a large number of this kind of warning I get this:
Then you haven't been enabling warnings
Any good compiler can and will warn you about things like that, but GCC in particular doesn't enable a lot of warnings by default.
My Makefile includes -Wall in CFLAGS for all compilations. Doesn't that enable all warnings?
That should enable that warning. IDK why it wouldn't work.
It seems that literal strings were originally of type char[n] but at some point that changed to const char[n]. I wonder what C standard gcc uses by default when none is specified?
Actually I think the C standard left the type of literal strings as "char", but also made it undefined behavior to modify them. Originally they were going to make them "const char" but that caused too many errors and people complained. I think C++ made it "const char" though.
In FlexProp I made it a warning because I think it is a useful thing to complain about (modifying a literal string is undefined behavior, after all, and leads to all kinds of unpleasantness). I guess I should make an option to turn that warning off.
I fixed all of the const char warnings and now I just get this:
I'm not sure where to go from here. I've attached the sources and the makefile I'm using. I invoke it with the command:
Hi David... I tried to build the xlisp-fastc, but the Makefile isn't included. It also seems to be missing some header files like "xlbcode.h". I was able to grab those from an older xlisp and reproduce the crash though (an uninitialized variable in a little used path of the compiler), and that fix is checked in now.
Oops. Sorry I forgot those two files. Here is a complete zip file. I'll try your fix later.
I updated my spin2cpp sources and rebuilt FlexC and I get a lot further. There are some runtime functions like atof and system that are not defined but I need to refactor xlisp to allow embedded builds that don't assume the existence of an extensive runtime library. FlexC still seems to have some problems with function pointers but they just generate warnings. The one warning I get that is puzzling to me is this one:
It's odd that it thinks val is used prior to its initialization since it is initialized in the first like of the function. Any idea why that might be happening? This is the complete function:
Also, I fixed the undefined symbols and was able to generate a binary file. It loads and starts to run but says it can't allocate enough memory. How large a heap does FlexC provide?
I've attached a zip file with sources. You can build them with this command:
and you can run the resulting program like this:
You will likely get this output:
I wrote the following simple program and the call to malloc failed. Are malloc/free implemented in FlexC?
malloc works up to about 4096 and then fails. Must be a stack issue.
Hmmm... xlisp needs a much bigger heap than that. I suppose I could just preallocate the heap for FlexC. I wonder why such a low limit?
I hate to say it, but RTFM: https://github.com/totalspectrum/spin2cpp/blob/master/doc/general.md#heap-size-specification
You're totally correct. Sorry for posting the question before checking the docs. I'll read them over later.
I increased my heap size and am getting some somewhat promising results. I only get a few warnings:
Here is an attempted run. The error seems to have to do with trying to load the initialization files but I am able to get a simple expression to evaluate correctly at the prompt:
Thank you for your bug reports. The type warnings are due to FlexC incorrectly parsing function pointer casts like (xlValue (*)(void)) as (xlValue *)... I'm not sure why that is, but since all pointers are the same size this shouldn't cause any code mis-compilation.
The use before set warning was bogus, of course, and due to a missing case in the check for whether a variable had been initialized. It should be fixed now.
Thanks for fixing the "set before use" warning. That gets rid of every warning except the ones related to function pointers. I'll look over my code to see if my implementation might be wrong. Thanks for your help!