uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 4406c2856c9d99eebc83263c53c74ecfd6fe11d5
parent 9835ec4f205c9b063b51b4514564cba8c8d5e35f
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 16 Sep 2021 09:11:53 -0700

Sublabels add refs to root labels in uxnasm

Diffstat:
Mprojects/examples/demos/piano.tal | 1-
Msrc/uxnasm.c | 21+++++++++++++++++----
2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal @@ -33,7 +33,6 @@ @last-note $1 @octave $1 -@color $1 @pointer [ &x $2 &y $2 ] @center [ &x $2 &y $2 ] @adsr-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -46,6 +46,7 @@ static char ops[][4] = { "ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT" }; +static int cpos(char *s, char a){ int i = 0; char c; while((c = s[i++])) if(c == a) return i; return -1; } static int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if(!a[i] || ++i >= len) return 1; return 0; } /* string compare */ static int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */ static int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */ @@ -184,6 +185,18 @@ makelabel(char *name) } static int +addref(Label *l) +{ + int pos = cpos(l->name, '/'); + if(pos != -1) { + char root[64]; + Label *rl = findlabel(scpy(l->name, root, pos)); + ++rl->refs; + } + return ++l->refs; +} + +static int skipblock(char *w, int *cap, char a, char b) { if(w[0] == b) { @@ -231,19 +244,19 @@ parsetoken(char *w) if(l->addr > 0xff) return error("Address is not in zero page", w); pushbyte(l->addr, 1); - return ++l->refs; + return addref(l); } else if(w[0] == ',' && (l = findlabel(w + 1))) { /* relative */ int off = l->addr - p.ptr - 3; if(off < -126 || off > 126) return error("Address is too far", w); pushbyte((Sint8)off, 1); - return ++l->refs; + return addref(l); } else if(w[0] == ':' && (l = findlabel(w + 1))) { /* raw */ pushshort(l->addr, 0); - return ++l->refs; + return addref(l); } else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */ pushshort(l->addr, 1); - return ++l->refs; + return addref(l); } else if(findopcode(w) || scmp(w, "BRK", 4)) { /* opcode */ pushbyte(findopcode(w), 0); return 1;