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
22a0865d
Commit
22a0865d
authored
Feb 15, 2014
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Improve exception bases, reduces ROM usage.
Thanks to @pfalcon for the tip!
parent
8725f8f7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objexcept.c
+21
-17
21 additions, 17 deletions
py/objexcept.c
py/runtime.c
+2
-0
2 additions, 0 deletions
py/runtime.c
with
23 additions
and
17 deletions
py/objexcept.c
+
21
−
17
View file @
22a0865d
...
@@ -66,30 +66,34 @@ const mp_obj_type_t mp_type_BaseException = {
...
@@ -66,30 +66,34 @@ const mp_obj_type_t mp_type_BaseException = {
.
make_new
=
mp_obj_exception_make_new
,
.
make_new
=
mp_obj_exception_make_new
,
};
};
#define MP_DEFINE_EXCEPTION(exc_name) \
#define MP_DEFINE_EXCEPTION_BASE(base_name) \
STATIC const mp_obj_tuple_t mp_type_ ## exc_name ## _bases_tuple = {{&tuple_type}, 1, {(mp_obj_t)&mp_type_BaseException}};\
STATIC const mp_obj_tuple_t mp_type_ ## base_name ## _base_tuple = {{&tuple_type}, 1, {(mp_obj_t)&mp_type_ ## base_name}};\
#define MP_DEFINE_EXCEPTION(exc_name, base_name) \
const mp_obj_type_t mp_type_ ## exc_name = { \
const mp_obj_type_t mp_type_ ## exc_name = { \
{ &mp_type_type }, \
{ &mp_type_type }, \
.name = MP_QSTR_ ## exc_name, \
.name = MP_QSTR_ ## exc_name, \
.print = mp_obj_exception_print, \
.print = mp_obj_exception_print, \
.make_new = mp_obj_exception_make_new, \
.make_new = mp_obj_exception_make_new, \
.bases_tuple = (mp_obj_t)&mp_type_ ##
exc
_name ## _base
s
_tuple, \
.bases_tuple = (mp_obj_t)&mp_type_ ##
base
_name ## _base_tuple, \
};
};
MP_DEFINE_EXCEPTION
(
AssertionError
)
MP_DEFINE_EXCEPTION_BASE
(
BaseException
)
MP_DEFINE_EXCEPTION
(
AttributeError
)
MP_DEFINE_EXCEPTION
(
ImportError
)
MP_DEFINE_EXCEPTION
(
AssertionError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
IndentationError
)
MP_DEFINE_EXCEPTION
(
AttributeError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
IndexError
)
MP_DEFINE_EXCEPTION
(
ImportError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
KeyError
)
MP_DEFINE_EXCEPTION
(
IndentationError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
NameError
)
MP_DEFINE_EXCEPTION
(
IndexError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
SyntaxError
)
MP_DEFINE_EXCEPTION
(
KeyError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
TypeError
)
MP_DEFINE_EXCEPTION
(
NameError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
ValueError
)
MP_DEFINE_EXCEPTION
(
SyntaxError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
OverflowError
)
MP_DEFINE_EXCEPTION
(
TypeError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
OSError
)
MP_DEFINE_EXCEPTION
(
ValueError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
NotImplementedError
)
MP_DEFINE_EXCEPTION
(
OverflowError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
StopIteration
)
MP_DEFINE_EXCEPTION
(
OSError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
NotImplementedError
,
BaseException
)
MP_DEFINE_EXCEPTION
(
StopIteration
,
BaseException
)
mp_obj_t
mp_obj_new_exception
(
const
mp_obj_type_t
*
exc_type
)
{
mp_obj_t
mp_obj_new_exception
(
const
mp_obj_type_t
*
exc_type
)
{
return
mp_obj_new_exception_msg_varg
(
exc_type
,
NULL
);
return
mp_obj_new_exception_msg_varg
(
exc_type
,
NULL
);
...
...
This diff is collapsed.
Click to expand it.
py/runtime.c
+
2
−
0
View file @
22a0865d
...
@@ -1003,6 +1003,8 @@ mp_obj_t rt_make_raise_obj(mp_obj_t o) {
...
@@ -1003,6 +1003,8 @@ mp_obj_t rt_make_raise_obj(mp_obj_t o) {
if
(
mp_obj_is_exception_type
(
o
))
{
if
(
mp_obj_is_exception_type
(
o
))
{
// o is an exception type (it is derived from BaseException (or is BaseException))
// o is an exception type (it is derived from BaseException (or is BaseException))
// create and return a new exception instance by calling o
// create and return a new exception instance by calling o
// TODO could have an option to disable traceback, then builtin exceptions (eg TypeError)
// could have const instances in ROM which we return here instead
return
rt_call_function_n_kw
(
o
,
0
,
0
,
NULL
);
return
rt_call_function_n_kw
(
o
,
0
,
0
,
NULL
);
}
else
if
(
mp_obj_is_exception_instance
(
o
))
{
}
else
if
(
mp_obj_is_exception_instance
(
o
))
{
// o is an instance of an exception, so use it as the exception
// o is an instance of an exception, so use it as the exception
...
...
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