(uxnasm) Merged token types

This commit is contained in:
Devine Lu Linvega 2024-03-27 10:39:34 -07:00
parent 1df9b12efd
commit a56a4e0be0
1 changed files with 12 additions and 12 deletions

View File

@ -21,14 +21,14 @@ typedef unsigned short Uint16;
typedef struct { typedef struct {
char *name, rune, *content; char *name, rune, *content;
Uint16 addr, refs; Uint16 addr, refs;
} Label; } Item;
typedef struct { typedef struct {
int ptr, length; int ptr, length;
Uint8 data[LENGTH]; Uint8 data[LENGTH];
Uint8 lambda_stack[0x100], lambda_ptr, lambda_len; Uint8 lambda_stack[0x100], lambda_ptr, lambda_len;
Uint16 line, label_len, macro_len, refs_len; Uint16 line, label_len, macro_len, refs_len;
Label labels[0x400], refs[0x1000], macros[0x100]; Item labels[0x400], refs[0x1000], macros[0x100];
} Program; } Program;
static char source[0x40], token[0x40], scope[0x40], sublabel[0x80], lambda[0x05]; static char source[0x40], token[0x40], scope[0x40], sublabel[0x80], lambda[0x05];
@ -66,7 +66,7 @@ static char *push(char *s, char c) { char *ptr = storenext; while((*storenext++
static int parse(char *w, FILE *f); static int parse(char *w, FILE *f);
static Label * static Item *
findmacro(char *name) findmacro(char *name)
{ {
int i; int i;
@ -76,7 +76,7 @@ findmacro(char *name)
return NULL; return NULL;
} }
static Label * static Item *
findlabel(char *name) findlabel(char *name)
{ {
int i; int i;
@ -132,7 +132,7 @@ walkcomment(char *w, FILE *f)
static int static int
makemacro(char *name, FILE *f) makemacro(char *name, FILE *f)
{ {
Label *m; Item *m;
char word[0x40]; char word[0x40];
if(!slen(name)) return error_asm("Macro is empty"); if(!slen(name)) return error_asm("Macro is empty");
if(findmacro(name)) return error_asm("Macro is duplicate"); if(findmacro(name)) return error_asm("Macro is duplicate");
@ -159,7 +159,7 @@ makemacro(char *name, FILE *f)
static int static int
makelabel(char *name, int setscope) makelabel(char *name, int setscope)
{ {
Label *l; Item *l;
if(name[0] == '&') if(name[0] == '&')
name = makesublabel(name + 1); name = makesublabel(name + 1);
if(!slen(name)) return error_asm("Label is empty"); if(!slen(name)) return error_asm("Label is empty");
@ -193,7 +193,7 @@ makelambda(int id)
static int static int
makepad(char *w) makepad(char *w)
{ {
Label *l; Item *l;
int rel = w[0] == '$' ? p.ptr : 0; int rel = w[0] == '$' ? p.ptr : 0;
if(sihx(w + 1)) if(sihx(w + 1))
p.ptr = shex(w + 1) + rel; p.ptr = shex(w + 1) + rel;
@ -207,7 +207,7 @@ makepad(char *w)
static int static int
addref(char *label, char rune, Uint16 addr) addref(char *label, char rune, Uint16 addr)
{ {
Label *r; Item *r;
if(p.refs_len >= 0x1000) if(p.refs_len >= 0x1000)
return error_asm("References limit exceeded"); return error_asm("References limit exceeded");
r = &p.refs[p.refs_len++]; r = &p.refs[p.refs_len++];
@ -251,7 +251,7 @@ writehex(char *w)
} }
static int static int
walkmacro(Label *m) walkmacro(Item *m)
{ {
char c, *contentptr = m->content, *cptr = token; char c, *contentptr = m->content, *cptr = token;
while((c = *contentptr++)) { while((c = *contentptr++)) {
@ -303,7 +303,7 @@ static int
parse(char *w, FILE *f) parse(char *w, FILE *f)
{ {
char c; char c;
Label *m; Item *m;
switch(w[0]) { switch(w[0]) {
case '(': return !walkcomment(w, f) ? error_asm("Invalid comment") : 1; case '(': return !walkcomment(w, f) ? error_asm("Invalid comment") : 1;
case '~': return !makeinclude(w + 1) ? error_asm("Invalid include") : 1; case '~': return !makeinclude(w + 1) ? error_asm("Invalid include") : 1;
@ -346,11 +346,11 @@ parse(char *w, FILE *f)
static int static int
resolve(void) resolve(void)
{ {
Label *l; Item *l;
int i; int i;
Uint16 a; Uint16 a;
for(i = 0; i < p.refs_len; i++) { for(i = 0; i < p.refs_len; i++) {
Label *r = &p.refs[i]; Item *r = &p.refs[i];
Uint8 *rom = p.data + r->addr; Uint8 *rom = p.data + r->addr;
switch(r->rune) { switch(r->rune) {
case '_': case '_':