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
e2fb2baa
Commit
e2fb2baa
authored
Jan 15, 2014
by
Damien George
Browse files
Implement repr.
parent
9528cd66
Changes
5
Hide whitespace changes
Inline
Side-by-side
py/builtin.c
View file @
e2fb2baa
...
...
@@ -140,10 +140,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
static
mp_obj_t
mp_builtin_chr
(
mp_obj_t
o_in
)
{
int
ord
=
mp_obj_get_int
(
o_in
);
if
(
0
<=
ord
&&
ord
<=
0x10ffff
)
{
char
*
str
=
m_new
(
char
,
2
);
str
[
0
]
=
ord
;
str
[
1
]
=
'\0'
;
return
mp_obj_new_str
(
qstr_from_str_take
(
str
,
2
));
char
str
[
2
]
=
{
ord
,
'\0'
};
return
mp_obj_new_str
(
qstr_from_strn_copy
(
str
,
1
));
}
else
{
nlr_jump
(
mp_obj_new_exception_msg
(
MP_QSTR_ValueError
,
"chr() arg not in range(0x110000)"
));
}
...
...
@@ -310,6 +308,14 @@ static mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_builtin_range_obj
,
1
,
3
,
mp_builtin_range
);
static
mp_obj_t
mp_builtin_repr
(
mp_obj_t
o_in
)
{
vstr_t
*
vstr
=
vstr_new
();
mp_obj_print_helper
((
void
(
*
)(
void
*
env
,
const
char
*
fmt
,
...))
vstr_printf
,
vstr
,
o_in
);
return
mp_obj_new_str
(
qstr_from_str_take
(
vstr
->
buf
,
vstr
->
alloc
));
}
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_repr_obj
,
mp_builtin_repr
);
static
mp_obj_t
mp_builtin_sum
(
int
n_args
,
const
mp_obj_t
*
args
)
{
assert
(
1
<=
n_args
&&
n_args
<=
2
);
mp_obj_t
value
;
...
...
@@ -324,6 +330,7 @@ static mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
}
return
value
;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_builtin_sum_obj
,
1
,
2
,
mp_builtin_sum
);
static
mp_obj_t
mp_builtin_sorted
(
mp_obj_t
args
,
mp_map_t
*
kwargs
)
{
...
...
@@ -343,4 +350,5 @@ static mp_obj_t mp_builtin_sorted(mp_obj_t args, mp_map_t *kwargs) {
return
self
;
}
MP_DEFINE_CONST_FUN_OBJ_KW
(
mp_builtin_sorted_obj
,
1
,
mp_builtin_sorted
);
py/builtin.h
View file @
e2fb2baa
...
...
@@ -21,5 +21,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_ord_obj);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_pow_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_print_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_range_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_repr_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_sorted_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_sum_obj
);
py/mpqstrraw.h
View file @
e2fb2baa
...
...
@@ -57,6 +57,7 @@ Q(ord)
Q
(
pow
)
Q
(
print
)
Q
(
range
)
Q
(
repr
)
Q
(
set
)
Q
(
sorted
)
Q
(
sum
)
...
...
py/runtime.c
View file @
e2fb2baa
...
...
@@ -134,6 +134,7 @@ void rt_init(void) {
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_pow
,
(
mp_obj_t
)
&
mp_builtin_pow_obj
);
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_print
,
(
mp_obj_t
)
&
mp_builtin_print_obj
);
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_range
,
(
mp_obj_t
)
&
mp_builtin_range_obj
);
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_repr
,
(
mp_obj_t
)
&
mp_builtin_repr_obj
);
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_sorted
,
(
mp_obj_t
)
&
mp_builtin_sorted_obj
);
mp_map_add_qstr
(
&
map_builtins
,
MP_QSTR_sum
,
(
mp_obj_t
)
&
mp_builtin_sum_obj
);
...
...
tests/basics/tests/exception1.py
View file @
e2fb2baa
# TODO: requires repr()
#a = IndexError(1, "test", [100, 200])
#print(repr(a))
a
=
IndexError
(
1
,
"test"
,
[
100
,
200
])
print
(
repr
(
a
))
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