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
660aef67
Commit
660aef67
authored
Apr 02, 2014
by
Damien George
Browse files
py: Allow multiple of str/list/tuple on left by an integer.
parent
48815668
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objint.c
View file @
660aef67
#include
<stdlib.h>
#include
<stdint.h>
#include
<assert.h>
...
...
@@ -9,6 +10,8 @@
#include
"parsenum.h"
#include
"mpz.h"
#include
"objint.h"
#include
"runtime0.h"
#include
"runtime.h"
#if MICROPY_ENABLE_FLOAT
#include
<math.h>
...
...
@@ -59,16 +62,20 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
}
}
// This is called
only for n
on
-
SMALL_INT
// This is called
for operations
on
SMALL_INT
that are not handled by mp_unary_op
mp_obj_t
int_unary_op
(
int
op
,
mp_obj_t
o_in
)
{
assert
(
0
);
return
mp_const_none
;
return
MP_OBJ_NULL
;
}
// This is called
only for n
on
-
SMALL_INT
// This is called
for operations
on
SMALL_INT
that are not handled by mp_binary_op
mp_obj_t
int_binary_op
(
int
op
,
mp_obj_t
lhs_in
,
mp_obj_t
rhs_in
)
{
assert
(
0
);
return
mp_const_none
;
if
(
op
==
MP_BINARY_OP_MULTIPLY
)
{
if
(
MP_OBJ_IS_STR
(
rhs_in
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_list
))
{
// multiply is commutative for these types, so delegate to them
return
mp_binary_op
(
op
,
rhs_in
,
lhs_in
);
}
}
return
MP_OBJ_NULL
;
}
// This is called only with strings whose value doesn't fit in SMALL_INT
...
...
py/objint_longlong.c
View file @
660aef67
...
...
@@ -9,6 +9,7 @@
#include
"mpz.h"
#include
"objint.h"
#include
"runtime0.h"
#include
"runtime.h"
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
...
...
@@ -57,6 +58,13 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
else
if
(
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_int
))
{
rhs_val
=
((
mp_obj_int_t
*
)
rhs_in
)
->
val
;
}
else
{
if
(
op
==
MP_BINARY_OP_MULTIPLY
)
{
if
(
MP_OBJ_IS_STR
(
rhs_in
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_list
))
{
// multiply is commutative for these types, so delegate to them
return
mp_binary_op
(
op
,
rhs_in
,
lhs_in
);
}
}
// unsupported operation/type
return
MP_OBJ_NULL
;
}
...
...
py/objint_mpz.c
View file @
660aef67
...
...
@@ -11,6 +11,7 @@
#include
"mpz.h"
#include
"objint.h"
#include
"runtime0.h"
#include
"runtime.h"
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
...
...
@@ -74,7 +75,13 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return
mp_obj_complex_binary_op
(
op
,
mpz_as_float
(
zlhs
),
0
,
rhs_in
);
#endif
}
else
{
// unsupported type
if
(
op
==
MP_BINARY_OP_MULTIPLY
)
{
if
(
MP_OBJ_IS_STR
(
rhs_in
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
rhs_in
,
&
mp_type_list
))
{
// multiply is commutative for these types, so delegate to them
return
mp_binary_op
(
op
,
rhs_in
,
lhs_in
);
}
}
// unsupported operation/type
return
MP_OBJ_NULL
;
}
...
...
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