summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/lexer.c14
-rw-r--r--py/misc.h23
-rw-r--r--py/parse.c2
-rw-r--r--py/repl.c2
-rw-r--r--py/runtime.c10
-rw-r--r--py/unicode.c (renamed from py/misc.c)19
-rw-r--r--stm/Makefile2
-rw-r--r--unix-cpy/Makefile2
-rw-r--r--unix/Makefile2
9 files changed, 28 insertions, 48 deletions
diff --git a/py/lexer.c b/py/lexer.c
index 6e43c7469a..4df91b0365 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -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
diff --git a/py/misc.h b/py/misc.h
index 1a33f0505d..9f83ab526f 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -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 ******************************************************/
diff --git a/py/parse.c b/py/parse.c
index ad9a47ffbc..d3786ba956 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -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;
diff --git a/py/repl.c b/py/repl.c
index ecf6e2d20b..4241ef0e4c 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -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) {
diff --git a/py/runtime.c b/py/runtime.c
index 1598cc291b..748294c350 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -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)));
}
}
diff --git a/py/misc.c b/py/unicode.c
index a5bf8d5534..58c860a0e4 100644
--- a/py/misc.c
+++ b/py/unicode.c
@@ -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);
-}
-*/
diff --git a/stm/Makefile b/stm/Makefile
index 0bbc10af50..c66a2f6ce6 100644
--- a/stm/Makefile
+++ b/stm/Makefile
@@ -45,7 +45,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
- misc.o \
+ unicode.o \
lexer.o \
parse.o \
scope.o \
diff --git a/unix-cpy/Makefile b/unix-cpy/Makefile
index 29ccb32773..a77a6308b1 100644
--- a/unix-cpy/Makefile
+++ b/unix-cpy/Makefile
@@ -14,7 +14,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
- misc.o \
+ unicode.o \
lexer.o \
lexerunix.o \
parse.o \
diff --git a/unix/Makefile b/unix/Makefile
index f191044421..f6b91889bb 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -15,7 +15,7 @@ PY_O = \
malloc.o \
qstr.o \
vstr.o \
- misc.o \
+ unicode.o \
lexer.o \
lexerunix.o \
parse.o \