Verified Commit 95f5050b authored by Rahix's avatar Rahix
Browse files

feat(pycardium): Enable frozen-module support



Closes #4.

Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent aea7b2db
#!/bin/bash
set -e
PYTHON="$1"
SOURCE_DIR="$2"
OUTPUT="$3"
QSTR_HEADER="$4"
shift 4
# We need the defs header, not the generated
QSTR_HEADER="$(dirname "$QSTR_HEADER")/qstrdefs.preprocessed.h"
"$PYTHON" "$SOURCE_DIR"/micropython/tools/mpy-tool.py \
--freeze \
--qstr-header "$QSTR_HEADER" \
-mlongint-impl longlong \
"$@" >"$OUTPUT"
#!/bin/bash
set -e
SOURCE_DIR="$1"
OUTPUT="$(realpath "$2")"
cd "$SOURCE_DIR"/micropython/mpy-cross
make -j "$(nproc)" >/dev/null
cp mpy-cross "$OUTPUT"
......@@ -17,6 +17,36 @@ micropython_gen_qstr = [
meson.current_source_dir(),
]
# mpy-cross
mpy_cross_bin = custom_target(
'mpy-cross',
output: 'mpy-cross',
build_by_default: true,
command: [files('gen-mpy-cross.sh'), meson.current_source_dir(), '@OUTPUT@'],
)
# seriously meson, this is retarded
mpy_cross_wrapper = executable(
'mpy-cross-wrapper',
'mpy-cross-wrapper.c',
link_depends: mpy_cross_bin,
native: true,
c_args: ['-DMPY_CROSS_PATH="' + meson.current_build_dir() + '"'],
)
mpy_cross = generator(
mpy_cross_wrapper,
output: '@BASENAME@.mpy',
arguments: ['-o', '@OUTPUT@', '-s', '@PLAINNAME@', '-march=armv7m', '@INPUT@'],
)
micropython_gen_frozen = [
files('gen-frozen.sh'),
python3,
meson.current_source_dir(),
]
# Sources
micropython_includes = include_directories(
'./micropython/',
......
#include <stdio.h>
#include <unistd.h>
#ifndef MPY_CROSS_PATH
#error "You need to define MPY_CROSS_PATH to compile this wrapper."
#endif
int main(int argc, char**argv)
{
char path[] = MPY_CROSS_PATH "/mpy-cross";
argv[0] = "mpy-cross";
execv(path, argv);
fprintf(stderr, "Failed to run '%s'!\n", path);
}
......@@ -36,6 +36,20 @@ qstr_h = custom_target(
mp_headers = [version_h, modules_h, qstr_h]
#################################
# Python Frozen Modules #
#################################
subdir('modules/py')
frozen_source = custom_target(
'frozen.c',
output: 'frozen.c',
input: [qstr_h, frozen_modules],
build_by_default: true,
command: [micropython_gen_frozen, '@OUTPUT@', '@INPUT@'],
)
###################
# MicroPython Lib #
###################
......@@ -52,6 +66,7 @@ elf = executable(
name + '.elf',
'main.c',
'mphalport.c',
frozen_source,
modsrc,
mp_headers,
include_directories: micropython_includes,
......
# Foo Module
def bar():
print("Hello from foo!")
X = 3.14
python_modules = files(
'foo.py',
)
frozen_modules = mpy_cross.process(python_modules)
......@@ -4,16 +4,15 @@
/* MicroPython Config Options */
/*
* Right now, we do not support importing external modules
* though this might change in the future.
*/
#define MICROPY_ENABLE_EXTERNAL_IMPORT (0)
/* We raise asynchronously from an interrupt handler */
#define MICROPY_ASYNC_KBD_INTR (1)
#define MICROPY_KBD_EXCEPTION (1)
/* Enable precompiled frozen modules */
#define MICROPY_MODULE_FROZEN_MPY (1)
#define MICROPY_MODULE_FROZEN (1)
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
#define MICROPY_ENABLE_DOC_STRING (1)
#define MICROPY_ENABLE_GC (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
......
......@@ -108,6 +108,11 @@ mp_lexer_t* mp_lexer_new_from_file(const char* filename)
mp_raise_OSError(MP_ENOENT);
}
mp_import_stat_t mp_import_stat(const char* path)
{
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t* args, mp_map_t* kwargs)
{
/* TODO: Once fs is implemented, get this working as well */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment