(uxnasm) Report file name in error correctly

This commit is contained in:
Devine Lu Linvega 2024-03-27 13:55:48 -07:00
parent 0f64cb61e9
commit 966aab7bb8
2 changed files with 15 additions and 9 deletions

View File

@ -1,5 +1,7 @@
( init ) ( init )
|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

View File

@ -23,12 +23,12 @@ typedef struct {
} Item; } Item;
typedef struct { typedef struct {
char *path;
int line; int line;
char *path;
} Context; } Context;
static int ptr, length; static int ptr, length;
static char source[0x40], token[0x40], scope[0x40], sublabel[0x80], lambda[0x05]; static char token[0x40], scope[0x40], sublabel[0x80], lambda[0x05];
static char dict[0x10000], *dictnext = dict; static char dict[0x10000], *dictnext = dict;
static Uint8 data[0x10000], lambda_stack[0x100], lambda_ptr, lambda_len; static Uint8 data[0x10000], lambda_stack[0x100], lambda_ptr, lambda_len;
static Uint16 label_len, refs_len, macro_len; static Uint16 label_len, refs_len, macro_len;
@ -60,7 +60,7 @@ static char *push(char *s, char c) { char *o = dictnext; while((*dictnext++ = *s
#define findlabel(x) finditem(x, labels, label_len) #define findlabel(x) finditem(x, labels, label_len)
#define findmacro(x) finditem(x, macros, macro_len) #define findmacro(x) finditem(x, macros, macro_len)
#define error_top(name, msg) !fprintf(stderr, "%s: %s\n", name, msg) #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, source, ctx->line) #define error_asm(name) !fprintf(stderr, "%s: %s in @%s, %s:%d.\n", name, token, scope, ctx->path, ctx->line)
/* clang-format on */ /* clang-format on */
@ -215,10 +215,14 @@ makepad(char *w)
{ {
Item *l; Item *l;
int rel = w[0] == '$' ? ptr : 0; int rel = w[0] == '$' ? ptr : 0;
if(sihx(w + 1)) if(sihx(w + 1)) {
return ptr = shex(w + 1) + rel; ptr = shex(w + 1) + rel;
if((l = findlabel(w + 1))) return 1;
return ptr = l->addr + rel; }
if((l = findlabel(w + 1))) {
ptr = l->addr + rel;
return 1;
}
return 0; return 0;
} }
@ -275,9 +279,9 @@ makeinclude(char *filename)
int res = 0; int res = 0;
Context ctx; Context ctx;
ctx.line = 0; ctx.line = 0;
ctx.path = push(filename, 0);
if(!(f = fopen(filename, "r"))) if(!(f = fopen(filename, "r")))
return error_top("Invalid source", filename); return error_top("Invalid source", filename);
scpy(filename, source, 0x40);
res = walkfile(f, &ctx); res = walkfile(f, &ctx);
fclose(f); fclose(f);
return res; return res;
@ -418,7 +422,7 @@ main(int argc, char *argv[])
ptr = PAGE; ptr = PAGE;
scpy("on-reset", scope, 0x40); scpy("on-reset", scope, 0x40);
if(argc == 1) return error_top("usage", "uxnasm [-v] input.tal output.rom"); if(argc == 1) return error_top("usage", "uxnasm [-v] input.tal output.rom");
if(scmp(argv[1], "-v", 2)) return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 26 Mar 2024.\n"); if(scmp(argv[1], "-v", 2)) return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 27 Mar 2024.\n");
if(!makeinclude(argv[1]) || !resolve()) return !error_top("Assembly", "Failed to assemble rom."); if(!makeinclude(argv[1]) || !resolve()) return !error_top("Assembly", "Failed to assemble rom.");
if(!(dst = fopen(argv[2], "wb"))) return !error_top("Invalid Output", argv[2]); if(!(dst = fopen(argv[2], "wb"))) return !error_top("Invalid Output", argv[2]);
if(length <= PAGE) return !error_top("Assembly", "Output rom is empty."); if(length <= PAGE) return !error_top("Assembly", "Output rom is empty.");