From b9a79eca1905a53d25931e795f9d06c42719aa4c Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 24 Feb 2024 08:46:18 -0800 Subject: [PATCH] (uxnasm)Passing uxntal scope requirements --- etc/coverage.tal | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ src/uxnasm.c | 9 +++--- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 etc/coverage.tal diff --git a/etc/coverage.tal b/etc/coverage.tal new file mode 100644 index 0000000..a75fdf1 --- /dev/null +++ b/etc/coverage.tal @@ -0,0 +1,77 @@ +( test file ) + +|0100 @program + + #01 ?{ ( skip ) #ffff } + !{ ( skip ) #ffff } + { ( skip ) #ffff } POP2r + + ( nested lambda ) + { { "hello 0a $1 } STH2r !print-str } STH2r JSR2 + + ( function application ) + { 01 02 03 04 05 } STH2r { LIT "0 ADD #18 DEO #0a18 DEO JMP2r } STH2r foreach + + ( get lambda length ) + { "Dindeldums $1 } STH2r get-lambda-length #0a18 DEO + + ( allocated string ) + ;hello-word print-str + + #800f DEO + +BRK + +( +@| test label inheritance ) + +@object + +&x $1 &y $1 + +&get-x ( -- x ) + ,&x LDR + JMP2r + +@object/get-y ( -- y ) + ,&y LDR + JMP2r + +( raw lambda length ) +_{ 01 02 03 } + +@get-lambda-length ( lambda* -- length* ) + #0002 SUB2 LDA2 +JMP2r + +@print-str ( str* -- ) + &while ( -- ) + ( send ) LDAk #18 DEO + ( loop ) INC2 LDAk ?&while + POP2 + +JMP2r + +@foreach ( arr* fn* -- ) + STH2 + DUP2 + DUP2 #0002 SUB2 LDA2 ADD2 + SWP2 + &l + LDAk STH2kr JSR2 + INC2 NEQ2k ?&l + POP2 POP2 POP2r +JMP2r + +@ ( short* -- ) + #2710 [ LIT2r 00fb ] + &w ( -- ) + DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip + DUP [ LIT "0 ] ADD #19 DEO + INCr &>skip + POP2 #000a DIV2 SWPr INCr STHkr ?&w + POP2r POP2 POP2 JMP2r + +$20 @label2 + +@hello-word "Hello 20 "World! 0a $1 diff --git a/src/uxnasm.c b/src/uxnasm.c index f80d63b..2f7b8f7 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -320,7 +320,10 @@ parse(char *w, FILE *f) case '@': /* label */ if(!makelabel(w + 1)) return error("Invalid label", w); - scpy(w + 1, p.scope, 0x40); + i = 0; + while(w[i + 1] != '/' && i < 0x3e && (p.scope[i] = w[i + 1])) + i++; + p.scope[i] = '\0'; break; case '&': /* sublabel */ if(!sublabel(subw, p.scope, w + 1) || !makelabel(subw)) @@ -346,7 +349,6 @@ parse(char *w, FILE *f) case '.': /* literal byte zero-page */ makereference(p.scope, w + 1, w[0], p.ptr + 1); return writelitbyte(0xff); - case ':': case '=': /* raw short absolute */ makereference(p.scope, w + 1, w[0], p.ptr); return writeshort(0xffff, 0); @@ -420,7 +422,6 @@ resolve(void) p.data[r->addr] = l->addr & 0xff; l->refs++; break; - case ':': case '=': case ';': if(!(l = findlabel(r->name))) @@ -501,7 +502,7 @@ main(int argc, char *argv[]) if(argc == 1) return error("usage", "uxnasm [-v] input.tal output.rom"); if(argv[1][0] == '-' && argv[1][1] == 'v') - return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 27 Oct 2023.\n"); + return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 24 Feb 2024.\n"); if(!(src = fopen(argv[1], "r"))) return !error("Invalid input", argv[1]); if(!assemble(src))