support #!fold-case directive

This commit is contained in:
Yuichi Nishiwaki 2014-07-29 18:12:45 +09:00
parent f639734cb1
commit 52aa837bea
3 changed files with 8 additions and 4 deletions

View File

@ -94,6 +94,7 @@ typedef struct {
xhash macros; xhash macros;
pic_value libs; pic_value libs;
bool rfcase;
xhash rlabels; xhash rlabels;
jmp_buf *jmp; jmp_buf *jmp;

View File

@ -134,13 +134,13 @@ read_directive(pic_state *pic, struct pic_port *port, int c)
switch ((char)peek(port)) { switch ((char)peek(port)) {
case 'n': case 'n':
if (expect(port, "no-fold-case")) { if (expect(port, "no-fold-case")) {
/* :FIXME: set no-fold-case flag */ pic->rfcase = false;
return pic_undef_value(); return pic_undef_value();
} }
break; break;
case 'f': case 'f':
if (expect(port, "fold-case")) { if (expect(port, "fold-case")) {
/* :FIXME: set fold-case flag */ pic->rfcase = true;
return pic_undef_value(); return pic_undef_value();
} }
break; break;
@ -191,13 +191,15 @@ read_symbol(pic_state *pic, struct pic_port *port, int c)
if (len != 0) { if (len != 0) {
c = next(port); c = next(port);
} }
if (pic->rfcase) {
c = tolower(c);
}
len += 1; len += 1;
buf = pic_realloc(pic, buf, len + 1); buf = pic_realloc(pic, buf, len + 1);
buf[len - 1] = (char)c; buf[len - 1] = (char)c;
} while (! isdelim(peek(port))); } while (! isdelim(peek(port)));
buf[len] = '\0'; sym = pic_intern(pic, buf, len);
sym = pic_intern_cstr(pic, buf);
pic_free(pic, buf); pic_free(pic, buf);
return pic_sym_value(sym); return pic_sym_value(sym);

View File

@ -59,6 +59,7 @@ pic_open(int argc, char *argv[], char **envp)
pic->lib = NULL; pic->lib = NULL;
/* reader */ /* reader */
pic->rfcase = false;
xh_init_int(&pic->rlabels, sizeof(pic_value)); xh_init_int(&pic->rlabels, sizeof(pic_value));
/* error handling */ /* error handling */