Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
95f5050b
Verified
Commit
95f5050b
authored
Jul 04, 2019
by
Rahix
Browse files
feat(pycardium): Enable frozen-module support
Closes
#4
. Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
aea7b2db
Changes
9
Hide whitespace changes
Inline
Side-by-side
lib/micropython/gen-frozen.sh
0 → 100755
View file @
95f5050b
#!/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
"
lib/micropython/gen-mpy-cross.sh
0 → 100755
View file @
95f5050b
#!/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
"
lib/micropython/meson.build
View file @
95f5050b
...
...
@@ -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/'
,
...
...
lib/micropython/mpy-cross-wrapper.c
0 → 100644
View file @
95f5050b
#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
);
}
pycardium/meson.build
View file @
95f5050b
...
...
@@ -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
,
...
...
pycardium/modules/py/foo.py
0 → 100644
View file @
95f5050b
# Foo Module
def
bar
():
print
(
"Hello from foo!"
)
X
=
3.14
pycardium/modules/py/meson.build
0 → 100644
View file @
95f5050b
python_modules
=
files
(
'foo.py'
,
)
frozen_modules
=
mpy_cross
.
process
(
python_modules
)
pycardium/mpconfigport.h
View file @
95f5050b
...
...
@@ -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)
...
...
pycardium/mphalport.c
View file @
95f5050b
...
...
@@ -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 */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment