Page 1 of 1

Compiling _stage.mpy

Posted: Wed Dec 25, 2019 7:33 pm
by deshipu
Hello,

I was very happy to see the native modules being added to release 1.12, as described at http://docs.micropython.org/en/latest/d ... atmod.html so I decided to go and try to compile my "stage" game library this way, because a lot of people wanting to use it are unable to compile their own firmware. I actually need to compile only a very small "_stage" helper module, that contains two classes for tile layers, and a simple function for rendering them and sending over SPI to the display. According to the documentation, it should be very simple.

So I started with my mod_stage.c (https://github.com/python-ugame/micropy ... od_stage.c) and replaced the module dict definition with the mpy_init function, as in the examples. I got _stage.c file: https://github.com/python-ugame/micropy ... y/_stage.c

So far so good. Next I created a simple Makefile based on the examples:

Code: Select all

MPY_DIR = ../../../micropython/micropython
ARCH = xtensa
MOD = _stage
SRC = _stage.c

include $(MPY_DIR)/py/dynruntime.mk
Unfortunately, running this results in a missing include "mphalport.h". A quick search in the MicroPython's code revealed, that there is no mphalport.h for the ESP8266, so I decided to try compiling for the ESP32 first. I added the include path to CFLAGS:

Code: Select all

CFLAGS += -I$(MPY_DIR)/ports/esp32/
this time it failed with some missing includes from esp-idf. I kept adding include directories, until I got to:

Code: Select all

MPY_DIR = ../../../micropython/micropython
ARCH = xtensawin
MOD = _stage
SRC = _stage.c

CFLAGS += \
	-I$(MPY_DIR)/ports/esp32/ \
	-I$(MPY_DIR)/ports/esp32/build \
	-I../../../micropython/esp-idf/components/freertos/include \
	-I../../../micropython/esp-idf/components/esp32/include \
	-I../../../micropython/esp-idf/components/driver/include \
	-I../../../micropython/esp-idf/components/soc/include \
	-I../../../micropython/esp-idf/components/soc/esp32/include \
	-I../../../micropython/esp-idf/components/heap/include \


include $(MPY_DIR)/py/dynruntime.mk
This time there is no include error, but instead I get several screenfuls of errors:

Code: Select all

CC _stage.c
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'text_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:171:22: error: initializer element is not constant
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
./build/_stage.config.h:171:22: note: (near initialization for 'mp_type_text.name')
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[1].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:170:23: error: initializer element is not constant
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
./build/_stage.config.h:170:23: note: (near initialization for 'mp_type_layer.name')
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
_stage.c:383:33: error: 'stage_module_globals' undeclared here (not in a function)
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                                 ^
_stage.c:383:16: error: initializer element is not constant
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                ^
_stage.c:383:16: note: (near initialization for 'mp_module__stage.globals')
_stage.c:387:19: error: unknown type name 'mp_obj_fun_bc_t'
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw,
                   ^
../../../micropython/micropython/py/dynruntime.mk:128: recipe for target 'build/_stage.o' failed
make: *** [build/_stage.o] Error 1
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ 
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ make
CC _stage.c
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'text_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:171:22: error: initializer element is not constant
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
./build/_stage.config.h:171:22: note: (near initialization for 'mp_type_text.name')
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[1].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:170:23: error: initializer element is not constant
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
./build/_stage.config.h:170:23: note: (near initialization for 'mp_type_layer.name')
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
_stage.c:383:33: error: 'stage_module_globals' undeclared here (not in a function)
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                                 ^
_stage.c:383:16: error: initializer element is not constant
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                ^
_stage.c:383:16: note: (near initialization for 'mp_module__stage.globals')
_stage.c:387:19: error: unknown type name 'mp_obj_fun_bc_t'
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw,
                   ^
../../../micropython/micropython/py/dynruntime.mk:128: recipe for target 'build/_stage.o' failed
make: *** [build/_stage.o] Error 1
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ make clean
/bin/rm -rf build 
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ make
GEN build/_stage.config.h
CC _stage.c
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'text_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:171:22: error: initializer element is not constant
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
./build/_stage.config.h:171:22: note: (near initialization for 'mp_type_text.name')
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[1].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:170:23: error: initializer element is not constant
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
./build/_stage.config.h:170:23: note: (near initialization for 'mp_type_layer.name')
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
_stage.c:383:33: error: 'stage_module_globals' undeclared here (not in a function)
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                                 ^
_stage.c:383:16: error: initializer element is not constant
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                ^
_stage.c:383:16: note: (near initialization for 'mp_module__stage.globals')
_stage.c:387:19: error: unknown type name 'mp_obj_fun_bc_t'
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw,
                   ^
../../../micropython/micropython/py/dynruntime.mk:128: recipe for target 'build/_stage.o' failed
make: *** [build/_stage.o] Error 1
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ make clean
/bin/rm -rf build 
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ 
sheep@ghostwheel:~/dev/ugame/micropython-stage/mpy$ make
GEN build/_stage.config.h
CC _stage.c
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'text_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:215:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&text_move_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:171:22: error: initializer element is not constant
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
./build/_stage.config.h:171:22: note: (near initialization for 'mp_type_text.name')
 #define MP_QSTR_Text (mp_native_qstr_val_table[1])
                      ^
_stage.c:221:13: note: in expansion of macro 'MP_QSTR_Text'
     .name = MP_QSTR_Text,
             ^
In file included from ../../../micropython/micropython/py/mpstate.h:35:0,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[0].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:287:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&layer_move_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: error: initializer element is not constant
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
../../../micropython/micropython/py/obj.h:92:30: note: (near initialization for 'layer_locals_dict_table[1].key')
 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
                              ^
../../../micropython/micropython/py/obj.h:248:24: note: in expansion of macro 'MP_OBJ_NEW_QSTR'
 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
                        ^
_stage.c:288:7: note: in expansion of macro 'MP_ROM_QSTR'
     { MP_ROM_QSTR(MP_QSTR_frame), MP_ROM_PTR(&layer_frame_obj) },
       ^
In file included from ../../../micropython/micropython/py/mpconfig.h:60:0,
                 from ../../../micropython/micropython/py/mpstate.h:31,
                 from ../../../micropython/micropython/py/runtime.h:29,
                 from _stage.c:28:
./build/_stage.config.h:170:23: error: initializer element is not constant
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
./build/_stage.config.h:170:23: note: (near initialization for 'mp_type_layer.name')
 #define MP_QSTR_Layer (mp_native_qstr_val_table[0])
                       ^
_stage.c:294:13: note: in expansion of macro 'MP_QSTR_Layer'
     .name = MP_QSTR_Layer,
             ^
_stage.c:383:33: error: 'stage_module_globals' undeclared here (not in a function)
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                                 ^
_stage.c:383:16: error: initializer element is not constant
     .globals = (mp_obj_dict_t*)&stage_module_globals,
                ^
_stage.c:383:16: note: (near initialization for 'mp_module__stage.globals')
_stage.c:387:19: error: unknown type name 'mp_obj_fun_bc_t'
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw,
                   ^
../../../micropython/micropython/py/dynruntime.mk:128: recipe for target 'build/_stage.o' failed
At this point I'm not sure how to proceed. Any suggestions?

Re: Compiling _stage.mpy

Posted: Wed Dec 25, 2019 9:17 pm
by deshipu
I figured that one out, you can't use any _ROM_ functions, so the creation of classes is a bit more involved and has to be done in the init funcvtion. The framebuf module is a good example of that.

However, now I'm getting:

Code: Select all

Traceback (most recent call last):
  File "../../../micropython/micropython/tools/mpy_ld.py", line 964, in <module>
    main()
  File "../../../micropython/micropython/tools/mpy_ld.py", line 961, in main
    do_link(args)
  File "../../../micropython/micropython/tools/mpy_ld.py", line 937, in do_link
    load_object_file(env, file)
  File "../../../micropython/micropython/tools/mpy_ld.py", line 595, in load_object_file
    if s.data_size == 0:
AttributeError: 'Section' object has no attribute 'data_size'

Re: Compiling _stage.mpy

Posted: Wed Dec 25, 2019 9:36 pm
by deshipu
The fight continues. After changing the "if s.data_size == 0:" line in mpy_ld.py to "if getattr(s, 'data_size', 0) == 0:" I get a new error. This time it can't find the symbol mp_obj_get_array, which is used in my code. What to do? The function is defined in py/obj.c, so I tried adding it to SRC. Unfortunately that gives me:

Code: Select all

$ make
GEN build/_stage.config.h
CC _stage.c
CC ../../../micropython/micropython/py/obj.c
../../../micropython/micropython/py/obj.c: In function 'mp_obj_print_exception':
../../../micropython/micropython/py/obj.c:96:30: error: 'MP_QSTRnull' undeclared (first use in this function)
                 if (block == MP_QSTRnull) {
                              ^
../../../micropython/micropython/py/obj.c:96:30: note: each undeclared identifier is reported only once for each function it appears in
../../../micropython/micropython/py/dynruntime.mk:128: recipe for target 'build/../../../micropython/micropython/py/obj.o' failed
make: *** [build/../../../micropython/micropython/py/obj.o] Error 1
which seems to be completely crazy?

Re: Compiling _stage.mpy

Posted: Sun Dec 29, 2019 4:20 pm
by deshipu
I gave it another go. This time I installed the latest version of python3-elftools, which "fixed" the AttributeError. However, I still get the symbol not found error for "mp_obj_get_array", which is, come to think about it, very suspicious, because other symbols from the py/obj.c are found without problems. Is there maybe some list of symbols somewhere that the dynamically loaded modules can use that is missing mp_obj_get_array in it perhaps?

Re: Compiling _stage.mpy

Posted: Sat Feb 01, 2020 1:13 pm
by deshipu
For anyone struggling with a similar problem, here is a missing piece of documentation: https://github.com/tve/micropython/comm ... dd114d4fae