... | ... |
@@ -175,15 +175,6 @@ 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 |
- |
|
187 | 178 |
static int |
188 | 179 |
makereference(char *scope, char *label, char rune, Uint16 addr) |
189 | 180 |
{ |
... | ... |
@@ -192,10 +183,7 @@ makereference(char *scope, char *label, char rune, Uint16 addr) |
192 | 183 |
if(p.refs_len >= 0x800) |
193 | 184 |
return error("References limit exceeded", label); |
194 | 185 |
r = &p.refs[p.refs_len++]; |
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] == '&') { |
|
186 |
+ if(label[0] == '&') { |
|
199 | 187 |
if(!sublabel(subw, scope, label + 1)) |
200 | 188 |
return error("Invalid sublabel", label); |
201 | 189 |
scpy(subw, r->name, 0x40); |
... | ... |
@@ -213,6 +201,15 @@ makereference(char *scope, char *label, char rune, Uint16 addr) |
213 | 201 |
return 1; |
214 | 202 |
} |
215 | 203 |
|
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 |
+ |
|
216 | 213 |
static int |
217 | 214 |
writebyte(Uint8 b) |
218 | 215 |
{ |
... | ... |
@@ -364,10 +361,14 @@ parse(char *w, FILE *f) |
364 | 361 |
while((c = w[++i])) |
365 | 362 |
if(!writebyte(c)) return 0; |
366 | 363 |
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); |
|
367 | 368 |
case '}': /* lambda end */ |
368 | 369 |
if(!makelabel(makelambda(p.lambda_stack[--p.lambda_ptr]))) |
369 | 370 |
return error("Invalid label", w); |
370 |
- break; |
|
371 |
+ return writebyte(0x6f); |
|
371 | 372 |
case '[': |
372 | 373 |
case ']': |
373 | 374 |
if(slen(w) == 1) break; /* else fallthrough */ |
... | ... |
@@ -497,9 +498,12 @@ writesym(char *filename) |
497 | 498 |
int |
498 | 499 |
main(int argc, char *argv[]) |
499 | 500 |
{ |
501 |
+ int i = 1; |
|
500 | 502 |
FILE *src, *dst; |
501 |
- if(argc < 3) |
|
502 |
- return !error("usage", "uxnasm input.tal output.rom"); |
|
503 |
+ if(i == argc) |
|
504 |
+ return error("usage", "uxnasm [-v] input.tal output.rom"); |
|
505 |
+ if(argv[i][0] == '-' && argv[i][1] == 'v') |
|
506 |
+ return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 8 Aug 2023\n"); |
|
503 | 507 |
if(!(src = fopen(argv[1], "r"))) |
504 | 508 |
return !error("Invalid input", argv[1]); |
505 | 509 |
if(!assemble(src)) |