commit 10bb933

Devine Lu Linvega  ·  2024-04-02 22:12:00 +0000 UTC
parent f4df46b
(uxnasm) Output to stdout
2 files changed,  +12, -6
+6, -0
1@@ -0,0 +1,6 @@
2+%square { DUP MUL ?{ } }
3+
4+|100
5+	#12 square
6+BRK
7+
+6, -6
 1@@ -50,8 +50,8 @@ static char *join(char *a, char j, char *b) { char *res = dictnext; save(a, j),
 2 #define writeshort(x) (writebyte(x >> 8, ctx) && writebyte(x & 0xff, ctx))
 3 #define findlabel(x) finditem(x, labels, labels_len)
 4 #define findmacro(x) finditem(x, macros, macro_len)
 5-#define error_top(name, msg) !fprintf(stderr, "%s: %s\n", name, msg)
 6-#define error_asm(name) !fprintf(stderr, "%s: %s in @%s, %s:%d.\n", name, token, scope, ctx->path, ctx->line)
 7+#define error_top(name, msg) !printf("%s: %s\n", name, msg)
 8+#define error_asm(name) !printf("%s: %s in @%s, %s:%d.\n", name, token, scope, ctx->path, ctx->line)
 9 
10 /* clang-format on */
11 
12@@ -308,7 +308,7 @@ parse(char *w, FILE *f, Context *ctx)
13 	case ',': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx);
14 	case '-': return makeref(w + 1, w[0], ptr) && writebyte(0xff, ctx);
15 	case '.': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx);
16-	case ':': fprintf(stderr, "Deprecated rune %s, use =%s\n", w, w + 1); /* fall-through */
17+	case ':': printf("Deprecated rune %s, use =%s\n", w, w + 1); /* fall-through */
18 	case '=': return makeref(w + 1, w[0], ptr) && writeshort(0xffff);
19 	case ';': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT2"), ctx) && writeshort(0xffff);
20 	case '?': return makeref(w + 1, w[0], ptr + 1) && writebyte(0x20, ctx) && writeshort(0xffff);
21@@ -374,9 +374,9 @@ build(char *rompath)
22 		return !error_top("Output file invalid", rompath);
23 	for(i = 0; i < labels_len; i++)
24 		if(labels[i].name[0] - 'A' > 25 && !labels[i].refs)
25-			fprintf(stdout, "-- Unused label: %s\n", labels[i].name);
26+			printf("-- Unused label: %s\n", labels[i].name);
27 	fwrite(data + PAGE, length - PAGE, 1, dst);
28-	fprintf(stdout,
29+	printf(
30 		"Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n",
31 		rompath,
32 		length - PAGE,
33@@ -403,7 +403,7 @@ main(int argc, char *argv[])
34 {
35 	ptr = PAGE;
36 	copy("on-reset", scope, 0);
37-	if(argc == 2 && scmp(argv[1], "-v", 2)) return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 2 Apr 2024.\n");
38+	if(argc == 2 && scmp(argv[1], "-v", 2)) return !printf("Uxnasm - Uxntal Assembler, 2 Apr 2024.\n");
39 	if(argc != 3) return error_top("usage", "uxnasm [-v] input.tal output.rom");
40 	if(!assemble(argv[1])) return 1;
41 	if(!resolve(argv[2])) return 1;