Browse code

(uxnasm) Generalized lambdas as common labels

neauoire authored on 03/08/2023 02:48:48
Showing 1 changed files
... ...
@@ -175,6 +175,15 @@ makelabel(char *name)
175 175
 	return 1;
176 176
 }
177 177
 
178
+static char *
179
+makelambda(int id)
180
+{
181
+	scpy("lambda", p.lambda, 0x07);
182
+	p.lambda[6] = '0' + (id >> 0x4);
183
+	p.lambda[7] = '0' + (id & 0xf);
184
+	return p.lambda;
185
+}
186
+
178 187
 static int
179 188
 makereference(char *scope, char *label, char rune, Uint16 addr)
180 189
 {
... ...
@@ -183,7 +192,10 @@ makereference(char *scope, char *label, char rune, Uint16 addr)
183 192
 	if(p.refs_len >= 0x800)
184 193
 		return error("References limit exceeded", label);
185 194
 	r = &p.refs[p.refs_len++];
186
-	if(label[0] == '&') {
195
+	if(label[0] == '{') {
196
+		p.lambda_stack[p.lambda_ptr++] = p.lambda_count;
197
+		scpy(makelambda(p.lambda_count++), r->name, 0x40);
198
+	} else if(label[0] == '&') {
187 199
 		if(!sublabel(subw, scope, label + 1))
188 200
 			return error("Invalid sublabel", label);
189 201
 		scpy(subw, r->name, 0x40);
... ...
@@ -201,15 +213,6 @@ makereference(char *scope, char *label, char rune, Uint16 addr)
201 213
 	return 1;
202 214
 }
203 215
 
204
-static char *
205
-makelambda(int id)
206
-{
207
-	scpy("lambda", p.lambda, 0x07);
208
-	p.lambda[6] = '0' + (id >> 0x4);
209
-	p.lambda[7] = '0' + (id & 0xf);
210
-	return p.lambda;
211
-}
212
-
213 216
 static int
214 217
 writebyte(Uint8 b)
215 218
 {
... ...
@@ -361,14 +364,10 @@ parse(char *w, FILE *f)
361 364
 		while((c = w[++i]))
362 365
 			if(!writebyte(c)) return 0;
363 366
 		break;
364
-	case '{': /* lambda start */
365
-		p.lambda_stack[p.lambda_ptr++] = p.lambda_count;
366
-		makereference(p.scope, makelambda(p.lambda_count++), ' ', p.ptr + 1);
367
-		return writebyte(0x60) && writeshort(0xffff, 0);
368 367
 	case '}': /* lambda end */
369 368
 		if(!makelabel(makelambda(p.lambda_stack[--p.lambda_ptr])))
370 369
 			return error("Invalid label", w);
371
-		return writebyte(0x6f);
370
+		break;
372 371
 	case '[':
373 372
 	case ']':
374 373
 		if(slen(w) == 1) break; /* else fallthrough */