(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

@ -2,7 +2,7 @@
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
%emit ( byte -- ) { #18 DEO }
%emit ( byte -- ) { #18 DEO }
|0100 @program

View File

@ -288,9 +288,17 @@ makeinclude(char *filename)
}
static int
parse(char *w, FILE *f, Context *ctx)
writestring(char *w, Context *ctx)
{
char c;
while((c = *(w++)))
if(!writebyte(c, ctx)) return 0;
return 1;
}
static int
parse(char *w, FILE *f, Context *ctx)
{
Item *m;
switch(w[0]) {
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 !makelabel(w + 1, 1, ctx) ? error_asm("Invalid label") : 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 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);
@ -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(0x20, 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 '|': return !makepad(w) ? error_asm("Invalid padding") : 1;
case '[':
case ']':
if(slen(w) == 1) break; /* else fallthrough */
case '"': /* raw string */
while((c = *(++w)))
if(!writebyte(c, ctx)) return 0;
break;
case ']': break;
default:
if(sihx(w))
return writehex(w, ctx);