Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
50149a57
Commit
50149a57
authored
Jan 20, 2015
by
Damien George
Browse files
py: Use mp_arg_check_num in some _make_new functions.
Reduces stmhal code size by about 250 bytes.
parent
ff8dd3f4
Changes
5
Hide whitespace changes
Inline
Side-by-side
py/objexcept.c
View file @
50149a57
...
...
@@ -30,11 +30,11 @@
#include
<stdio.h>
#include
"py/mpstate.h"
#include
"py/nlr.h"
#include
"py/objlist.h"
#include
"py/objstr.h"
#include
"py/objtuple.h"
#include
"py/objtype.h"
#include
"py/runtime.h"
#include
"py/gc.h"
// Instance of MemoryError exception - needed by mp_malloc_fail
...
...
@@ -115,23 +115,17 @@ STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...
}
mp_obj_t
mp_obj_exception_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_type_t
*
type
=
type_in
;
if
(
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"%s does not take keyword arguments"
,
mp_obj_get_type_str
(
type_in
)));
}
mp_arg_check_num
(
n_args
,
n_kw
,
0
,
MP_OBJ_FUN_ARGS_MAX
,
false
);
mp_obj_exception_t
*
o
=
m_new_obj_var_maybe
(
mp_obj_exception_t
,
mp_obj_t
,
0
);
if
(
o
==
NULL
)
{
// Couldn't allocate heap memory; use local data instead.
o
=
&
MP_STATE_VM
(
mp_emergency_exception_obj
);
// We can't store any args.
n_args
=
0
;
o
->
args
=
mp_const_empty_tuple
;
}
else
{
o
->
args
=
mp_obj_new_tuple
(
n_args
,
args
);
}
o
->
base
.
type
=
type
;
o
->
base
.
type
=
type
_in
;
o
->
traceback
=
MP_OBJ_NULL
;
return
o
;
}
...
...
py/objfilter.c
View file @
50149a57
...
...
@@ -24,7 +24,6 @@
* THE SOFTWARE.
*/
#include
"py/nlr.h"
#include
"py/runtime.h"
typedef
struct
_mp_obj_filter_t
{
...
...
@@ -34,10 +33,7 @@ typedef struct _mp_obj_filter_t {
}
mp_obj_filter_t
;
STATIC
mp_obj_t
filter_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
if
(
n_args
!=
2
||
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"filter expected 2 arguments"
));
}
assert
(
n_args
==
2
);
mp_arg_check_num
(
n_args
,
n_kw
,
2
,
2
,
false
);
mp_obj_filter_t
*
o
=
m_new_obj
(
mp_obj_filter_t
);
o
->
base
.
type
=
type_in
;
o
->
fun
=
args
[
0
];
...
...
py/objmap.c
View file @
50149a57
...
...
@@ -27,7 +27,6 @@
#include
<stdlib.h>
#include
<assert.h>
#include
"py/nlr.h"
#include
"py/runtime.h"
typedef
struct
_mp_obj_map_t
{
...
...
@@ -38,10 +37,7 @@ typedef struct _mp_obj_map_t {
}
mp_obj_map_t
;
STATIC
mp_obj_t
map_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
if
(
n_args
<
2
||
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"map must have at least 2 arguments and no keyword arguments"
));
}
assert
(
n_args
>=
2
);
mp_arg_check_num
(
n_args
,
n_kw
,
2
,
MP_OBJ_FUN_ARGS_MAX
,
false
);
mp_obj_map_t
*
o
=
m_new_obj_var
(
mp_obj_map_t
,
mp_obj_t
,
n_args
-
1
);
o
->
base
.
type
=
type_in
;
o
->
n_iters
=
n_args
-
1
;
...
...
py/objobject.c
View file @
50149a57
...
...
@@ -26,9 +26,7 @@
#include
<stdlib.h>
#include
"py/nlr.h"
#include
"py/obj.h"
#include
"py/runtime0.h"
#include
"py/runtime.h"
mp_obj_t
instance_make_new
(
mp_obj_t
self_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
);
...
...
@@ -38,10 +36,7 @@ typedef struct _mp_obj_object_t {
STATIC
mp_obj_t
object_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
(
void
)
args
;
if
(
n_args
!=
0
||
n_kw
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"object takes no arguments"
));
}
mp_arg_check_num
(
n_args
,
n_kw
,
0
,
0
,
false
);
mp_obj_object_t
*
o
=
m_new_obj
(
mp_obj_object_t
);
o
->
base
.
type
=
type_in
;
return
o
;
...
...
py/objtype.c
View file @
50149a57
...
...
@@ -855,11 +855,9 @@ STATIC void super_print(void (*print)(void *env, const char *fmt, ...), void *en
STATIC
mp_obj_t
super_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
(
void
)
type_in
;
if
(
n_args
!=
2
||
n_kw
!=
0
)
{
// 0 arguments are turned into 2 in the compiler
// 1 argument is not yet implemented
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"super() requires 2 arguments"
));
}
// 0 arguments are turned into 2 in the compiler
// 1 argument is not yet implemented
mp_arg_check_num
(
n_args
,
n_kw
,
2
,
2
,
false
);
return
mp_obj_new_super
(
args
[
0
],
args
[
1
]);
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment