Put unicode functions in unicode.c, and tidy their names.

This commit is contained in:
Damien George 2013-12-30 18:23:50 +00:00
parent 212c296c0b
commit 8cc96a35e5
9 changed files with 28 additions and 48 deletions

View File

@ -54,9 +54,9 @@ void mp_token_show(const mp_token_t *tok) {
const char *j = i + tok->len;
printf(" ");
while (i < j) {
unichar c = g_utf8_get_char(i);
i = g_utf8_next_char(i);
if (g_unichar_isprint(c)) {
unichar c = utf8_get_char(i);
i = utf8_next_char(i);
if (unichar_isprint(c)) {
printf("%c", c);
} else {
printf("?");
@ -116,19 +116,19 @@ static bool is_char_and(mp_lexer_t *lex, char c1, char c2) {
}
static bool is_whitespace(mp_lexer_t *lex) {
return g_unichar_isspace(lex->chr0);
return unichar_isspace(lex->chr0);
}
static bool is_letter(mp_lexer_t *lex) {
return g_unichar_isalpha(lex->chr0);
return unichar_isalpha(lex->chr0);
}
static bool is_digit(mp_lexer_t *lex) {
return g_unichar_isdigit(lex->chr0);
return unichar_isdigit(lex->chr0);
}
static bool is_following_digit(mp_lexer_t *lex) {
return g_unichar_isdigit(lex->chr1);
return unichar_isdigit(lex->chr1);
}
// TODO UNICODE include unicode characters in definition of identifiers

View File

@ -37,24 +37,13 @@ int m_get_total_bytes_allocated(void);
typedef int unichar; // TODO
unichar g_utf8_get_char(const char *s);
char *g_utf8_next_char(const char *s);
unichar utf8_get_char(const char *s);
char *utf8_next_char(const char *s);
bool g_unichar_isspace(unichar c);
bool g_unichar_isalpha(unichar c);
bool g_unichar_isprint(unichar c);
bool g_unichar_isdigit(unichar c);
//char *g_strdup(const char *s);
/** blob ********************************************************/
/*
unsigned short decode_le16(byte *buf);
unsigned int decode_le32(byte *buf);
void encode_le16(byte *buf, unsigned short i);
void encode_le32(byte *buf, unsigned int i);
*/
bool unichar_isspace(unichar c);
bool unichar_isalpha(unichar c);
bool unichar_isprint(unichar c);
bool unichar_isdigit(unichar c);
/** string ******************************************************/

View File

@ -212,7 +212,7 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
}
}
for (; i < len; i++) {
if (g_unichar_isdigit(str[i]) && str[i] - '0' < base) {
if (unichar_isdigit(str[i]) && str[i] - '0' < base) {
int_val = base * int_val + str[i] - '0';
} else if (base == 16 && 'a' <= str[i] && str[i] <= 'f') {
int_val = base * int_val + str[i] - 'a' + 10;

View File

@ -8,7 +8,7 @@ bool str_startswith_word(const char *str, const char *head) {
return false;
}
}
return head[i] == '\0' && (str[i] == '\0' || !g_unichar_isalpha(str[i]));
return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i]));
}
bool mp_repl_is_compound_stmt(const char *line) {

View File

@ -226,7 +226,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args)
unique_codes[unique_code_id].is_generator = false;
unique_codes[unique_code_id].u_native.fun = fun;
printf("native code: %d bytes\n", len);
//printf("native code: %d bytes\n", len);
#ifdef DEBUG_PRINT
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) {
DEBUG_OP_printf("load_build_class\n");
mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, rt_q___build_class__, false);
if (elem == NULL) {
printf("name doesn't exist: __build_class__\n");
assert(0);
nlr_jump(mp_obj_new_exception_msg(rt_q_NameError, "name '__build_class__' is not defined"));
}
return elem->value;
}
@ -525,7 +524,7 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
break;
}
default: printf("%d\n", op); assert(0);
default: assert(0);
}
if (fit_small_int(lhs_val)) {
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) {
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) {
mp_obj_instance_store_attr(base, attr, value);
} else {
printf("?AttributeError: '%s' object has no attribute '%s'\n", mp_obj_get_type_str(base), qstr_str(attr));
assert(0);
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)));
}
}

View File

@ -1,5 +1,4 @@
#include <stdint.h>
#include <string.h>
#include "misc.h"
@ -39,27 +38,27 @@ static const uint8_t attr[] = {
AT_LO, AT_LO, AT_LO, AT_PR, AT_PR, AT_PR, AT_PR, 0
};
unichar g_utf8_get_char(const char *s) {
unichar utf8_get_char(const char *s) {
return *s;
}
char *g_utf8_next_char(const char *s) {
char *utf8_next_char(const char *s) {
return (char*)(s + 1);
}
bool g_unichar_isspace(unichar c) {
bool unichar_isspace(unichar c) {
return c < 128 && (attr[c] & FL_SPACE) != 0;
}
bool g_unichar_isalpha(unichar c) {
bool unichar_isalpha(unichar c) {
return c < 128 && (attr[c] & FL_ALPHA) != 0;
}
bool g_unichar_isprint(unichar c) {
bool unichar_isprint(unichar c) {
return c < 128 && (attr[c] & FL_PRINT) != 0;
}
bool g_unichar_isdigit(unichar c) {
bool unichar_isdigit(unichar c) {
return c < 128 && (attr[c] & FL_DIGIT) != 0;
}
@ -76,9 +75,3 @@ bool char_is_lower(unichar c) {
return c < 128 && (attr[c] & FL_LOWER) != 0;
}
*/
/*
char *g_strdup(const char *s) {
return strdup(s);
}
*/

View File

@ -45,7 +45,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
misc.o \
unicode.o \
lexer.o \
parse.o \
scope.o \

View File

@ -14,7 +14,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
misc.o \
unicode.o \
lexer.o \
lexerunix.o \
parse.o \

View File

@ -15,7 +15,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
misc.o \
unicode.o \
lexer.o \
lexerunix.o \
parse.o \