10000 Put unicode functions in unicode.c, and tidy their names. · jpralves/micropython@8cc96a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8cc96a3

Browse files
committed
Put unicode functions in unicode.c, and tidy their names.
1 parent 212c296 commit 8cc96a3

File tree

9 files changed

+28
-48
lines changed

9 files changed

+28
-48
lines changed

py/lexer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ void mp_token_show(const mp_token_t *tok) {
5454
const char *j = i + tok->len;
5555
printf(" ");
5656
while (i < j) {
57-
unichar c = g_utf8_get_char(i);
58-
i = g_utf8_next_char(i);
59-
if (g_unichar_isprint(c)) {
57+
unichar c = utf8_get_char(i);
58+
i = utf8_next_char(i);
59+
if (unichar_isprint(c)) {
6060
printf("%c", c);
6161
} else {
6262
printf("?");
@@ -116,19 +116,19 @@ static bool is_char_and(mp_lexer_t *lex, char c1, char c2) {
116116
}
117117

118118
static bool is_whitespace(mp_lexer_t *lex) {
119-
return g_unichar_isspace(lex->chr0);
119+
return unichar_isspace(lex->chr0);
120120
}
121121

122122
static bool is_letter(mp_lexer_t *lex) {
123-
return g_unichar_isalpha(lex->chr0);
123+
return unichar_isalpha(lex->chr0);
124124
}
125125

126126
static bool is_digit(mp_lexer_t *lex) {
127-
return g_unichar_isdigit(lex->chr0);
127+
return unichar_isdigit(lex->chr0);
128128
}
129129

130130
static bool is_following_digit(mp_lexer_t *lex) {
131-
return g_unichar_isdigit(lex->chr1);
131+
return unichar_isdigit(lex->chr1);
132132
}
133133

134134
// TODO UNICODE include unicode characters in definition of identifiers

py/misc.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,13 @@ int m_get_total_bytes_allocated(void);
3737

3838
typedef int unichar; // TODO
3939

40-
unichar g_utf8_get_char(const char *s);
41-
char *g_utf8_next_char(const char *s);
40+
unichar utf8_get_char(const char *s);
41+
char *utf8_next_char(const char *s);
4242

43-
bool g_unichar_isspace(unichar c);
44-
bool g_unichar_isalpha(unichar c);
45-
bool g_unichar_isprint(unichar c);
46-
bool g_unichar_isdigit(unichar c);
47-
48-
//char *g_strdup(const char *s);
49-
50-
/** blob ********************************************************/
51-
52-
/*
53-
unsigned short decode_le16(byte *buf);
54-
unsigned int decode_le32(byte *buf);
55-
void encode_le16(byte *buf, unsigned short i);
56-
void encode_le32(byte *buf, unsigned int i);
57-
*/
43+
bool unichar_isspace(unichar c);
44+
bool unichar_isalpha(unichar c);
45+
bool unichar_isprint(unichar c);
46+
bool unichar_isdigit(unichar c);
5847

5948
/** string ******************************************************/
6049

py/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
212212
}
213213
}
214214
for (; i < len; i++) {
215-
if (g_unichar_isdigit(str[i]) && str[i] - '0' < base) {
215+
if (unichar_isdigit(str[i]) && str[i] - '0' < base) {
216216
int_val = base * int_val + str[i] - '0';
217217
} else if (base == 16 && 'a' <= str[i] && str[i] <= 'f') {
218218
int_val = base * int_val + str[i] - 'a' + 10;

py/repl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bool str_startswith_word(const char *str, const char *head) {
88
return false;
99
}
1010
}
11-
return head[i] == '\0' && (str[i] == '\0' || !g_unichar_isalpha(str[i]));
11+
return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i]));
1212
}
1313

1414
bool mp_repl_is_compound_stmt(const char *line) {

py/runtime.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args)
226226
unique_codes[unique_code_id].is_generator = false;
227227
unique_codes[unique_code_id].u_native.fun = fun;
228228

229-
printf("native code: %d bytes\n", len);
229+
//printf("native code: %d bytes\n", len);
230230

231231
#ifdef DEBUG_PRINT
232232
DEBUG_printf("assign native code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
@@ -421,8 +421,7 @@ mp_obj_t rt_load_build_class(void) {
421421
DEBUG_OP_printf("load_build_class\n");
422422
mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, rt_q___build_class__, false);
423423
if (elem == NULL) {
424-
printf("name doesn't exist: __build_class__\n");
425-
assert(0);
424+
nlr_jump(mp_obj_new_exception_msg(rt_q_NameError, "name '__build_class__' is not defined"));
426425
}
427426
return elem->value;
428427
}
@@ -525,7 +524,7 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
525524
break;
526525
}
527526

528-
default: printf("%d\n", op); assert(0);
527+
default: assert(0);
529528
}
530529
if (fit_small_int(lhs_val)) {
531530
return MP_OBJ_NEW_SMALL_INT(lhs_val);
@@ -831,8 +830,7 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
831830
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) {
832831
mp_obj_instance_store_attr(base, attr, value);
833832
} else {
834-
printf("?AttributeError: '%s' object has no attribute '%s'\n", mp_obj_get_type_str(base), qstr_str(attr));
835-
assert(0);
833+
nlr_jump(mp_obj_new_exception_msg_2_args(rt_q_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
836834
}
837835
}
838836

py/misc.c renamed to py/unicode.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <stdint.h>
2-
#include <string.h>
32

43
#include "misc.h"
54

@@ -39,27 +38,27 @@ static const uint8_t attr[] = {
3938
AT_LO, AT_LO, AT_LO, AT_PR, AT_PR, AT_PR, AT_PR, 0
4039
};
4140

42-
unichar g_utf8_get_char(const char *s) {
41+
unichar utf8_get_char(const char *s) {
4342
return *s;
4443
}
4544

46-
char *g_utf8_next_char(const char *s) {
45+
char *utf8_next_char(const char *s) {
4746
return (char*)(s + 1);
4847
}
4948

50-
bool g_unichar_isspace(unichar c) {
49+
bool unichar_isspace(unichar c) {
5150
return c < 128 && (attr[c] & FL_SPACE) != 0;
5251
}
5352

54-
bool g_unichar_isalpha(unichar c) {
53+
bool unichar_isalpha(unichar c) {
5554
return c < 128 && (attr[c] & FL_ALPHA) != 0;
5655
}
5756

58-
bool g_unichar_isprint(unichar c) {
57+
bool unichar_isprint(unichar c) {
5958
return c < 128 && (attr[c] & FL_PRINT) != 0;
6059
}
6160

62-
bool g_unichar_isdigit(unichar c) {
61+
bool unichar_isdigit(unichar c) {
6362
return c < 128 && (attr[c] & FL_DIGIT) != 0;
6463
}
6564

@@ -76,9 +75,3 @@ bool char_is_lower(unichar c) {
7675
return c < 128 && (attr[c] & FL_LOWER) != 0;
7776
}
7877
*/
79-
80-
/*
81-
char *g_strdup(const char *s) {
82-
return strdup(s);
83-
}
84-
*/

stm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PY_O = \
4545
malloc.o \
4646
qstr.o \
4747
vstr.o \
48-
misc.o \
48+
unicode.o \
4949
lexer.o \
5050
parse.o \
5151
scope.o \

unix-cpy/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PY_O = \
1414
malloc.o \
1515
qstr.o \
1616
vstr.o \
17-
misc.o \
17+
unicode.o \
1818
lexer.o \
1919
lexerunix.o \
2020
parse.o \

unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PY_O = \
1515
malloc.o \
1616
qstr.o \
1717
vstr.o \
18-
misc.o \
18+
unicode.o \
1919
lexer.o \
2020
lexerunix.o \
2121
parse.o \

0 commit comments

Comments
 (0)
0