uxn

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

commit 2ddc20b1b6acc05a1ce8ab468e407d138ccee581
parent 9ca8e9623d0ab1c299f08d3dd9d54098557f5749
Author: neauoire <aliceffekt@gmail.com>
Date:   Wed,  2 Aug 2023 19:48:48 -0700

(uxnasm) Generalized lambdas as common labels

Diffstat:
Msrc/uxnasm.c | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -175,6 +175,15 @@ makelabel(char *name) return 1; } +static char * +makelambda(int id) +{ + scpy("lambda", p.lambda, 0x07); + p.lambda[6] = '0' + (id >> 0x4); + p.lambda[7] = '0' + (id & 0xf); + return p.lambda; +} + static int makereference(char *scope, char *label, char rune, Uint16 addr) { @@ -183,7 +192,10 @@ makereference(char *scope, char *label, char rune, Uint16 addr) if(p.refs_len >= 0x800) return error("References limit exceeded", label); r = &p.refs[p.refs_len++]; - if(label[0] == '&') { + if(label[0] == '{') { + p.lambda_stack[p.lambda_ptr++] = p.lambda_count; + scpy(makelambda(p.lambda_count++), r->name, 0x40); + } else if(label[0] == '&') { if(!sublabel(subw, scope, label + 1)) return error("Invalid sublabel", label); scpy(subw, r->name, 0x40); @@ -201,15 +213,6 @@ makereference(char *scope, char *label, char rune, Uint16 addr) return 1; } -static char * -makelambda(int id) -{ - scpy("lambda", p.lambda, 0x07); - p.lambda[6] = '0' + (id >> 0x4); - p.lambda[7] = '0' + (id & 0xf); - return p.lambda; -} - static int writebyte(Uint8 b) { @@ -361,14 +364,10 @@ parse(char *w, FILE *f) while((c = w[++i])) if(!writebyte(c)) return 0; break; - case '{': /* lambda start */ - p.lambda_stack[p.lambda_ptr++] = p.lambda_count; - makereference(p.scope, makelambda(p.lambda_count++), ' ', p.ptr + 1); - return writebyte(0x60) && writeshort(0xffff, 0); case '}': /* lambda end */ if(!makelabel(makelambda(p.lambda_stack[--p.lambda_ptr]))) return error("Invalid label", w); - return writebyte(0x6f); + break; case '[': case ']': if(slen(w) == 1) break; /* else fallthrough */