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
b2a237d3
Commit
b2a237d3
authored
Mar 6, 2015
by
Peter D. Gray
Committed by
Damien George
Mar 11, 2015
Browse files
Options
Downloads
Patches
Plain Diff
py: Add support for start/stop/step attributes of builtin range object.
parent
5be4a84a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/mpconfig.h
+6
-0
6 additions, 0 deletions
py/mpconfig.h
py/objrange.c
+17
-0
17 additions, 0 deletions
py/objrange.c
py/qstrdefs.h
+5
-0
5 additions, 0 deletions
py/qstrdefs.h
tests/basics/builtin_range.py
+5
-0
5 additions, 0 deletions
tests/basics/builtin_range.py
with
33 additions
and
0 deletions
py/mpconfig.h
+
6
−
0
View file @
b2a237d3
...
...
@@ -382,6 +382,12 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_PROPERTY (1)
#endif
// Whether to implement the start/stop/step attributes (readback) on
// the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
#ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
#endif
// Whether to support complete set of special methods
// for user classes, otherwise only the most used
#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
...
...
This diff is collapsed.
Click to expand it.
py/objrange.c
+
17
−
0
View file @
b2a237d3
...
...
@@ -166,6 +166,20 @@ STATIC mp_obj_t range_getiter(mp_obj_t o_in) {
return
mp_obj_new_range_iterator
(
o
->
start
,
o
->
stop
,
o
->
step
);
}
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
STATIC
void
range_load_attr
(
mp_obj_t
o_in
,
qstr
attr
,
mp_obj_t
*
dest
)
{
mp_obj_range_t
*
o
=
o_in
;
if
(
attr
==
MP_QSTR_start
)
{
dest
[
0
]
=
mp_obj_new_int
(
o
->
start
);
}
else
if
(
attr
==
MP_QSTR_stop
)
{
dest
[
0
]
=
mp_obj_new_int
(
o
->
stop
);
}
else
if
(
attr
==
MP_QSTR_step
)
{
dest
[
0
]
=
mp_obj_new_int
(
o
->
step
);
}
}
#endif
const
mp_obj_type_t
mp_type_range
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_range
,
...
...
@@ -174,4 +188,7 @@ const mp_obj_type_t mp_type_range = {
.
unary_op
=
range_unary_op
,
.
subscr
=
range_subscr
,
.
getiter
=
range_getiter
,
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
.
load_attr
=
range_load_attr
,
#endif
};
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
5
−
0
View file @
b2a237d3
...
...
@@ -245,6 +245,11 @@ Q(single)
Q
(
sep
)
Q
(
end
)
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
Q
(
step
)
Q
(
stop
)
#endif
Q
(
clear
)
Q
(
copy
)
Q
(
fromkeys
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/builtin_range.py
+
5
−
0
View file @
b2a237d3
...
...
@@ -24,3 +24,8 @@ print(range(4)[1:2])
print
(
range
(
4
)[
1
:
3
])
print
(
range
(
4
)[
1
::
2
])
print
(
range
(
4
)[
1
:
-
2
:
2
])
# attrs
print
(
range
(
1
,
2
,
3
).
start
)
print
(
range
(
1
,
2
,
3
).
stop
)
print
(
range
(
1
,
2
,
3
).
step
)
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