Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
636ed0ff
Commit
636ed0ff
authored
6 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/emitglue: Remove union in mp_raw_code_t to combine bytecode & native.
parent
39868209
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/emitglue.c
+11
-11
11 additions, 11 deletions
py/emitglue.c
py/emitglue.h
+10
-16
10 additions, 16 deletions
py/emitglue.h
py/persistentcode.c
+10
-10
10 additions, 10 deletions
py/persistentcode.c
tools/mpy-tool.py
+8
-10
8 additions, 10 deletions
tools/mpy-tool.py
with
39 additions
and
47 deletions
py/emitglue.c
+
11
−
11
View file @
636ed0ff
...
...
@@ -67,12 +67,12 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
rc
->
kind
=
MP_CODE_BYTECODE
;
rc
->
scope_flags
=
scope_flags
;
rc
->
data
.
u_byte
.
bytecode
=
code
;
rc
->
data
.
u_byte
.
const_table
=
const_table
;
rc
->
fun_
data
=
code
;
rc
->
const_table
=
const_table
;
#if MICROPY_PERSISTENT_CODE_SAVE
rc
->
data
.
u_byte
.
bc
_len
=
len
;
rc
->
data
.
u_byte
.
n_obj
=
n_obj
;
rc
->
data
.
u_byte
.
n_raw_code
=
n_raw_code
;
rc
->
fun_
data_len
=
len
;
rc
->
n_obj
=
n_obj
;
rc
->
n_raw_code
=
n_raw_code
;
#endif
#ifdef DEBUG_PRINT
...
...
@@ -94,9 +94,9 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
rc
->
kind
=
kind
;
rc
->
scope_flags
=
scope_flags
;
rc
->
n_pos_args
=
n_pos_args
;
rc
->
data
.
u_native
.
fun_data
=
fun_data
;
rc
->
data
.
u_native
.
const_table
=
const_table
;
rc
->
data
.
u_native
.
type_sig
=
type_sig
;
rc
->
fun_data
=
fun_data
;
rc
->
const_table
=
const_table
;
rc
->
type_sig
=
type_sig
;
#ifdef DEBUG_PRINT
DEBUG_printf
(
"assign native: kind=%d fun=%p len="
UINT_FMT
" n_pos_args="
UINT_FMT
" flags=%x
\n
"
,
kind
,
fun_data
,
fun_len
,
n_pos_args
,
(
uint
)
scope_flags
);
...
...
@@ -135,7 +135,7 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
#if MICROPY_EMIT_NATIVE
case
MP_CODE_NATIVE_PY
:
case
MP_CODE_NATIVE_VIPER
:
fun
=
mp_obj_new_fun_native
(
def_args
,
def_kw_args
,
rc
->
data
.
u_native
.
fun_data
,
rc
->
data
.
u_native
.
const_table
);
fun
=
mp_obj_new_fun_native
(
def_args
,
def_kw_args
,
rc
->
fun_data
,
rc
->
const_table
);
// Check for a generator function, and if so change the type of the object
if
((
rc
->
scope_flags
&
MP_SCOPE_FLAG_GENERATOR
)
!=
0
)
{
((
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
fun
))
->
type
=
&
mp_type_native_gen_wrap
;
...
...
@@ -144,13 +144,13 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
#endif
#if MICROPY_EMIT_INLINE_ASM
case
MP_CODE_NATIVE_ASM
:
fun
=
mp_obj_new_fun_asm
(
rc
->
n_pos_args
,
rc
->
data
.
u_native
.
fun_data
,
rc
->
data
.
u_native
.
type_sig
);
fun
=
mp_obj_new_fun_asm
(
rc
->
n_pos_args
,
rc
->
fun_data
,
rc
->
type_sig
);
break
;
#endif
default:
// rc->kind should always be set and BYTECODE is the only remaining case
assert
(
rc
->
kind
==
MP_CODE_BYTECODE
);
fun
=
mp_obj_new_fun_bc
(
def_args
,
def_kw_args
,
rc
->
data
.
u_byte
.
bytecode
,
rc
->
data
.
u_byte
.
const_table
);
fun
=
mp_obj_new_fun_bc
(
def_args
,
def_kw_args
,
rc
->
fun_data
,
rc
->
const_table
);
// check for generator functions and if so change the type of the object
if
((
rc
->
scope_flags
&
MP_SCOPE_FLAG_GENERATOR
)
!=
0
)
{
((
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
fun
))
->
type
=
&
mp_type_gen_wrap
;
...
...
This diff is collapsed.
Click to expand it.
py/emitglue.h
+
10
−
16
View file @
636ed0ff
...
...
@@ -52,22 +52,16 @@ typedef struct _mp_raw_code_t {
mp_uint_t
kind
:
3
;
// of type mp_raw_code_kind_t
mp_uint_t
scope_flags
:
7
;
mp_uint_t
n_pos_args
:
11
;
union
{
struct
{
const
byte
*
bytecode
;
const
void
*
fun_data
;
const
mp_uint_t
*
const_table
;
#if MICROPY_PERSISTENT_CODE_SAVE
mp_uint_t
bc
_len
;
size_t
fun_data
_len
;
uint16_t
n_obj
;
uint16_t
n_raw_code
;
#endif
}
u_byte
;
struct
{
void
*
fun_data
;
const
mp_uint_t
*
const_table
;
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
mp_uint_t
type_sig
;
// for viper, compressed as 2-bit types; ret is MSB, then arg0, arg1, etc
}
u_native
;
}
data
;
#endif
}
mp_raw_code_t
;
mp_raw_code_t
*
mp_emit_glue_new_raw_code
(
void
);
...
...
This diff is collapsed.
Click to expand it.
py/persistentcode.c
+
10
−
10
View file @
636ed0ff
...
...
@@ -449,16 +449,16 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc, qstr_window_t *q
}
// extract prelude
const
byte
*
ip
=
rc
->
data
.
u_byte
.
bytecode
;
const
byte
*
ip
=
rc
->
fun_
data
;
const
byte
*
ip2
;
bytecode_prelude_t
prelude
;
extract_prelude
(
&
ip
,
&
ip2
,
&
prelude
);
// save prelude
size_t
prelude_len
=
ip
-
rc
->
data
.
u_byte
.
bytecode
;
const
byte
*
ip_top
=
rc
->
data
.
u_byte
.
bytecode
+
rc
->
data
.
u_byte
.
bc
_len
;
mp_print_uint
(
print
,
rc
->
data
.
u_byte
.
bc
_len
);
mp_print_bytes
(
print
,
rc
->
data
.
u_byte
.
bytecode
,
prelude_len
);
size_t
prelude_len
=
ip
-
rc
->
fun_
data
;
const
byte
*
ip_top
=
rc
->
fun_data
+
rc
->
fun_data
_len
;
mp_print_uint
(
print
,
rc
->
fun_
data_len
);
mp_print_bytes
(
print
,
rc
->
fun_
data
,
prelude_len
);
// save bytecode
save_bytecode
(
print
,
qstr_window
,
ip
,
ip_top
);
...
...
@@ -468,17 +468,17 @@ STATIC void save_raw_code(mp_print_t *print, mp_raw_code_t *rc, qstr_window_t *q
save_qstr
(
print
,
qstr_window
,
ip2
[
2
]
|
(
ip2
[
3
]
<<
8
));
// source_file
// save constant table
mp_print_uint
(
print
,
rc
->
data
.
u_byte
.
n_obj
);
mp_print_uint
(
print
,
rc
->
data
.
u_byte
.
n_raw_code
);
const
mp_uint_t
*
const_table
=
rc
->
data
.
u_byte
.
const_table
;
mp_print_uint
(
print
,
rc
->
n_obj
);
mp_print_uint
(
print
,
rc
->
n_raw_code
);
const
mp_uint_t
*
const_table
=
rc
->
const_table
;
for
(
uint
i
=
0
;
i
<
prelude
.
n_pos_args
+
prelude
.
n_kwonly_args
;
++
i
)
{
mp_obj_t
o
=
(
mp_obj_t
)
*
const_table
++
;
save_qstr
(
print
,
qstr_window
,
MP_OBJ_QSTR_VALUE
(
o
));
}
for
(
uint
i
=
0
;
i
<
rc
->
data
.
u_byte
.
n_obj
;
++
i
)
{
for
(
uint
i
=
0
;
i
<
rc
->
n_obj
;
++
i
)
{
save_obj
(
print
,
(
mp_obj_t
)
*
const_table
++
);
}
for
(
uint
i
=
0
;
i
<
rc
->
data
.
u_byte
.
n_raw_code
;
++
i
)
{
for
(
uint
i
=
0
;
i
<
rc
->
n_raw_code
;
++
i
)
{
save_raw_code
(
print
,
(
mp_raw_code_t
*
)(
uintptr_t
)
*
const_table
++
,
qstr_window
);
}
}
...
...
This diff is collapsed.
Click to expand it.
tools/mpy-tool.py
+
8
−
10
View file @
636ed0ff
...
...
@@ -391,18 +391,16 @@ class RawCode:
print
(
'
.kind = MP_CODE_BYTECODE,
'
)
print
(
'
.scope_flags = 0x%02x,
'
%
self
.
prelude
[
2
])
print
(
'
.n_pos_args = %u,
'
%
self
.
prelude
[
3
])
print
(
'
.data.u_byte = {
'
)
print
(
'
.bytecode = bytecode_data_%s,
'
%
self
.
escaped_name
)
print
(
'
.fun_data = bytecode_data_%s,
'
%
self
.
escaped_name
)
if
const_table_len
:
print
(
'
.const_table = (mp_uint_t*)const_table_data_%s,
'
%
self
.
escaped_name
)
else
:
print
(
'
.const_table = NULL,
'
)
print
(
'
#if MICROPY_PERSISTENT_CODE_SAVE
'
)
print
(
'
.bc
_len = %u,
'
%
len
(
self
.
bytecode
))
print
(
'
.fun_data
_len = %u,
'
%
len
(
self
.
bytecode
))
print
(
'
.n_obj = %u,
'
%
len
(
self
.
objs
))
print
(
'
.n_raw_code = %u,
'
%
len
(
self
.
raw_codes
))
print
(
'
#endif
'
)
print
(
'
},
'
)
print
(
'
};
'
)
class
BytecodeBuffer
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment