commit aedc593434d9a06131fe53c7f89fcf4db9b72291
parent 966aab7bb826ae78df16a95ab7184fbaddba7b7d
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Wed, 27 Mar 2024 15:55:16 -0700
(uxnasm) Abstracted write string
Diffstat:
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/etc/hello.tal b/etc/hello.tal
@@ -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
diff --git a/src/uxnasm.c b/src/uxnasm.c
@@ -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);