(uxnasm) Abstracted write string

This commit is contained in:
Devine Lu Linvega 2024-03-27 15:55:16 -07:00
parent 966aab7bb8
commit aedc593434
2 changed files with 13 additions and 9 deletions

View File

@ -288,9 +288,17 @@ makeinclude(char *filename)
} }
static int static int
parse(char *w, FILE *f, Context *ctx) writestring(char *w, Context *ctx)
{ {
char c; char c;
while((c = *(w++)))
if(!writebyte(c, ctx)) return 0;
return 1;
}
static int
parse(char *w, FILE *f, Context *ctx)
{
Item *m; Item *m;
switch(w[0]) { switch(w[0]) {
case '(': return !walkcomment(f, ctx) ? error_asm("Invalid comment") : 1; case '(': return !walkcomment(f, ctx) ? error_asm("Invalid comment") : 1;
@ -298,6 +306,7 @@ parse(char *w, FILE *f, Context *ctx)
case '%': return !makemacro(w + 1, f, ctx) ? error_asm("Invalid macro") : 1; case '%': return !makemacro(w + 1, f, ctx) ? error_asm("Invalid macro") : 1;
case '@': return !makelabel(w + 1, 1, ctx) ? error_asm("Invalid label") : 1; case '@': return !makelabel(w + 1, 1, ctx) ? error_asm("Invalid label") : 1;
case '&': return !makelabel(w, 0, ctx) ? error_asm("Invalid sublabel") : 1; case '&': return !makelabel(w, 0, ctx) ? error_asm("Invalid sublabel") : 1;
case '}': return !makelabel(makelambda(lambda_stack[--lambda_ptr]), 0, ctx) ? error_asm("Invalid label") : 1;
case '#': return !sihx(w + 1) || !writehex(w, ctx) ? error_asm("Invalid hexadecimal") : 1; case '#': return !sihx(w + 1) || !writehex(w, ctx) ? error_asm("Invalid hexadecimal") : 1;
case '_': return addref(w + 1, w[0], ptr) && writebyte(0xff, ctx); case '_': return addref(w + 1, w[0], ptr) && writebyte(0xff, ctx);
case ',': return addref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx); case ',': return addref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx);
@ -308,16 +317,11 @@ parse(char *w, FILE *f, Context *ctx)
case ';': return addref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT2"), ctx) && writeshort(0xffff); case ';': return addref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT2"), ctx) && writeshort(0xffff);
case '?': return addref(w + 1, w[0], ptr + 1) && writebyte(0x20, ctx) && writeshort(0xffff); case '?': return addref(w + 1, w[0], ptr + 1) && writebyte(0x20, ctx) && writeshort(0xffff);
case '!': return addref(w + 1, w[0], ptr + 1) && writebyte(0x40, ctx) && writeshort(0xffff); case '!': return addref(w + 1, w[0], ptr + 1) && writebyte(0x40, ctx) && writeshort(0xffff);
case '}': return !makelabel(makelambda(lambda_stack[--lambda_ptr]), 0, ctx) ? error_asm("Invalid label") : 1; case '"': return !writestring(w + 1, ctx) ? error_asm("Invalid string") : 1;
case '$': case '$':
case '|': return !makepad(w) ? error_asm("Invalid padding") : 1; case '|': return !makepad(w) ? error_asm("Invalid padding") : 1;
case '[': case '[':
case ']': case ']': break;
if(slen(w) == 1) break; /* else fallthrough */
case '"': /* raw string */
while((c = *(++w)))
if(!writebyte(c, ctx)) return 0;
break;
default: default:
if(sihx(w)) if(sihx(w))
return writehex(w, ctx); return writehex(w, ctx);