aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2010-11-09 12:09:54 +0100
committerMike Pall <mike>2010-11-09 12:09:54 +0100
commitad29c1f39feb55d4d443b9352448a12a1be8ee23 (patch)
tree685adbbcad3f65cacf636dda30bf1785191d9c6e
parentfe21a42a92546416cc235511c4e1949d850c0139 (diff)
downloadluajit-ad29c1f39feb55d4d443b9352448a12a1be8ee23.tar.gz
luajit-ad29c1f39feb55d4d443b9352448a12a1be8ee23.tar.bz2
luajit-ad29c1f39feb55d4d443b9352448a12a1be8ee23.zip
Rename character type handling from lj_ctype* to lj_char*.
-rw-r--r--src/Makefile2
-rw-r--r--src/Makefile.dep32
-rw-r--r--src/lib_base.c4
-rw-r--r--src/lib_string.c24
-rw-r--r--src/lj_char.c (renamed from src/lj_ctype.c)21
-rw-r--r--src/lj_char.h40
-rw-r--r--src/lj_ctype.h40
-rw-r--r--src/lj_lex.c20
-rw-r--r--src/lj_str.c14
-rw-r--r--src/ljamalg.c2
10 files changed, 99 insertions, 100 deletions
diff --git a/src/Makefile b/src/Makefile
index 4e18d796..bae6691e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -289,7 +289,7 @@ LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
289 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o 289 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o
290LJLIB_C= $(LJLIB_O:.o=.c) 290LJLIB_C= $(LJLIB_O:.o=.c)
291 291
292LJCORE_O= lj_gc.o lj_err.o lj_ctype.o lj_bc.o lj_obj.o \ 292LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
293 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o \ 293 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o \
294 lj_state.o lj_dispatch.o lj_vmevent.o lj_api.o \ 294 lj_state.o lj_dispatch.o lj_vmevent.o lj_api.o \
295 lj_lex.o lj_parse.o \ 295 lj_lex.o lj_parse.o \
diff --git a/src/Makefile.dep b/src/Makefile.dep
index f2914d6d..b30086d9 100644
--- a/src/Makefile.dep
+++ b/src/Makefile.dep
@@ -15,7 +15,7 @@ lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \
15lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ 15lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
16 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \ 16 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \
17 lj_meta.h lj_state.h lj_bc.h lj_ff.h lj_ffdef.h lj_dispatch.h lj_jit.h \ 17 lj_meta.h lj_state.h lj_bc.h lj_ff.h lj_ffdef.h lj_dispatch.h lj_jit.h \
18 lj_ir.h lj_ctype.h lj_lib.h lj_libdef.h 18 lj_ir.h lj_char.h lj_lib.h lj_libdef.h
19lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ 19lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
20 lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h 20 lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h
21lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ 21lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
@@ -37,7 +37,7 @@ lib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
37 lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h 37 lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h
38lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ 38lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
39 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \ 39 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \
40 lj_state.h lj_ff.h lj_ffdef.h lj_ctype.h lj_lib.h lj_libdef.h 40 lj_state.h lj_ff.h lj_ffdef.h lj_char.h lj_lib.h lj_libdef.h
41lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ 41lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
42 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \ 42 lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \
43 lj_libdef.h 43 lj_libdef.h
@@ -52,7 +52,7 @@ lj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
52 lj_vm.h lj_target.h lj_target_*.h 52 lj_vm.h lj_target.h lj_target_*.h
53lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \ 53lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \
54 lj_bcdef.h 54 lj_bcdef.h
55lj_ctype.o: lj_ctype.c lj_ctype.h lj_def.h lua.h luaconf.h 55lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h
56lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 56lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
57 lj_err.h lj_errmsg.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \ 57 lj_err.h lj_errmsg.h lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h \
58 lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_vm.h luajit.h 58 lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_vm.h luajit.h
@@ -73,7 +73,7 @@ lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
73 lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ 73 lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
74 lj_bc.h lj_traceerr.h lj_lib.h 74 lj_bc.h lj_traceerr.h lj_lib.h
75lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ 75lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
76 lj_err.h lj_errmsg.h lj_str.h lj_lex.h lj_parse.h lj_ctype.h 76 lj_err.h lj_errmsg.h lj_str.h lj_lex.h lj_parse.h lj_char.h
77lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \ 77lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \
78 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \ 78 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \
79 lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_lib.h 79 lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_lib.h
@@ -112,7 +112,7 @@ lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
112 lj_state.h lj_frame.h lj_bc.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h \ 112 lj_state.h lj_frame.h lj_bc.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h \
113 lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h 113 lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h
114lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ 114lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
115 lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ctype.h 115 lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_char.h
116lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ 116lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
117 lj_err.h lj_errmsg.h lj_tab.h 117 lj_err.h lj_errmsg.h lj_tab.h
118lj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 118lj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
@@ -128,15 +128,15 @@ lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
128ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ 128ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \
129 lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \ 129 lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \
130 lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h \ 130 lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h \
131 lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c lj_ctype.c \ 131 lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c lj_char.c lj_char.h \
132 lj_ctype.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c \ 132 lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c lj_udata.c \
133 lj_udata.c lj_meta.c lj_state.c lj_mcode.h lj_lex.h lj_alloc.h \ 133 lj_meta.c lj_state.c lj_mcode.h lj_lex.h lj_alloc.h lj_dispatch.c \
134 lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \ 134 lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h lj_api.c \
135 lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c \ 135 lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c lj_iropt.h \
136 lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \ 136 lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \
137 lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_mcode.c lj_snap.c lj_target.h \ 137 lj_opt_loop.c lj_snap.h lj_mcode.c lj_snap.c lj_target.h lj_target_*.h \
138 lj_target_*.h lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c \ 138 lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c lj_trace.c \
139 lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \ 139 lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lualib.h \
140 lualib.h lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \ 140 lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c lib_os.c \
141 lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_init.c 141 lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_init.c
142luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h 142luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h
diff --git a/src/lib_base.c b/src/lib_base.c
index 0a13f36b..6a842d2c 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -25,7 +25,7 @@
25#include "lj_bc.h" 25#include "lj_bc.h"
26#include "lj_ff.h" 26#include "lj_ff.h"
27#include "lj_dispatch.h" 27#include "lj_dispatch.h"
28#include "lj_ctype.h" 28#include "lj_char.h"
29#include "lj_lib.h" 29#include "lj_lib.h"
30 30
31/* -- Base library: checks ------------------------------------------------ */ 31/* -- Base library: checks ------------------------------------------------ */
@@ -197,7 +197,7 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
197 lj_err_arg(L, 2, LJ_ERR_BASERNG); 197 lj_err_arg(L, 2, LJ_ERR_BASERNG);
198 ul = strtoul(p, &ep, base); 198 ul = strtoul(p, &ep, base);
199 if (p != ep) { 199 if (p != ep) {
200 while (lj_ctype_isspace((unsigned char)(*ep))) ep++; 200 while (lj_char_isspace((unsigned char)(*ep))) ep++;
201 if (*ep == '\0') { 201 if (*ep == '\0') {
202 setnumV(L->base-1, cast_num(ul)); 202 setnumV(L->base-1, cast_num(ul));
203 return FFH_RES(1); 203 return FFH_RES(1);
diff --git a/src/lib_string.c b/src/lib_string.c
index 8ca9ef01..73a09583 100644
--- a/src/lib_string.c
+++ b/src/lib_string.c
@@ -22,7 +22,7 @@
22#include "lj_tab.h" 22#include "lj_tab.h"
23#include "lj_state.h" 23#include "lj_state.h"
24#include "lj_ff.h" 24#include "lj_ff.h"
25#include "lj_ctype.h" 25#include "lj_char.h"
26#include "lj_lib.h" 26#include "lj_lib.h"
27 27
28/* ------------------------------------------------------------------------ */ 28/* ------------------------------------------------------------------------ */
@@ -181,9 +181,9 @@ static const char *classend(MatchState *ms, const char *p)
181} 181}
182 182
183static const unsigned char match_class_map[32] = { 183static const unsigned char match_class_map[32] = {
184 0, LJ_CTYPE_ALPHA, 0, LJ_CTYPE_CNTRL, LJ_CTYPE_DIGIT, 0,0,0,0,0,0,0, 184 0, LJ_CHAR_ALPHA, 0, LJ_CHAR_CNTRL, LJ_CHAR_DIGIT, 0,0,0,0,0,0,0,
185 LJ_CTYPE_LOWER, 0,0,0, LJ_CTYPE_PUNCT, 0,0, LJ_CTYPE_SPACE, 0, 185 LJ_CHAR_LOWER, 0,0,0, LJ_CHAR_PUNCT, 0,0, LJ_CHAR_SPACE, 0,
186 LJ_CTYPE_UPPER, 0, LJ_CTYPE_ALNUM, LJ_CTYPE_XDIGIT, 0,0,0,0,0,0,0 186 LJ_CHAR_UPPER, 0, LJ_CHAR_ALNUM, LJ_CHAR_XDIGIT, 0,0,0,0,0,0,0
187}; 187};
188 188
189static int match_class(int c, int cl) 189static int match_class(int c, int cl)
@@ -191,7 +191,7 @@ static int match_class(int c, int cl)
191 if ((cl & 0xc0) == 0x40) { 191 if ((cl & 0xc0) == 0x40) {
192 int t = match_class_map[(cl&0x1f)]; 192 int t = match_class_map[(cl&0x1f)];
193 if (t) { 193 if (t) {
194 t = lj_ctype_isa(c, t); 194 t = lj_char_isa(c, t);
195 return (cl & 0x20) ? t : !t; 195 return (cl & 0x20) ? t : !t;
196 } 196 }
197 if (cl == 'z') return c == 0; 197 if (cl == 'z') return c == 0;
@@ -353,7 +353,7 @@ static const char *match(MatchState *ms, const char *s, const char *p)
353 goto init; /* else return match(ms, s, ep); */ 353 goto init; /* else return match(ms, s, ep); */
354 } 354 }
355 default: 355 default:
356 if (lj_ctype_isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ 356 if (lj_char_isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
357 s = match_capture(ms, s, uchar(*(p+1))); 357 s = match_capture(ms, s, uchar(*(p+1)));
358 if (s == NULL) return NULL; 358 if (s == NULL) return NULL;
359 p+=2; 359 p+=2;
@@ -549,7 +549,7 @@ static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
549 luaL_addchar(b, news[i]); 549 luaL_addchar(b, news[i]);
550 } else { 550 } else {
551 i++; /* skip ESC */ 551 i++; /* skip ESC */
552 if (!lj_ctype_isdigit(uchar(news[i]))) { 552 if (!lj_char_isdigit(uchar(news[i]))) {
553 luaL_addchar(b, news[i]); 553 luaL_addchar(b, news[i]);
554 } else if (news[i] == '0') { 554 } else if (news[i] == '0') {
555 luaL_addlstring(b, s, (size_t)(e - s)); 555 luaL_addlstring(b, s, (size_t)(e - s));
@@ -679,14 +679,14 @@ static const char *scanformat(lua_State *L, const char *strfrmt, char *form)
679 while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */ 679 while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */
680 if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS)) 680 if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS))
681 lj_err_caller(L, LJ_ERR_STRFMTR); 681 lj_err_caller(L, LJ_ERR_STRFMTR);
682 if (lj_ctype_isdigit(uchar(*p))) p++; /* skip width */ 682 if (lj_char_isdigit(uchar(*p))) p++; /* skip width */
683 if (lj_ctype_isdigit(uchar(*p))) p++; /* (2 digits at most) */ 683 if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */
684 if (*p == '.') { 684 if (*p == '.') {
685 p++; 685 p++;
686 if (lj_ctype_isdigit(uchar(*p))) p++; /* skip precision */ 686 if (lj_char_isdigit(uchar(*p))) p++; /* skip precision */
687 if (lj_ctype_isdigit(uchar(*p))) p++; /* (2 digits at most) */ 687 if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */
688 } 688 }
689 if (lj_ctype_isdigit(uchar(*p))) 689 if (lj_char_isdigit(uchar(*p)))
690 lj_err_caller(L, LJ_ERR_STRFMTW); 690 lj_err_caller(L, LJ_ERR_STRFMTW);
691 *(form++) = '%'; 691 *(form++) = '%';
692 strncpy(form, strfrmt, (size_t)(p - strfrmt + 1)); 692 strncpy(form, strfrmt, (size_t)(p - strfrmt + 1));
diff --git a/src/lj_ctype.c b/src/lj_char.c
index 9f19b879..11f23efe 100644
--- a/src/lj_ctype.c
+++ b/src/lj_char.c
@@ -1,5 +1,5 @@
1/* 1/*
2** Internal CTYPE replacement. 2** Character types.
3** Donated to the public domain. 3** Donated to the public domain.
4** 4**
5** This is intended to replace the problematic libc single-byte NLS functions. 5** This is intended to replace the problematic libc single-byte NLS functions.
@@ -7,22 +7,21 @@
7** on POSIX systems. It never worked too well on Windows systems since hardly 7** on POSIX systems. It never worked too well on Windows systems since hardly
8** anyone bothered to call setlocale(). 8** anyone bothered to call setlocale().
9** 9**
10** Instead this table is hardcoded for ASCII, except for identifiers. These 10** This table is hardcoded for ASCII. Identifiers include the characters
11** include the characters 128-255, too. This allows for the use of all 11** 128-255, too. This allows for the use of all non-ASCII chars as identifiers
12** non-ASCII chars as identifiers in the lexer. This is a broad definition, 12** in the lexer. This is a broad definition, but works well in practice
13** but works well in practice for both UTF-8 locales and most single-byte 13** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*).
14** locales (such as ISO-8859-*).
15** 14**
16** If you really need proper ctypes for UTF-8 strings, please use an add-on 15** If you really need proper character types for UTF-8 strings, please use
17** library such as slnunicode: http://luaforge.net/projects/sln/ 16** an add-on library such as slnunicode: http://luaforge.net/projects/sln/
18*/ 17*/
19 18
20#define lj_ctype_c 19#define lj_char_c
21#define LUA_CORE 20#define LUA_CORE
22 21
23#include "lj_ctype.h" 22#include "lj_char.h"
24 23
25LJ_DATADEF const uint8_t lj_ctype_bits[257] = { 24LJ_DATADEF const uint8_t lj_char_bits[257] = {
26 0, 25 0,
27 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, 26 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1,
28 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
diff --git a/src/lj_char.h b/src/lj_char.h
new file mode 100644
index 00000000..d474285c
--- /dev/null
+++ b/src/lj_char.h
@@ -0,0 +1,40 @@
1/*
2** Character types.
3** Donated to the public domain.
4*/
5
6#ifndef _LJ_CHAR_H
7#define _LJ_CHAR_H
8
9#include "lj_def.h"
10
11#define LJ_CHAR_CNTRL 0x01
12#define LJ_CHAR_SPACE 0x02
13#define LJ_CHAR_PUNCT 0x04
14#define LJ_CHAR_DIGIT 0x08
15#define LJ_CHAR_XDIGIT 0x10
16#define LJ_CHAR_UPPER 0x20
17#define LJ_CHAR_LOWER 0x40
18#define LJ_CHAR_IDENT 0x80
19#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER)
20#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)
21
22/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
23#define lj_char_isa(c, t) (lj_char_bits[(c)+1] & t)
24#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL)
25#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE)
26#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT)
27#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT)
28#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT)
29#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER)
30#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER)
31#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT)
32#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA)
33#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM)
34
35#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1))
36#define lj_char_tolower(c) ((c) + lj_char_isupper(c))
37
38LJ_DATA const uint8_t lj_char_bits[257];
39
40#endif
diff --git a/src/lj_ctype.h b/src/lj_ctype.h
deleted file mode 100644
index c4cdff84..00000000
--- a/src/lj_ctype.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2** Internal CTYPE replacement.
3** Donated to the public domain.
4*/
5
6#ifndef _LJ_CTYPE_H
7#define _LJ_CTYPE_H
8
9#include "lj_def.h"
10
11#define LJ_CTYPE_CNTRL 0x01
12#define LJ_CTYPE_SPACE 0x02
13#define LJ_CTYPE_PUNCT 0x04
14#define LJ_CTYPE_DIGIT 0x08
15#define LJ_CTYPE_XDIGIT 0x10
16#define LJ_CTYPE_UPPER 0x20
17#define LJ_CTYPE_LOWER 0x40
18#define LJ_CTYPE_IDENT 0x80
19#define LJ_CTYPE_ALPHA (LJ_CTYPE_LOWER|LJ_CTYPE_UPPER)
20#define LJ_CTYPE_ALNUM (LJ_CTYPE_ALPHA|LJ_CTYPE_DIGIT)
21
22/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
23#define lj_ctype_isa(c, t) (lj_ctype_bits[(c)+1] & t)
24#define lj_ctype_iscntrl(c) lj_ctype_isa((c), LJ_CTYPE_CNTRL)
25#define lj_ctype_isspace(c) lj_ctype_isa((c), LJ_CTYPE_SPACE)
26#define lj_ctype_ispunct(c) lj_ctype_isa((c), LJ_CTYPE_PUNCT)
27#define lj_ctype_isdigit(c) lj_ctype_isa((c), LJ_CTYPE_DIGIT)
28#define lj_ctype_isxdigit(c) lj_ctype_isa((c), LJ_CTYPE_XDIGIT)
29#define lj_ctype_isupper(c) lj_ctype_isa((c), LJ_CTYPE_UPPER)
30#define lj_ctype_islower(c) lj_ctype_isa((c), LJ_CTYPE_LOWER)
31#define lj_ctype_isident(c) lj_ctype_isa((c), LJ_CTYPE_IDENT)
32#define lj_ctype_isalpha(c) lj_ctype_isa((c), LJ_CTYPE_ALPHA)
33#define lj_ctype_isalnum(c) lj_ctype_isa((c), LJ_CTYPE_ALNUM)
34
35#define lj_ctype_toupper(c) ((c) - (lj_ctype_islower(c) >> 1))
36#define lj_ctype_tolower(c) ((c) + lj_ctype_isupper(c))
37
38LJ_DATA const uint8_t lj_ctype_bits[257];
39
40#endif
diff --git a/src/lj_lex.c b/src/lj_lex.c
index d02ae849..d3544e8e 100644
--- a/src/lj_lex.c
+++ b/src/lj_lex.c
@@ -15,7 +15,7 @@
15#include "lj_str.h" 15#include "lj_str.h"
16#include "lj_lex.h" 16#include "lj_lex.h"
17#include "lj_parse.h" 17#include "lj_parse.h"
18#include "lj_ctype.h" 18#include "lj_char.h"
19 19
20/* Lua lexer token names. */ 20/* Lua lexer token names. */
21static const char *const tokennames[] = { 21static const char *const tokennames[] = {
@@ -80,11 +80,11 @@ static void inclinenumber(LexState *ls)
80static void read_numeral(LexState *ls, TValue *tv) 80static void read_numeral(LexState *ls, TValue *tv)
81{ 81{
82 int c; 82 int c;
83 lua_assert(lj_ctype_isdigit(ls->current)); 83 lua_assert(lj_char_isdigit(ls->current));
84 do { 84 do {
85 c = ls->current; 85 c = ls->current;
86 save_and_next(ls); 86 save_and_next(ls);
87 } while (lj_ctype_isident(ls->current) || ls->current == '.' || 87 } while (lj_char_isident(ls->current) || ls->current == '.' ||
88 ((ls->current == '-' || ls->current == '+') && 88 ((ls->current == '-' || ls->current == '+') &&
89 ((c & ~0x20) == 'E' || (c & ~0x20) == 'P'))); 89 ((c & ~0x20) == 'E' || (c & ~0x20) == 'P')));
90 save(ls, '\0'); 90 save(ls, '\0');
@@ -166,7 +166,7 @@ static void read_string(LexState *ls, int delim, TValue *tv)
166 case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue; 166 case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
167 case END_OF_STREAM: continue; /* will raise an error next loop */ 167 case END_OF_STREAM: continue; /* will raise an error next loop */
168 default: 168 default:
169 if (!lj_ctype_isdigit(ls->current)) { 169 if (!lj_char_isdigit(ls->current)) {
170 save_and_next(ls); /* handles \\, \", \', and \? */ 170 save_and_next(ls); /* handles \\, \", \', and \? */
171 } else { /* \xxx */ 171 } else { /* \xxx */
172 int i = 0; 172 int i = 0;
@@ -174,7 +174,7 @@ static void read_string(LexState *ls, int delim, TValue *tv)
174 do { 174 do {
175 c = 10*c + (ls->current-'0'); 175 c = 10*c + (ls->current-'0');
176 next(ls); 176 next(ls);
177 } while (++i<3 && lj_ctype_isdigit(ls->current)); 177 } while (++i<3 && lj_char_isdigit(ls->current));
178 if (c > 255) 178 if (c > 255)
179 lj_lex_error(ls, TK_string, LJ_ERR_XESC); 179 lj_lex_error(ls, TK_string, LJ_ERR_XESC);
180 save(ls, c); 180 save(ls, c);
@@ -200,16 +200,16 @@ static int llex(LexState *ls, TValue *tv)
200{ 200{
201 lj_str_resetbuf(&ls->sb); 201 lj_str_resetbuf(&ls->sb);
202 for (;;) { 202 for (;;) {
203 if (lj_ctype_isident(ls->current)) { 203 if (lj_char_isident(ls->current)) {
204 GCstr *s; 204 GCstr *s;
205 if (lj_ctype_isdigit(ls->current)) { /* Numeric literal. */ 205 if (lj_char_isdigit(ls->current)) { /* Numeric literal. */
206 read_numeral(ls, tv); 206 read_numeral(ls, tv);
207 return TK_number; 207 return TK_number;
208 } 208 }
209 /* Identifier or reserved word. */ 209 /* Identifier or reserved word. */
210 do { 210 do {
211 save_and_next(ls); 211 save_and_next(ls);
212 } while (lj_ctype_isident(ls->current)); 212 } while (lj_char_isident(ls->current));
213 s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n); 213 s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n);
214 if (s->reserved > 0) /* Reserved word? */ 214 if (s->reserved > 0) /* Reserved word? */
215 return TK_OFS + s->reserved; 215 return TK_OFS + s->reserved;
@@ -282,7 +282,7 @@ static int llex(LexState *ls, TValue *tv)
282 return TK_dots; /* ... */ 282 return TK_dots; /* ... */
283 } 283 }
284 return TK_concat; /* .. */ 284 return TK_concat; /* .. */
285 } else if (!lj_ctype_isdigit(ls->current)) { 285 } else if (!lj_char_isdigit(ls->current)) {
286 return '.'; 286 return '.';
287 } else { 287 } else {
288 read_numeral(ls, tv); 288 read_numeral(ls, tv);
@@ -369,7 +369,7 @@ const char *lj_lex_token2str(LexState *ls, LexToken token)
369{ 369{
370 if (token > TK_OFS) 370 if (token > TK_OFS)
371 return tokennames[token-TK_OFS-1]; 371 return tokennames[token-TK_OFS-1];
372 else if (!lj_ctype_iscntrl(token)) 372 else if (!lj_char_iscntrl(token))
373 return lj_str_pushf(ls->L, "%c", token); 373 return lj_str_pushf(ls->L, "%c", token);
374 else 374 else
375 return lj_str_pushf(ls->L, "char(%d)", token); 375 return lj_str_pushf(ls->L, "char(%d)", token);
diff --git a/src/lj_str.c b/src/lj_str.c
index 618687f5..5e69ed0d 100644
--- a/src/lj_str.c
+++ b/src/lj_str.c
@@ -16,7 +16,7 @@
16#include "lj_err.h" 16#include "lj_err.h"
17#include "lj_str.h" 17#include "lj_str.h"
18#include "lj_state.h" 18#include "lj_state.h"
19#include "lj_ctype.h" 19#include "lj_char.h"
20 20
21/* -- String interning ---------------------------------------------------- */ 21/* -- String interning ---------------------------------------------------- */
22 22
@@ -180,27 +180,27 @@ int LJ_FASTCALL lj_str_numconv(const char *s, TValue *n)
180{ 180{
181 lua_Number sign = 1; 181 lua_Number sign = 1;
182 const uint8_t *p = (const uint8_t *)s; 182 const uint8_t *p = (const uint8_t *)s;
183 while (lj_ctype_isspace(*p)) p++; 183 while (lj_char_isspace(*p)) p++;
184 if (*p == '-') { p++; sign = -1; } else if (*p == '+') { p++; } 184 if (*p == '-') { p++; sign = -1; } else if (*p == '+') { p++; }
185 if ((uint32_t)(*p - '0') < 10) { 185 if ((uint32_t)(*p - '0') < 10) {
186 uint32_t k = (uint32_t)(*p++ - '0'); 186 uint32_t k = (uint32_t)(*p++ - '0');
187 if (k == 0 && ((*p & ~0x20) == 'X')) { 187 if (k == 0 && ((*p & ~0x20) == 'X')) {
188 p++; 188 p++;
189 if (!lj_ctype_isxdigit(*p)) 189 if (!lj_char_isxdigit(*p))
190 return 0; /* Don't accept '0x' without hex digits. */ 190 return 0; /* Don't accept '0x' without hex digits. */
191 do { 191 do {
192 if (k >= 0x10000000) goto parsedbl; 192 if (k >= 0x10000000) goto parsedbl;
193 k = (k << 4) + (*p & 15u); 193 k = (k << 4) + (*p & 15u);
194 if (!lj_ctype_isdigit(*p)) k += 9; 194 if (!lj_char_isdigit(*p)) k += 9;
195 p++; 195 p++;
196 } while (lj_ctype_isxdigit(*p)); 196 } while (lj_char_isxdigit(*p));
197 } else { 197 } else {
198 while ((uint32_t)(*p - '0') < 10) { 198 while ((uint32_t)(*p - '0') < 10) {
199 if (k >= 0x19999999) goto parsedbl; 199 if (k >= 0x19999999) goto parsedbl;
200 k = k * 10u + (uint32_t)(*p++ - '0'); 200 k = k * 10u + (uint32_t)(*p++ - '0');
201 } 201 }
202 } 202 }
203 while (LJ_UNLIKELY(lj_ctype_isspace(*p))) p++; 203 while (LJ_UNLIKELY(lj_char_isspace(*p))) p++;
204 if (LJ_LIKELY(*p == '\0')) { 204 if (LJ_LIKELY(*p == '\0')) {
205 setnumV(n, sign * cast_num(k)); 205 setnumV(n, sign * cast_num(k));
206 return 1; 206 return 1;
@@ -213,7 +213,7 @@ parsedbl:
213 setnumV(&tv, lua_str2number(s, &endptr)); 213 setnumV(&tv, lua_str2number(s, &endptr));
214 if (endptr == s) return 0; /* Conversion failed. */ 214 if (endptr == s) return 0; /* Conversion failed. */
215 if (LJ_UNLIKELY(*endptr != '\0')) { 215 if (LJ_UNLIKELY(*endptr != '\0')) {
216 while (lj_ctype_isspace((uint8_t)*endptr)) endptr++; 216 while (lj_char_isspace((uint8_t)*endptr)) endptr++;
217 if (*endptr != '\0') return 0; /* Invalid trailing characters? */ 217 if (*endptr != '\0') return 0; /* Invalid trailing characters? */
218 } 218 }
219 if (LJ_LIKELY(!tvisnan(&tv))) 219 if (LJ_LIKELY(!tvisnan(&tv)))
diff --git a/src/ljamalg.c b/src/ljamalg.c
index 5d66a9eb..4f3b5025 100644
--- a/src/ljamalg.c
+++ b/src/ljamalg.c
@@ -26,7 +26,7 @@
26 26
27#include "lj_gc.c" 27#include "lj_gc.c"
28#include "lj_err.c" 28#include "lj_err.c"
29#include "lj_ctype.c" 29#include "lj_char.c"
30#include "lj_bc.c" 30#include "lj_bc.c"
31#include "lj_obj.c" 31#include "lj_obj.c"
32#include "lj_str.c" 32#include "lj_str.c"