Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FOOP (Fake Object Oriented Programming)
08-10-2012, 09:33 PM, (This post was last modified: 08-10-2012, 09:34 PM by regis.)
Exclamation  FOOP (Fake Object Oriented Programming)
As far as I know, there's no C++ open source Compiler for 8-bit PIC from Microchip.
Therefore, Pinguino IDE (Python) has to translate C++ Arduino-like syntax (eg. Serial.begin) into C (eg. serial_init). The translation is quite heavy (many libraries with many functions) for the system so we thought (thanks to one of our Pinguino 32 users) we could make some simple FOOP (see the title for explanation) with SDCC.
Here below, you will find an example (this time with GCC just to test it on a computer) how we could do. Do we have to go further ? Is there a better way ? Feel free to give your opinion.
Thank you.

#include <stdio.h>

// Prototypes
void print(char *, int);
void begin(void);

// Class
typedef struct
    void (* begin) (void);
    void (* print) (char *, int);
} serial;

// Constructor
serial new(void)
    serial s;
    s.begin = begin;
    s.print = print;
    return s;

// Functions
void begin(void)
    printf("initialization ...\r\n");

void print(char *tab, int lng)
    char mach[80];
    int i;

    for (i=0; i<lng; i++)
       mach[i] = *tab;

int main(void)
    serial myserial = new();
    char mystr[]={'S','A','L','U','T'};

    return 0;
It is easier to complain than it is to do, but it is better to do than it is to complain.
08-10-2012, 11:33 PM, (This post was last modified: 08-10-2012, 11:33 PM by pingotg.)
RE: FOOP (Fake Object Oriented Programming)
So you'd swap some compile-time work for continual runtime overhead (increased size and reduced speed)?

Sounds unattractive (except I don't use 8-bit Pinguino so my vote really doesn't matter).

In case you plan on this for 32-bit please provide a way to avoid it.

Surely a faster pre-processing phase would be better, if the Python code is too slow.

09-10-2012, 04:29 AM,
RE: FOOP (Fake Object Oriented Programming)
I also don't know of any open-source C++ PIC 8bit compiler.

I don't see any problem in this pseudo solution, this kind of use is quite common.

But I have to say, in the first place, at least for me, parsing code using python seems to be the first problem...

But as always, at the end of the day the most important is something that can do the job Smile

Forum Jump:

Users browsing this thread: 1 Guest(s)