(uxnasm) Abstracted write string
This commit is contained in:
parent
966aab7bb8
commit
aedc593434
|
@ -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
|
|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
|
|0100 @program
|
||||||
|
|
||||||
|
|
20
src/uxnasm.c
20
src/uxnasm.c
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue