Adding more posix, hex $.

This commit is contained in:
Brad Nelson
2021-01-03 00:44:15 -08:00
parent cb6566caf1
commit 83541a7dce
2 changed files with 11 additions and 1 deletions

View File

@ -13,7 +13,9 @@ static struct {
static cell_t convert(const char *pos, cell_t n, cell_t *ret) {
*ret = 0;
cell_t negate = 0;
cell_t base = g_sys.base;
if (!n) { return 0; }
if (pos[0] == '$') { base = 16; ++pos; --n; }
if (pos[0] == '-') { negate = -1; ++pos; --n; }
for (; n; --n) {
uintptr_t d = pos[0] - '0';
@ -22,7 +24,7 @@ static cell_t convert(const char *pos, cell_t n, cell_t *ret) {
if (d < 10) { return 0; }
}
if (d >= (uintptr_t) g_sys.base) { return 0; }
*ret = *ret * g_sys.base + d;
*ret = *ret * base + d;
++pos;
}
if (negate) { *ret = -*ret; }

View File

@ -38,6 +38,14 @@ z" __errno_location" 0 sysfunc __errno_location
1 constant SEEK_CUR
2 constant SEEK_END
( mmap )
0 constant PROT_NONE
1 constant PROT_READ
2 constant PROT_WRITE
4 constant PROT_EXEC
$10 constant MAP_FIXED
$20 constant MAP_ANONYMOUS
( Terminal handling )
: n. ( n -- ) base @ swap decimal <# #s #> type base ! ;
: esc 27 emit ;