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
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
7b21c2d8
Commit
7b21c2d8
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Fix allocation of unique code blocks.
parent
97209d38
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objmodule.c
+3
-1
3 additions, 1 deletion
py/objmodule.c
py/runtime.c
+12
-7
12 additions, 7 deletions
py/runtime.c
with
15 additions
and
8 deletions
py/objmodule.c
+
3
−
1
View file @
7b21c2d8
...
...
@@ -6,6 +6,7 @@
#include
"nlr.h"
#include
"misc.h"
#include
"mpconfig.h"
#include
"mpqstr.h"
#include
"obj.h"
#include
"runtime.h"
#include
"map.h"
...
...
@@ -31,7 +32,8 @@ mp_obj_t mp_obj_new_module(qstr module_name) {
mp_obj_module_t
*
o
=
m_new_obj
(
mp_obj_module_t
);
o
->
base
.
type
=
&
module_type
;
o
->
name
=
module_name
;
o
->
globals
=
mp_map_new
(
MP_MAP_QSTR
,
0
);
o
->
globals
=
mp_map_new
(
MP_MAP_QSTR
,
1
);
mp_qstr_map_lookup
(
o
->
globals
,
MP_QSTR___name__
,
true
)
->
value
=
mp_obj_new_str
(
module_name
);
return
o
;
}
...
...
This diff is collapsed.
Click to expand it.
py/runtime.c
+
12
−
7
View file @
7b21c2d8
...
...
@@ -61,7 +61,8 @@ typedef struct _mp_code_t {
}
mp_code_t
;
static
int
next_unique_code_id
;
static
mp_code_t
*
unique_codes
;
static
machine_uint_t
unique_codes_alloc
=
0
;
static
mp_code_t
*
unique_codes
=
NULL
;
#ifdef WRITE_CODE
FILE
*
fp_write_code
=
NULL
;
...
...
@@ -126,6 +127,7 @@ void rt_init(void) {
mp_qstr_map_lookup
(
&
map_builtins
,
MP_QSTR_sum
,
true
)
->
value
=
rt_make_function_var
(
1
,
mp_builtin_sum
);
next_unique_code_id
=
1
;
// 0 indicates "no code"
unique_codes_alloc
=
0
;
unique_codes
=
NULL
;
#ifdef WRITE_CODE
...
...
@@ -134,6 +136,7 @@ void rt_init(void) {
}
void
rt_deinit
(
void
)
{
m_del
(
mp_code_t
,
unique_codes
,
unique_codes_alloc
);
#ifdef WRITE_CODE
if
(
fp_write_code
!=
NULL
)
{
fclose
(
fp_write_code
);
...
...
@@ -146,18 +149,20 @@ int rt_get_unique_code_id(void) {
}
static
void
alloc_unique_codes
(
void
)
{
if
(
unique_codes
==
NULL
)
{
unique_codes
=
m_new
(
mp_code_t
,
next_unique_code_id
+
10
);
// XXX hack until we fix the REPL allocation problem
for
(
int
i
=
0
;
i
<
next_unique_code_id
;
i
++
)
{
if
(
next_unique_code_id
>
unique_codes_alloc
)
{
// increase size of unique_codes table
unique_codes
=
m_renew
(
mp_code_t
,
unique_codes
,
unique_codes_alloc
,
next_unique_code_id
);
for
(
int
i
=
unique_codes_alloc
;
i
<
next_unique_code_id
;
i
++
)
{
unique_codes
[
i
].
kind
=
MP_CODE_NONE
;
}
unique_codes_alloc
=
next_unique_code_id
;
}
}
void
rt_assign_byte_code
(
int
unique_code_id
,
byte
*
code
,
uint
len
,
int
n_args
,
int
n_locals
,
int
n_stack
,
bool
is_generator
)
{
alloc_unique_codes
();
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
);
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
&&
unique_codes
[
unique_code_id
].
kind
==
MP_CODE_NONE
);
unique_codes
[
unique_code_id
].
kind
=
MP_CODE_BYTE
;
unique_codes
[
unique_code_id
].
n_args
=
n_args
;
unique_codes
[
unique_code_id
].
n_locals
=
n_locals
;
...
...
@@ -192,7 +197,7 @@ void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, i
void
rt_assign_native_code
(
int
unique_code_id
,
void
*
fun
,
uint
len
,
int
n_args
)
{
alloc_unique_codes
();
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
);
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
&&
unique_codes
[
unique_code_id
].
kind
==
MP_CODE_NONE
);
unique_codes
[
unique_code_id
].
kind
=
MP_CODE_NATIVE
;
unique_codes
[
unique_code_id
].
n_args
=
n_args
;
unique_codes
[
unique_code_id
].
n_locals
=
0
;
...
...
@@ -225,7 +230,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args)
void
rt_assign_inline_asm_code
(
int
unique_code_id
,
void
*
fun
,
uint
len
,
int
n_args
)
{
alloc_unique_codes
();
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
);
assert
(
1
<=
unique_code_id
&&
unique_code_id
<
next_unique_code_id
&&
unique_codes
[
unique_code_id
].
kind
==
MP_CODE_NONE
);
unique_codes
[
unique_code_id
].
kind
=
MP_CODE_INLINE_ASM
;
unique_codes
[
unique_code_id
].
n_args
=
n_args
;
unique_codes
[
unique_code_id
].
n_locals
=
0
;
...
...
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