Allow underscores in gfx literals (#951)

Fixes #950
This commit is contained in:
Rangi
2021-11-21 16:18:23 -05:00
committed by GitHub
parent bdcef6f252
commit ec6d63bce3
4 changed files with 20 additions and 5 deletions

View File

@@ -1204,6 +1204,7 @@ static uint32_t readBinaryNumber(void)
int c = peek();
int bit;
// Check for '_' after digits in case one of the digits is '_'
if (c == binDigits[0])
bit = 0;
else if (c == binDigits[1])
@@ -1229,7 +1230,7 @@ static uint32_t readHexNumber(void)
for (;; shiftChar()) {
int c = peek();
if (c >= 'a' && c <= 'f') /* Convert letters to right after digits */
if (c >= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
@@ -1257,7 +1258,7 @@ char gfxDigits[4];
static uint32_t readGfxConstant(void)
{
uint32_t bp0 = 0, bp1 = 0;
uint32_t bitPlaneLower = 0, bitPlaneUpper = 0;
uint8_t width = 0;
dbgPrint("Reading gfx constant with digits [%c,%c,%c,%c]\n",
@@ -1266,6 +1267,7 @@ static uint32_t readGfxConstant(void)
int c = peek();
uint32_t pixel;
// Check for '_' after digits in case one of the digits is '_'
if (c == gfxDigits[0])
pixel = 0;
else if (c == gfxDigits[1])
@@ -1274,12 +1276,14 @@ static uint32_t readGfxConstant(void)
pixel = 2;
else if (c == gfxDigits[3])
pixel = 3;
else if (c == '_' && width > 0)
continue;
else
break;
if (width < 8) {
bp0 = bp0 << 1 | (pixel & 1);
bp1 = bp1 << 1 | (pixel >> 1);
bitPlaneLower = bitPlaneLower << 1 | (pixel & 1);
bitPlaneUpper = bitPlaneUpper << 1 | (pixel >> 1);
}
if (width < 9)
width++;
@@ -1291,7 +1295,7 @@ static uint32_t readGfxConstant(void)
warning(WARNING_LARGE_CONSTANT,
"Graphics constant is too long, only first 8 pixels considered\n");
return bp1 << 8 | bp0;
return bitPlaneUpper << 8 | bitPlaneLower;
}
/* Functions to read identifiers & keywords */

View File

@@ -219,6 +219,10 @@ There are a number of numeric formats.
.El
.Pp
Underscores are also accepted in numbers, except at the beginning of one.
This can be useful for grouping digits, like
.Ql 123_456
or
.Ql %1100_1001 .
.Pp
The "character constant" form yields the value the character maps to in the current charmap.
For example, by default

View File

@@ -10,6 +10,7 @@ _1234::
db &200 ; octal
db %11110000, %10 ; binary
dl 6.283185 ; fixed point
dw `01233210, `00332211 ; gfx
; with underscores
dw _1234 ; label
@@ -19,3 +20,9 @@ _1234::
db &2_0_0_ ; octal
db %1111_0000, %1_0 ; binary
dl 6_._283_185 ; fixed point
dw `0123_3210, `00_33_22_11_ ; gfx
; underscores as digits
opt g_ABC, b_X
db %_X_X__XX
dw `_A_B_C__