(uxnasm) Reference store strings in dict
This commit is contained in:
parent
c9f2eb0aad
commit
0414a98b0e
27
src/uxnasm.c
27
src/uxnasm.c
|
@ -29,7 +29,7 @@ typedef struct {
|
||||||
} Label;
|
} Label;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[0x40], rune;
|
char *name, rune;
|
||||||
Uint16 addr;
|
Uint16 addr;
|
||||||
} Reference;
|
} Reference;
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ typedef struct {
|
||||||
Reference refs[0x1000];
|
Reference refs[0x1000];
|
||||||
} Program;
|
} Program;
|
||||||
|
|
||||||
char source[0x40], token[0x40], scope[0x40], sublabel[0x40], lambda[0x05];
|
static char source[0x40], token[0x40], scope[0x40], sublabel[0x80], lambda[0x05];
|
||||||
char dict[0x10000], *storenext = dict;
|
static char dict[0x10000], *storenext = dict;
|
||||||
|
|
||||||
Program p;
|
Program p;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ static char *push(char *s) { char *ptr = storenext; while((*storenext++ = *s++))
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
static int parse(char *w, FILE *f);
|
static int parse(char *w, FILE *f);
|
||||||
static char *makesublabel(char *src, char *name);
|
static char *makesublabel(char *name);
|
||||||
|
|
||||||
static Macro *
|
static Macro *
|
||||||
findmacro(char *name)
|
findmacro(char *name)
|
||||||
|
@ -93,7 +93,7 @@ findlabel(char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if(name[0] == '&')
|
if(name[0] == '&')
|
||||||
name = makesublabel(sublabel, name + 1);
|
name = makesublabel(name + 1);
|
||||||
for(i = 0; i < p.label_len; i++)
|
for(i = 0; i < p.label_len; i++)
|
||||||
if(scmp(p.labels[i].name, name, 0x40))
|
if(scmp(p.labels[i].name, name, 0x40))
|
||||||
return &p.labels[i];
|
return &p.labels[i];
|
||||||
|
@ -172,7 +172,7 @@ makelabel(char *name, int setscope)
|
||||||
{
|
{
|
||||||
Label *l;
|
Label *l;
|
||||||
if(name[0] == '&')
|
if(name[0] == '&')
|
||||||
name = makesublabel(sublabel, name + 1);
|
name = makesublabel(name + 1);
|
||||||
if(!slen(name)) return error_asm("Label is empty");
|
if(!slen(name)) return error_asm("Label is empty");
|
||||||
if(findlabel(name)) return error_asm("Label is duplicate");
|
if(findlabel(name)) return error_asm("Label is duplicate");
|
||||||
if(sihx(name)) return error_asm("Label is hex number");
|
if(sihx(name)) return error_asm("Label is hex number");
|
||||||
|
@ -202,13 +202,9 @@ makelambda(int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
makesublabel(char *buf, char *name)
|
makesublabel(char *name)
|
||||||
{
|
{
|
||||||
if(slen(scope) + slen(name) >= 0x3f) {
|
return push(scat(scat(scpy(scope, sublabel, 0x40), "/"), name));
|
||||||
(void)error_asm("Sublabel length too long");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return scat(scat(scpy(scope, buf, 0x40), "/"), name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -234,12 +230,11 @@ addref(char *label, char rune, Uint16 addr)
|
||||||
r = &p.refs[p.refs_len++];
|
r = &p.refs[p.refs_len++];
|
||||||
if(label[0] == '{') {
|
if(label[0] == '{') {
|
||||||
p.lambda_stack[p.lambda_ptr++] = p.lambda_len;
|
p.lambda_stack[p.lambda_ptr++] = p.lambda_len;
|
||||||
scpy(makelambda(p.lambda_len++), r->name, 0x40);
|
r->name = push(makelambda(p.lambda_len++));
|
||||||
} else if(label[0] == '&' || label[0] == '/') {
|
} else if(label[0] == '&' || label[0] == '/') {
|
||||||
if(!makesublabel(r->name, label + 1))
|
r->name = makesublabel(label + 1);
|
||||||
return error_asm("Invalid sublabel");
|
|
||||||
} else
|
} else
|
||||||
scpy(label, r->name, 0x40);
|
r->name = push(label);
|
||||||
r->rune = rune;
|
r->rune = rune;
|
||||||
r->addr = addr;
|
r->addr = addr;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue