Compare commits

...

3 Commits

Author SHA1 Message Date
Lobo Torres f6cda36187 (uxnasm) Explicit error for empty rom 2024-03-29 11:36:57 -07:00
Devine Lu Linvega e47a14f673 (uxnasm) Catch missized #hex 2024-03-29 10:43:22 -07:00
Devine Lu Linvega 68d6a5f604 (uxnasm) More explicit resolve errors 2024-03-29 10:26:25 -07:00
1 changed files with 10 additions and 9 deletions

View File

@ -97,7 +97,7 @@ findopcode(char *s)
else if(s[m] == 'k')
i |= (1 << 7);
else
return 0;
return error_top("Unknown opcode mode", s);
m++;
}
return i;
@ -177,7 +177,7 @@ makemacro(char *name, FILE *f, Context *ctx)
if(c == 0xa) ctx->line += 1;
while(f && fread(&c, 1, 1, f) && c != '}') {
if(c == 0xa) ctx->line += 1;
if(c == '%') return 0;
if(c == '%') return error_top("Nested macro", name);
if(c == '(')
walkcomment(f, ctx);
else
@ -258,9 +258,9 @@ writehex(char *w, Context *ctx)
{
if(*w == '#')
writebyte(findopcode("LIT") | !!(++w)[2] << 5, ctx);
if(!w[2])
if(w[1] && !w[2])
return writebyte(shex(w), ctx);
else if(!w[4])
else if(w[3] && !w[4])
return writeshort(shex(w));
else
return 0;
@ -331,7 +331,7 @@ resolve(void)
for(i = 0; i < refs_len; i++) {
Item *r = &refs[i], *l = findlabel(r->name);
Uint8 *rom = data + r->addr;
if(!l) return 0;
if(!l) return error_top("Unknown label", r->name);
switch(r->rune) {
case '_':
case ',':
@ -400,10 +400,11 @@ main(int argc, char *argv[])
{
ptr = PAGE;
copy("on-reset", scope, 0);
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, 28 Mar 2024.\n");
if(!assemble(argv[1]) || !length) return !error_top("Assembly", "Failed to assemble rom.");
if(argc == 2 && scmp(argv[1], "-v", 2)) return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 29 Mar 2024.\n");
if(argc != 3) return error_top("usage", "uxnasm [-v] input.tal output.rom");
if(!assemble(argv[1])) return !error_top("Assembly", "Failed to assemble rom.");
if(!length) return !error_top("Assembly", "Output rom is empty.");
if(!resolve()) return !error_top("Assembly", "Failed to resolve symbols.");
if(!build(argv[2])) return !error_top("Assembly", "Failed to build rom.");
return 0;
}
}