First successful build

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
p-i-
Posts: 20
Joined: Sun Sep 14, 2014 2:24 pm

First successful build

Post by p-i- » Mon Sep 22, 2014 12:14 am

I have finally managed to get µPy to build in a generic C/C++ project. (I am on OSX/Xcode by the way).

Copy /micropython-master/py/*.{c,h} into my C++ project's source tree /myProj/uPy/py/

Next I get /micropython-master/unix/ to build, which creates /micropython-master/unix/build/genhdr/qstrdefs.generated.h which I also copy to /myProj/uPy/

Search /myProj/uPy/py/qstr.{c,h} for "qstrdefs.generated.h", and modify TWO #include-s to:

Code: Select all

#include "qstrdefs.generated.h"
Copy /micropython-master/bare-arm/mpconfigport.h -> /myProj/uPy/, and add at the top:

Code: Select all

#ifndef NULL
#define NULL 0
#endif

#define MICROPY_NLR_SETJMP (1)
I rename main.c -> foo.c and cut it down to a minimum:

Code: Select all

#include "mpconfig.h"
#include "nlr.h" // <-- port specific nlr_jmp_fail
#include "misc.h"
#include "qstr.h"
#include "lexer.h" // <-- port specific at bottom
//#include "parse.h"
#include "obj.h"
//#include "parsehelper.h"
//#include "compile.h"
//#include "runtime0.h"
//#include "runtime.h"
//#include "repl.h"


void gc_collect(void) {
}

mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
    return NULL;
}

mp_import_stat_t mp_import_stat(const char *path) {
    return MP_IMPORT_STAT_NO_EXIST;
}

mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) {
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open);

void nlr_jump_fail(void *val) {
}
I think that's everything. I get a ton of cast warnings, but 0 errors.

Tomorrow I will set about trying to get it up and running.

As far as I am aware from talking with dhylands, two further modifications are required:

1. implementing gc_collect so that it to(a) informs µPy of all external references C++-land holds on Python objects, so µPy doesn't garbage collect them and (b) prods µPy to do its own internal checking

2. implementing mp_builtin_open, so that µPy can open files, and #import will work

π

Post Reply