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
|
run: all bin/modal
|
||||||
@ bin/modal -q examples/hello.modal
|
@ bin/modal -q examples/hello.modal
|
||||||
debug: all bin/modal-debug
|
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
|
test: all bin/modal-debug bin/modal
|
||||||
@ bin/modal -v
|
@ bin/modal -v
|
||||||
@ bin/modal-debug -q examples/fizzbuzz.modal
|
@ 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;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
sint(char *s)
|
chex(char c)
|
||||||
{
|
{
|
||||||
char c;
|
c -= 0x30;
|
||||||
int r = 0, n = 1;
|
if(c < 10) return c;
|
||||||
if(*s == '-') { n = -1, s++; }
|
c -= 0x31;
|
||||||
while((c = *s++) && !spacer(c)) r = r * 10 + c - '0';
|
if(c < 6) return 10 + c;
|
||||||
return r * n;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -47,6 +47,21 @@ walk(char *s)
|
||||||
return 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
|
static void
|
||||||
device_write(char *s)
|
device_write(char *s)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +98,9 @@ device_write(char *s)
|
||||||
case 't': putc(0x09, stdout); break;
|
case 't': putc(0x09, stdout); break;
|
||||||
case 'n': putc(0x0a, stdout); break;
|
case 'n': putc(0x0a, stdout); break;
|
||||||
case 's': putc(0x20, stdout); break;
|
case 's': putc(0x20, stdout); break;
|
||||||
|
default: putc(sint(--s), stdout), s = walk(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
putc(c, stdout);
|
putc(c, stdout);
|
||||||
}
|
}
|
||||||
|
@ -314,7 +331,7 @@ main(int argc, char **argv)
|
||||||
return !printf("usage: modal [-vqn] source.modal\n");
|
return !printf("usage: modal [-vqn] source.modal\n");
|
||||||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||||
switch(argv[i][1]) {
|
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 'q': /* quiet */ quiet = 1; break;
|
||||||
case 'p': /* debug */ debug = 1; break;
|
case 'p': /* debug */ debug = 1; break;
|
||||||
case 'a': /* access */ access = 1; break;
|
case 'a': /* access */ access = 1; break;
|
||||||
|
|
Loading…
Reference in New Issue