From 10bb9334903aaaea543c65e3502a57d37c7f17ef Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 2 Apr 2024 15:12:00 -0700 Subject: [PATCH] (uxnasm) Output to stdout --- etc/hello.tal | 6 ++++++ src/uxnasm.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 etc/hello.tal diff --git a/etc/hello.tal b/etc/hello.tal new file mode 100644 index 0000000..260f119 --- /dev/null +++ b/etc/hello.tal @@ -0,0 +1,6 @@ +%square { DUP MUL ?{ } } + +|100 + #12 square +BRK + diff --git a/src/uxnasm.c b/src/uxnasm.c index 0efd08e..654778c 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -50,8 +50,8 @@ static char *join(char *a, char j, char *b) { char *res = dictnext; save(a, j), #define writeshort(x) (writebyte(x >> 8, ctx) && writebyte(x & 0xff, ctx)) #define findlabel(x) finditem(x, labels, labels_len) #define findmacro(x) finditem(x, macros, macro_len) -#define error_top(name, msg) !fprintf(stderr, "%s: %s\n", name, msg) -#define error_asm(name) !fprintf(stderr, "%s: %s in @%s, %s:%d.\n", name, token, scope, ctx->path, ctx->line) +#define error_top(name, msg) !printf("%s: %s\n", name, msg) +#define error_asm(name) !printf("%s: %s in @%s, %s:%d.\n", name, token, scope, ctx->path, ctx->line) /* clang-format on */ @@ -308,7 +308,7 @@ parse(char *w, FILE *f, Context *ctx) case ',': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx); case '-': return makeref(w + 1, w[0], ptr) && writebyte(0xff, ctx); case '.': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT"), ctx) && writebyte(0xff, ctx); - case ':': fprintf(stderr, "Deprecated rune %s, use =%s\n", w, w + 1); /* fall-through */ + case ':': printf("Deprecated rune %s, use =%s\n", w, w + 1); /* fall-through */ case '=': return makeref(w + 1, w[0], ptr) && writeshort(0xffff); case ';': return makeref(w + 1, w[0], ptr + 1) && writebyte(findopcode("LIT2"), ctx) && writeshort(0xffff); case '?': return makeref(w + 1, w[0], ptr + 1) && writebyte(0x20, ctx) && writeshort(0xffff); @@ -374,9 +374,9 @@ build(char *rompath) return !error_top("Output file invalid", rompath); for(i = 0; i < labels_len; i++) if(labels[i].name[0] - 'A' > 25 && !labels[i].refs) - fprintf(stdout, "-- Unused label: %s\n", labels[i].name); + printf("-- Unused label: %s\n", labels[i].name); fwrite(data + PAGE, length - PAGE, 1, dst); - fprintf(stdout, + printf( "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", rompath, length - PAGE, @@ -403,7 +403,7 @@ main(int argc, char *argv[]) { ptr = PAGE; copy("on-reset", scope, 0); - if(argc == 2 && scmp(argv[1], "-v", 2)) return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 2 Apr 2024.\n"); + if(argc == 2 && scmp(argv[1], "-v", 2)) return !printf("Uxnasm - Uxntal Assembler, 2 Apr 2024.\n"); if(argc != 3) return error_top("usage", "uxnasm [-v] input.tal output.rom"); if(!assemble(argv[1])) return 1; if(!resolve(argv[2])) return 1;