I'm adding some I2C support to arduino-ats and decided to look under the hood to see why the arduino prelude uses modified versions of CATS files, and see if it would be possible to use the standard prelude for ATS2. It looks like the primary reason for copying CATS files, is to remove code related to stdio and printing.
This leads to some questions about how enable the embedded developers at the end of the discussion of things I tried to get around the problem.
Some discussion of things I tried...
As an experiment, I forced the inclusion of the avr version of stdio.h and it creates errors because stderr/out/in are macros, and the avr toolchain seems to have a problem with nested macros. As an experiment, I changed the stdio.h to have these definitions:
extern struct __file *stdin; /* Standard input stream. */
extern struct __file *stdout; /* Standard output stream. */
extern struct __file *stderr; /* Standard error output stream. */
Which removes the error and leaves the following error:
/opt/ATS/ATS2-Postiats-0.2.2/prelude/CATS/integer.cats:980:55: error: expected ‘)’ before ‘(’ token
#define atspre_print_int(x) atspre_fprint_int(stdout, (x))
^
In case of spacing in the text, the ^ is at (x)
The code called from this generated code in the .c file:
ATSextern()
atsvoid_t0ype
atspre_print_int(atstkind_t0ype(atstype_int) arg0)
{
/* tmpvardeclst(beg) */
// ATStmpdec_void(tmpret80) ;
ATStmpdec(tmpref81[32], atstkind_t0ype(atstype_byte)) ;
I assume the compiler is bumping into a similar nested macro problem.
Back to the real question.
Stdio is not something always available when you are dealing with bare iron or RTOS based platforms, and often it is senseless. So I am asking how might this be addressed? My thoughts are that faking out ATS with functions that are not needed is a poor approach. I think it would make more sense to have a #define to either turn off everything related to stdio, or allow for user definitions, or both. Another approach might be to factor out the code into one file/interface so that an application can simply not include it.
In general, I think coupling any core libraries to IO or an OS API will limit the user base, if those libraries are essential to quick success.
Thoughts?
Mike