Added hex output
This commit is contained in:
parent
549d7d5218
commit
f7a2b49120
|
@ -0,0 +1,5 @@
|
|||
?(?: ?:) \#48
|
||||
?(?: ?:) \101
|
||||
?(?: ?:) \#6c
|
||||
?(?: ?:) \108
|
||||
?(?: ?:) \#6f
|
2
makefile
2
makefile
|
@ -10,7 +10,7 @@ dest:
|
|||
run: all bin/modal
|
||||
@ bin/modal -q examples/hello.modal
|
||||
debug: all bin/modal-debug
|
||||
@ bin/modal-debug -a examples/unicode.modal
|
||||
@ bin/modal-debug -a examples/binary.modal
|
||||
test: all bin/modal-debug bin/modal
|
||||
@ bin/modal -v
|
||||
@ bin/modal-debug -q examples/fizzbuzz.modal
|
||||
|
|
33
src/modal.c
33
src/modal.c
|
@ -21,14 +21,14 @@ copy(char *src, char *dst, int length)
|
|||
return dst;
|
||||
}
|
||||
|
||||
static int
|
||||
sint(char *s)
|
||||
int
|
||||
chex(char c)
|
||||
{
|
||||
char c;
|
||||
int r = 0, n = 1;
|
||||
if(*s == '-') { n = -1, s++; }
|
||||
while((c = *s++) && !spacer(c)) r = r * 10 + c - '0';
|
||||
return r * n;
|
||||
c -= 0x30;
|
||||
if(c < 10) return c;
|
||||
c -= 0x31;
|
||||
if(c < 6) return 10 + c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -47,6 +47,21 @@ walk(char *s)
|
|||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
sint(char *s)
|
||||
{
|
||||
char c = *s, *cap = walk(s);
|
||||
int r = 0, n = 1;
|
||||
if(c == '#') {
|
||||
s++;
|
||||
while((c = *s) && s++ < cap) r = (r << 4) | chex(c);
|
||||
return r;
|
||||
}
|
||||
if(c == '-') { n = -1, s++; }
|
||||
while((c = *s) && s++ < cap) r = r * 10 + c - '0';
|
||||
return r * n;
|
||||
}
|
||||
|
||||
static void
|
||||
device_write(char *s)
|
||||
{
|
||||
|
@ -83,7 +98,9 @@ device_write(char *s)
|
|||
case 't': putc(0x09, stdout); break;
|
||||
case 'n': putc(0x0a, stdout); break;
|
||||
case 's': putc(0x20, stdout); break;
|
||||
default: putc(sint(--s), stdout), s = walk(s);
|
||||
}
|
||||
|
||||
} else
|
||||
putc(c, stdout);
|
||||
}
|
||||
|
@ -314,7 +331,7 @@ main(int argc, char **argv)
|
|||
return !printf("usage: modal [-vqn] source.modal\n");
|
||||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||
switch(argv[i][1]) {
|
||||
case 'v': /* version */ return !printf("Modal Interpreter, 10 May 2024.\n");
|
||||
case 'v': /* version */ return !printf("Modal Interpreter, 13 May 2024.\n");
|
||||
case 'q': /* quiet */ quiet = 1; break;
|
||||
case 'p': /* debug */ debug = 1; break;
|
||||
case 'a': /* access */ access = 1; break;
|
||||
|
|
Loading…
Reference in New Issue