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
6942f80a
Commit
6942f80a
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Add qstr cfg capability; generate QSTR_NULL and QSTR_ from script.
parent
e233a55a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/makeqstrdata.py
+17
-2
17 additions, 2 deletions
py/makeqstrdata.py
py/qstr.c
+2
-4
2 additions, 4 deletions
py/qstr.c
py/qstr.h
+3
-4
3 additions, 4 deletions
py/qstr.h
py/qstrdefs.h
+4
-0
4 additions, 0 deletions
py/qstrdefs.h
with
26 additions
and
10 deletions
py/makeqstrdata.py
+
17
−
2
View file @
6942f80a
...
...
@@ -40,12 +40,25 @@ def compute_hash(qstr):
def
do_work
(
infiles
):
# read the qstrs in from the input files
qcfgs
=
{}
qstrs
=
{}
for
infile
in
infiles
:
with
open
(
infile
,
'
rt
'
)
as
f
:
for
line
in
f
:
line
=
line
.
strip
()
# is this a config line?
match
=
re
.
match
(
r
'
^QCFG\((.+), (.+)\)
'
,
line
)
if
match
:
value
=
match
.
group
(
2
)
if
value
[
0
]
==
'
(
'
and
value
[
-
1
]
==
'
)
'
:
# strip parenthesis from config value
value
=
value
[
1
:
-
1
]
qcfgs
[
match
.
group
(
1
)]
=
value
continue
# is this a QSTR line?
match
=
re
.
match
(
r
'
^Q\((.
+
)\)$
'
,
line
.
strip
()
)
match
=
re
.
match
(
r
'
^Q\((.
*
)\)$
'
,
line
)
if
not
match
:
continue
...
...
@@ -63,11 +76,13 @@ def do_work(infiles):
# process the qstrs, printing out the generated C header file
print
(
'
// This file was automatically generated by makeqstrdata.py
'
)
print
(
''
)
# add NULL qstr with no hash or data
print
(
'
QDEF(MP_QSTR_NULL, (const byte*)
"
\\
x00
\\
x00
\\
x00
\\
x00
"
""
)
'
)
for
order
,
ident
,
qstr
in
sorted
(
qstrs
.
values
(),
key
=
lambda
x
:
x
[
0
]):
qhash
=
compute_hash
(
qstr
)
qlen
=
len
(
qstr
)
qdata
=
qstr
.
replace
(
'"'
,
'
\\
"'
)
print
(
'
Q
(
%s, (const byte*)
"
\\
x%02x
\\
x%02x
\\
x%02x
\\
x%02x
"
"
%s
"
)
'
%
(
ident
,
qhash
&
0xff
,
(
qhash
>>
8
)
&
0xff
,
qlen
&
0xff
,
(
qlen
>>
8
)
&
0xff
,
qdata
))
print
(
'
Q
DEF(MP_QSTR_
%s, (const byte*)
"
\\
x%02x
\\
x%02x
\\
x%02x
\\
x%02x
"
"
%s
"
)
'
%
(
ident
,
qhash
&
0xff
,
(
qhash
>>
8
)
&
0xff
,
qlen
&
0xff
,
(
qlen
>>
8
)
&
0xff
,
qdata
))
return
True
...
...
This diff is collapsed.
Click to expand it.
py/qstr.c
+
2
−
4
View file @
6942f80a
...
...
@@ -75,11 +75,9 @@ STATIC const qstr_pool_t const_pool = {
10
,
// set so that the first dynamically allocated pool is twice this size; must be <= the len (just below)
MP_QSTR_number_of
,
// corresponds to number of strings in array just below
{
(
const
byte
*
)
"
\0\0\0\0
"
,
// invalid/no qstr has empty data
(
const
byte
*
)
"
\x05\x15\0\0
"
,
// empty qstr with hash=5381=0x1505
#define Q(id, str) str,
#define QDEF(id, str) str,
#include
"genhdr/qstrdefs.generated.h"
#undef Q
#undef Q
DEF
},
};
...
...
This diff is collapsed.
Click to expand it.
py/qstr.h
+
3
−
4
View file @
6942f80a
...
...
@@ -35,12 +35,11 @@
// Note: it would be possible to define MP_QSTR_xxx as qstr_from_str_static("xxx")
// for qstrs that are referenced this way, but you don't want to have them in ROM.
// first entry in enum will be MP_QSTR_NULL=0, which indicates invalid/no qstr
enum
{
MP_QSTR_NULL
=
0
,
// indicates invalid/no qstr
MP_QSTR_
=
1
,
// the empty qstr
#define Q(id, str) MP_QSTR_##id,
#define QDEF(id, str) id,
#include
"genhdr/qstrdefs.generated.h"
#undef Q
#undef Q
DEF
MP_QSTR_number_of
,
};
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
4
−
0
View file @
6942f80a
...
...
@@ -29,6 +29,10 @@
// All the qstr definitions in this file are available as constants.
// That is, they are in ROM and you can reference them simply as MP_QSTR_xxxx.
// qstr configuration passed to makeqstrdata.py of the form QCFG(key, value)
//QCFG(somekey, somevalue)
Q
()
Q
(
*
)
Q
(
__build_class__
)
Q
(
__class__
)
...
...
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