uxn

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

commit a197c24b2a55e16aa5cbe089468d2885b150cc72
parent bcdd08bc4e7c604f5110546a4f4a849e4f0a6a87
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Tue, 26 Mar 2024 13:35:37 -0700

Abstracted walk-comment

Diffstat:
Metc/hello.tal | 6++++--
Msrc/uxnasm.c | 33++++++++++++++++++++-------------
2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/etc/hello.tal b/etc/hello.tal @@ -1,5 +1,7 @@ ( init ) +%emit { #18 DEO } + |0100 @program #1234 SWP @@ -11,8 +13,8 @@ ;hello-word &while - ( send ) LDAk #18 DEO - ( loop ) INC2 LDAk ,&while JCN + ( send ) LDAk emit + ( loop ) INC2 LDAk ?&while POP2 #010f DEO diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -313,24 +313,31 @@ doinclude(char *filename) } static int +walkcomment(char *w, FILE *f) +{ + int i = 1; + char word[0x40]; + if(slen(w) != 1) + fprintf(stderr, "-- Malformed comment: %s\n", w); + while(fscanf(f, "%63s", word) == 1) { + if(slen(word) != 1) + continue; + else if(word[0] == '(') + i++; + else if(word[0] == ')' && --i < 1) + break; + } + return 1; +} + +static int parse(char *w, FILE *f) { int i; - char word[0x40], c; + char c; Macro *m; switch(w[0]) { - case '(': /* comment */ - if(slen(w) != 1) fprintf(stderr, "-- Malformed comment: %s\n", w); - i = 1; /* track nested comment depth */ - while(fscanf(f, "%63s", word) == 1) { - if(slen(word) != 1) - continue; - else if(word[0] == '(') - i++; - else if(word[0] == ')' && --i < 1) - break; - } - break; + case '(': return walkcomment(w, f); case '~': return !doinclude(w + 1) ? error_asm("Invalid include") : 1; case '%': return !makemacro(w + 1, f) ? error_asm("Invalid macro") : 1; case '@': return !makelabel(w + 1, 1) ? error_asm("Invalid label") : 1;