uxn

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

commit 19157a9ae1994def43f41fa89a274bd8425b196d
parent 72b0458745ba0ec9166886b5d45c3a4a0f2f822a
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 24 Apr 2021 17:12:25 -0700

Removed templating macros in assembler

Diffstat:
Mbuild.sh | 2+-
Metc/usm.sublime-syntax | 12++++++++++++
Mprojects/software/nasu.usm | 3+--
Mprojects/software/noodle.usm | 2+-
Msrc/assembler.c | 41++++++++++-------------------------------
5 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/build.sh b/build.sh @@ -32,7 +32,7 @@ else fi echo "Assembling.." -./bin/assembler projects/demos/bifurcan.usm bin/boot.rom +./bin/assembler projects/software/nasu.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax @@ -24,6 +24,12 @@ contexts: - match: '\.(\S+)\sPOK' scope: constant.numeric pop: true + - match: '\.(\S+)\sGET2' + scope: constant.numeric + pop: true + - match: '\.(\S+)\sGET' + scope: constant.numeric + pop: true - match: '\.(\S+)\sDEI2' scope: entity.name.type.typedef @@ -37,6 +43,12 @@ contexts: - match: '\.(\S+)\sPEK' scope: entity.name.type.typedef pop: true + - match: '\.(\S+)\sPUT2' + scope: entity.name.type.typedef + pop: true + - match: '\.(\S+)\sPUT' + scope: entity.name.type.typedef + pop: true # label - match: '\@(\S+)\s?' diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm @@ -12,7 +12,6 @@ Select paint color for 2-bit mode ) - %RTN { JMP2r } %STEP8 { #0033 SFT2 } @@ -726,7 +725,7 @@ RTN [ 0038 4492 2810 0000 ] ( open ) [ 0000 0082 4438 0000 ] ( closed ) @tool_selector [ 80c0 e0f0 f8e0 1000 ] -@tool_hand [ 4040 4070 f8f8 f870 ] +@tool_hand [ 2020 20b8 7c7c 3838 ] @tool_eraser [ 2050 b87c 3e1c 0800 ] @moveup_icn [ 0010 387c fe10 1000 ] @movedown_icn [ 0010 1010 fe7c 3810 ] diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm @@ -943,7 +943,7 @@ RTN @pointers_icn [ 80c0 e0f0 f8e0 1000 ] - [ 4040 4070 f8f8 f870 ] + [ 2020 20b8 7c7c 3838 ] @eye_icn [ 0038 4492 2810 0000 ] ( open ) diff --git a/src/assembler.c b/src/assembler.c @@ -92,9 +92,6 @@ findmacro(char *name) for(i = 0; i < p.mlen; ++i) if(scmp(p.macros[i].name, name, 64)) return &p.macros[i]; - for(i = 0; i < p.mlen; ++i) - if(p.macros[i].name[0] == '%' && ssin(name, p.macros[i].name + 1) != -1) - return &p.macros[i]; return NULL; } @@ -131,25 +128,10 @@ findopcode(char *s) return 0; } -char *template(char *src, char *dst, char *w, Macro *m) -{ - char input[64]; - if(scin(src, '%') == -1) - return src; - scpy(w, input, ssin(w, m->name + 1) + 1); - scpy(src, dst, scin(src, '%') + 1); - scat(dst, input); - scat(dst, src + scin(src, '%') + 1); - return dst; -} - char * sublabel(char *src, char *scope, char *name) { - scpy(scope, src, 64); - scpy("/", src + slen(src), 64); - scpy(name, src + slen(src), 64); - return src; + return scat(scat(scpy(scope, src, 64), "/"), name); } #pragma mark - Parser @@ -237,9 +219,8 @@ walktoken(char *w) } if((m = findmacro(w))) { int i, res = 0; - char templated[64]; for(i = 0; i < m->len; ++i) - res += walktoken(template(m->items[i], templated, w, m)); + res += walktoken(m->items[i]); return res; } return error("Unknown label in first pass", w); @@ -286,20 +267,18 @@ parsetoken(char *w) else return 0; return 1; - } else if((m = findmacro(w))) { - int i; - for(i = 0; i < m->len; ++i) { - char templated[64]; - if(!parsetoken(template(m->items[i], templated, w, m))) - return 0; - } - return ++m->refs; } else if(sihx(w)) { if(slen(w) == 2) pushbyte(shex(w), 0); else if(slen(w) == 4) pushshort(shex(w), 0); return 1; + } else if((m = findmacro(w))) { + int i; + for(i = 0; i < m->len; ++i) + if(!parsetoken(m->items[i])) + return 0; + return ++m->refs; } return 0; } @@ -337,7 +316,7 @@ pass1(FILE *f) int pass2(FILE *f) { - int ccmnt = 0, ctemplate = 0; + int ccmnt = 0, cmacr = 0; char w[64], scope[64], subw[64]; printf("Pass 2\n"); while(fscanf(f, "%s", w) == 1) { @@ -346,7 +325,7 @@ pass2(FILE *f) if(w[0] == '[') continue; if(w[0] == ']') continue; if(skipblock(w, &ccmnt, '(', ')')) continue; - if(skipblock(w, &ctemplate, '{', '}')) continue; + if(skipblock(w, &cmacr, '{', '}')) continue; if(w[0] == '|') { if(p.length && shex(w + 1) < p.ptr) return error("Memory Overwrite", w);