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
39dc1454
Commit
39dc1454
authored
Oct 03, 2014
by
Damien George
Browse files
py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.
This should pretty much resolve issue #50.
parent
3eaa0c38
Changes
12
Hide whitespace changes
Inline
Side-by-side
py/bc.h
View file @
39dc1454
...
...
@@ -42,7 +42,7 @@ typedef struct _mp_code_state {
mp_obj_t
*
sp
;
// bit 0 is saved currently_in_except_block value
mp_exc_stack_t
*
exc_sp
;
uint
n_state
;
mp_
uint
_t
n_state
;
// Variable-length
mp_obj_t
state
[
0
];
// Variable-length, never accessed by name, only as (void*)(state + n_state)
...
...
py/compile.c
View file @
39dc1454
...
...
@@ -1459,7 +1459,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) {
if
(
i
>
0
)
{
*
str_dest
++
=
'.'
;
}
uint
str_src_len
;
mp_
uint
_t
str_src_len
;
const
byte
*
str_src
=
qstr_data
(
MP_PARSE_NODE_LEAF_ARG
(
pns
->
nodes
[
i
]),
&
str_src_len
);
memcpy
(
str_dest
,
str_src
,
str_src_len
);
str_dest
+=
str_src_len
;
...
...
@@ -2563,7 +2563,7 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
byte
*
s_dest
=
qstr_build_start
(
n_bytes
,
&
q_ptr
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
if
(
MP_PARSE_NODE_IS_LEAF
(
pns
->
nodes
[
i
]))
{
uint
s_len
;
mp_
uint
_t
s_len
;
const
byte
*
s
=
qstr_data
(
MP_PARSE_NODE_LEAF_ARG
(
pns
->
nodes
[
i
]),
&
s_len
);
memcpy
(
s_dest
,
s
,
s_len
);
s_dest
+=
s_len
;
...
...
py/emitnative.c
View file @
39dc1454
...
...
@@ -1075,7 +1075,7 @@ STATIC void emit_native_import_star(emit_t *emit) {
STATIC
void
emit_native_load_const_tok
(
emit_t
*
emit
,
mp_token_kind_t
tok
)
{
DEBUG_printf
(
"load_const_tok(tok=%u)
\n
"
,
tok
);
emit_native_pre
(
emit
);
in
t
vtype
;
vtype_kind_
t
vtype
;
mp_uint_t
val
;
if
(
emit
->
do_viper_types
)
{
switch
(
tok
)
{
...
...
py/objboundmeth.c
View file @
39dc1454
...
...
@@ -55,7 +55,7 @@ mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, con
// need to insert self->self before all other args and then call self->meth
in
t
n_total
=
n_args
+
2
*
n_kw
;
mp_uint_
t
n_total
=
n_args
+
2
*
n_kw
;
if
(
n_total
<=
4
)
{
// use stack to allocate temporary args array
mp_obj_t
args2
[
5
];
...
...
py/objclosure.c
View file @
39dc1454
...
...
@@ -46,7 +46,7 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
// need to concatenate closed-over-vars and args
in
t
n_total
=
self
->
n_closed
+
n_args
+
2
*
n_kw
;
mp_uint_
t
n_total
=
self
->
n_closed
+
n_args
+
2
*
n_kw
;
if
(
n_total
<=
5
)
{
// use stack to allocate temporary args array
mp_obj_t
args2
[
5
];
...
...
@@ -68,7 +68,7 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
STATIC
void
closure_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
)
{
mp_obj_closure_t
*
o
=
o_in
;
print
(
env
,
"<closure %s at %p, n_closed=%u "
,
mp_obj_fun_get_name
(
o
->
fun
),
o
,
o
->
n_closed
);
for
(
in
t
i
=
0
;
i
<
o
->
n_closed
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
o
->
n_closed
;
i
++
)
{
if
(
o
->
closed
[
i
]
==
MP_OBJ_NULL
)
{
print
(
env
,
"(nil)"
);
}
else
{
...
...
py/objfun.c
View file @
39dc1454
...
...
@@ -116,29 +116,6 @@ const mp_obj_type_t mp_type_fun_builtin = {
.
binary_op
=
mp_obj_fun_binary_op
,
};
#if 0 // currently unused, and semi-obsolete
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun) {
mp_obj_fun_builtin_t *o = m_new_obj(mp_obj_fun_builtin_t);
o->base.type = &mp_type_fun_native;
o->is_kw = false;
o->n_args_min = n_args_min;
o->n_args_max = MP_OBJ_FUN_ARGS_MAX;
o->fun = fun;
return o;
}
// min and max are inclusive
mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun) {
mp_obj_fun_builtin_t *o = m_new_obj(mp_obj_fun_builtin_t);
o->base.type = &mp_type_fun_native;
o->is_kw = false;
o->n_args_min = n_args_min;
o->n_args_max = n_args_max;
o->fun = fun;
return o;
}
#endif
/******************************************************************************/
/* byte code functions */
...
...
@@ -161,9 +138,9 @@ STATIC void fun_bc_print(void (*print)(void *env, const char *fmt, ...), void *e
#endif
#if DEBUG_PRINT
STATIC
void
dump_args
(
const
mp_obj_t
*
a
,
in
t
sz
)
{
STATIC
void
dump_args
(
const
mp_obj_t
*
a
,
mp_uint_
t
sz
)
{
DEBUG_printf
(
"%p: "
,
a
);
for
(
in
t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
sz
;
i
++
)
{
DEBUG_printf
(
"%p "
,
a
[
i
]);
}
DEBUG_printf
(
"
\n
"
);
...
...
py/objstr.c
View file @
39dc1454
...
...
@@ -213,7 +213,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
return
mp_obj_str_builder_end
(
o
);
}
in
t
len
;
mp_int_
t
len
;
byte
*
data
;
vstr_t
*
vstr
=
NULL
;
mp_obj_t
o
=
NULL
;
...
...
@@ -293,7 +293,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// add 2 strings or bytes
GET_STR_DATA_LEN
(
rhs_in
,
rhs_data
,
rhs_len
);
in
t
alloc_len
=
lhs_len
+
rhs_len
;
mp_uint_
t
alloc_len
=
lhs_len
+
rhs_len
;
/* code for making qstr
byte *q_ptr;
...
...
@@ -440,8 +440,8 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
}
// count required length
in
t
required_len
=
0
;
for
(
in
t
i
=
0
;
i
<
seq_len
;
i
++
)
{
mp_uint_
t
required_len
=
0
;
for
(
mp_uint_
t
i
=
0
;
i
<
seq_len
;
i
++
)
{
if
(
mp_obj_get_type
(
seq_items
[
i
])
!=
self_type
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"join expects a list of str/bytes objects consistent with self object"
));
...
...
@@ -456,7 +456,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
// make joined string
byte
*
data
;
mp_obj_t
joined_str
=
mp_obj_str_builder_start
(
self_type
,
required_len
,
&
data
);
for
(
in
t
i
=
0
;
i
<
seq_len
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
seq_len
;
i
++
)
{
if
(
i
>
0
)
{
memcpy
(
data
,
sep_str
,
sep_len
);
data
+=
sep_len
;
...
...
@@ -562,7 +562,7 @@ STATIC mp_obj_t str_rsplit(mp_uint_t n_args, const mp_obj_t *args) {
// Preallocate list to the max expected # of elements, as we
// will fill it from the end.
mp_obj_list_t
*
res
=
mp_obj_new_list
(
splits
+
1
,
NULL
);
in
t
idx
=
splits
;
mp_int_
t
idx
=
splits
;
if
(
sep
==
mp_const_none
)
{
assert
(
!
"TODO: rsplit(None,n) not implemented"
);
...
...
@@ -598,7 +598,7 @@ STATIC mp_obj_t str_rsplit(mp_uint_t n_args, const mp_obj_t *args) {
}
if
(
idx
!=
0
)
{
// We split less parts than split limit, now go cleanup surplus
in
t
used
=
org_splits
+
1
-
idx
;
mp_int_
t
used
=
org_splits
+
1
-
idx
;
memmove
(
res
->
items
,
&
res
->
items
[
idx
],
used
*
sizeof
(
mp_obj_t
));
mp_seq_clear
(
res
->
items
,
used
,
res
->
alloc
,
sizeof
(
*
res
->
items
));
res
->
len
=
used
;
...
...
@@ -1554,7 +1554,7 @@ STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) {
GET_STR_DATA_LEN
(
self_in
,
self_data
,
self_len
);
byte
*
data
;
mp_obj_t
s
=
mp_obj_str_builder_start
(
mp_obj_get_type
(
self_in
),
self_len
,
&
data
);
for
(
in
t
i
=
0
;
i
<
self_len
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
self_len
;
i
++
)
{
*
data
++
=
op
(
*
self_data
++
);
}
*
data
=
0
;
...
...
@@ -1577,7 +1577,7 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) {
}
if
(
f
!=
unichar_isupper
&&
f
!=
unichar_islower
)
{
for
(
in
t
i
=
0
;
i
<
self_len
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
self_len
;
i
++
)
{
if
(
!
f
(
*
self_data
++
))
{
return
mp_const_false
;
}
...
...
@@ -1585,7 +1585,7 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) {
}
else
{
bool
contains_alpha
=
false
;
for
(
in
t
i
=
0
;
i
<
self_len
;
i
++
)
{
// only check alphanumeric characters
for
(
mp_uint_
t
i
=
0
;
i
<
self_len
;
i
++
)
{
// only check alphanumeric characters
if
(
unichar_isalpha
(
*
self_data
++
))
{
contains_alpha
=
true
;
if
(
!
f
(
*
(
self_data
-
1
)))
{
// -1 because we already incremented above
...
...
py/objstr.h
View file @
39dc1454
...
...
@@ -36,17 +36,17 @@ typedef struct _mp_obj_str_t {
// use this macro to extract the string hash
#define GET_STR_HASH(str_obj_in, str_hash) \
uint str_hash; if (MP_OBJ_IS_QSTR(str_obj_in)) \
mp_
uint
_t
str_hash; if (MP_OBJ_IS_QSTR(str_obj_in)) \
{ str_hash = qstr_hash(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_hash = ((mp_obj_str_t*)str_obj_in)->hash; }
// use this macro to extract the string length
#define GET_STR_LEN(str_obj_in, str_len) \
uint str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
mp_
uint
_t
str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)str_obj_in)->len; }
// use this macro to extract the string data and length
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
const byte *str_data; uint str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
const byte *str_data;
mp_
uint
_t
str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; }
...
...
py/qstr.c
View file @
39dc1454
...
...
@@ -55,7 +55,7 @@
#define Q_GET_DATA(q) ((q) + 4)
// this must match the equivalent function in makeqstrdata.py
mp_uint_t
qstr_compute_hash
(
const
byte
*
data
,
uint
len
)
{
mp_uint_t
qstr_compute_hash
(
const
byte
*
data
,
mp_
uint
_t
len
)
{
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
mp_uint_t
hash
=
5381
;
for
(
const
byte
*
top
=
data
+
len
;
data
<
top
;
data
++
)
{
...
...
@@ -71,9 +71,9 @@ mp_uint_t qstr_compute_hash(const byte *data, uint len) {
typedef
struct
_qstr_pool_t
{
struct
_qstr_pool_t
*
prev
;
uint
total_prev_len
;
uint
alloc
;
uint
len
;
mp_
uint
_t
total_prev_len
;
mp_
uint
_t
alloc
;
mp_
uint
_t
len
;
const
byte
*
qstrs
[];
}
qstr_pool_t
;
...
...
@@ -130,7 +130,7 @@ STATIC qstr qstr_add(const byte *q_ptr) {
return
last_pool
->
total_prev_len
+
last_pool
->
len
-
1
;
}
qstr
qstr_find_strn
(
const
char
*
str
,
uint
str_len
)
{
qstr
qstr_find_strn
(
const
char
*
str
,
mp_
uint
_t
str_len
)
{
// work out hash of str
mp_uint_t
str_hash
=
qstr_compute_hash
((
const
byte
*
)
str
,
str_len
);
...
...
@@ -151,7 +151,7 @@ qstr qstr_from_str(const char *str) {
return
qstr_from_strn
(
str
,
strlen
(
str
));
}
qstr
qstr_from_strn
(
const
char
*
str
,
uint
len
)
{
qstr
qstr_from_strn
(
const
char
*
str
,
mp_
uint
_t
len
)
{
qstr
q
=
qstr_find_strn
(
str
,
len
);
if
(
q
==
0
)
{
mp_uint_t
hash
=
qstr_compute_hash
((
const
byte
*
)
str
,
len
);
...
...
@@ -167,7 +167,7 @@ qstr qstr_from_strn(const char *str, uint len) {
return
q
;
}
byte
*
qstr_build_start
(
uint
len
,
byte
**
q_ptr
)
{
byte
*
qstr_build_start
(
mp_
uint
_t
len
,
byte
**
q_ptr
)
{
assert
(
len
<=
65535
);
*
q_ptr
=
m_new
(
byte
,
4
+
len
+
1
);
(
*
q_ptr
)[
2
]
=
len
;
...
...
@@ -194,7 +194,7 @@ mp_uint_t qstr_hash(qstr q) {
return
Q_GET_HASH
(
find_qstr
(
q
));
}
uint
qstr_len
(
qstr
q
)
{
mp_
uint
_t
qstr_len
(
qstr
q
)
{
const
byte
*
qd
=
find_qstr
(
q
);
return
Q_GET_LENGTH
(
qd
);
}
...
...
@@ -205,13 +205,13 @@ const char *qstr_str(qstr q) {
return
(
const
char
*
)
Q_GET_DATA
(
qd
);
}
const
byte
*
qstr_data
(
qstr
q
,
uint
*
len
)
{
const
byte
*
qstr_data
(
qstr
q
,
mp_
uint
_t
*
len
)
{
const
byte
*
qd
=
find_qstr
(
q
);
*
len
=
Q_GET_LENGTH
(
qd
);
return
Q_GET_DATA
(
qd
);
}
void
qstr_pool_info
(
uint
*
n_pool
,
uint
*
n_qstr
,
uint
*
n_str_data_bytes
,
uint
*
n_total_bytes
)
{
void
qstr_pool_info
(
mp_
uint
_t
*
n_pool
,
mp_
uint
_t
*
n_qstr
,
mp_
uint
_t
*
n_str_data_bytes
,
mp_
uint
_t
*
n_total_bytes
)
{
*
n_pool
=
0
;
*
n_qstr
=
0
;
*
n_str_data_bytes
=
0
;
...
...
py/qstr.h
View file @
39dc1454
...
...
@@ -45,20 +45,18 @@ typedef mp_uint_t qstr;
void
qstr_init
(
void
);
mp_uint_t
qstr_compute_hash
(
const
byte
*
data
,
uint
len
);
qstr
qstr_find_strn
(
const
char
*
str
,
uint
str_len
);
// returns MP_QSTR_NULL if not found
mp_uint_t
qstr_compute_hash
(
const
byte
*
data
,
mp_
uint
_t
len
);
qstr
qstr_find_strn
(
const
char
*
str
,
mp_
uint
_t
str_len
);
// returns MP_QSTR_NULL if not found
qstr
qstr_from_str
(
const
char
*
str
);
qstr
qstr_from_strn
(
const
char
*
str
,
uint
len
);
//qstr qstr_from_str_static(const char *str);
//qstr qstr_from_strn_copy(const char *str, int len);
qstr
qstr_from_strn
(
const
char
*
str
,
mp_uint_t
len
);
byte
*
qstr_build_start
(
uint
len
,
byte
**
q_ptr
);
byte
*
qstr_build_start
(
mp_
uint
_t
len
,
byte
**
q_ptr
);
qstr
qstr_build_end
(
byte
*
q_ptr
);
mp_uint_t
qstr_hash
(
qstr
q
);
const
char
*
qstr_str
(
qstr
q
);
uint
qstr_len
(
qstr
q
);
const
byte
*
qstr_data
(
qstr
q
,
uint
*
len
);
mp_
uint
_t
qstr_len
(
qstr
q
);
const
byte
*
qstr_data
(
qstr
q
,
mp_
uint
_t
*
len
);
void
qstr_pool_info
(
uint
*
n_pool
,
uint
*
n_qstr
,
uint
*
n_str_data_bytes
,
uint
*
n_total_bytes
);
void
qstr_pool_info
(
mp_
uint
_t
*
n_pool
,
mp_
uint
_t
*
n_qstr
,
mp_
uint
_t
*
n_str_data_bytes
,
mp_
uint
_t
*
n_total_bytes
);
py/runtime.c
View file @
39dc1454
...
...
@@ -109,14 +109,14 @@ void mp_deinit(void) {
mp_obj_t
mp_load_const_int
(
qstr
qstr
)
{
DEBUG_OP_printf
(
"load '%s'
\n
"
,
qstr_str
(
qstr
));
uint
len
;
mp_
uint
_t
len
;
const
byte
*
data
=
qstr_data
(
qstr
,
&
len
);
return
mp_parse_num_integer
((
const
char
*
)
data
,
len
,
0
);
}
mp_obj_t
mp_load_const_dec
(
qstr
qstr
)
{
DEBUG_OP_printf
(
"load '%s'
\n
"
,
qstr_str
(
qstr
));
uint
len
;
mp_
uint
_t
len
;
const
byte
*
data
=
qstr_data
(
qstr
,
&
len
);
return
mp_parse_num_decimal
((
const
char
*
)
data
,
len
,
true
,
false
);
}
...
...
@@ -128,7 +128,7 @@ mp_obj_t mp_load_const_str(qstr qstr) {
mp_obj_t
mp_load_const_bytes
(
qstr
qstr
)
{
DEBUG_OP_printf
(
"load b'%s'
\n
"
,
qstr_str
(
qstr
));
uint
len
;
mp_
uint
_t
len
;
const
byte
*
data
=
qstr_data
(
qstr
,
&
len
);
return
mp_obj_new_bytes
(
data
,
len
);
}
...
...
unix/main.c
View file @
39dc1454
...
...
@@ -242,9 +242,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mem_info_obj, mem_info);
#endif
STATIC
mp_obj_t
qstr_info
(
void
)
{
uint
n_pool
,
n_qstr
,
n_str_data_bytes
,
n_total_bytes
;
mp_
uint
_t
n_pool
,
n_qstr
,
n_str_data_bytes
,
n_total_bytes
;
qstr_pool_info
(
&
n_pool
,
&
n_qstr
,
&
n_str_data_bytes
,
&
n_total_bytes
);
printf
(
"qstr pool: n_pool=
%u, n_qstr=%u
, n_str_data_bytes=
%u
, n_total_bytes=
%u
\n
"
,
n_pool
,
n_qstr
,
n_str_data_bytes
,
n_total_bytes
);
printf
(
"qstr pool: n_pool=
"
UINT_FMT
", n_qstr="
UINT_FMT
"
, n_str_data_bytes=
"
UINT_FMT
"
, n_total_bytes=
"
UINT_FMT
"
\n
"
,
n_pool
,
n_qstr
,
n_str_data_bytes
,
n_total_bytes
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
qstr_info_obj
,
qstr_info
);
...
...
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