From 02f2769153d9f77edf5bfe73f2ab8730cd4be3fe Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 10 Apr 2023 10:16:17 -0700 Subject: [PATCH] Cleaned up build script --- build.sh | 26 ++++++-------------------- src/uxnasm.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/build.sh b/build.sh index de48653..e0af39d 100755 --- a/build.sh +++ b/build.sh @@ -2,8 +2,9 @@ RELEASE_FLAGS="-Os -DNDEBUG -g0 -s" DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined" -EMU_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11" -CLI_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli" +CORE_DEVICES="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c" +EMU_INC="${CORE_DEVICES} src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/uxn11.c -o bin/uxn11 -lX11" +CLI_INC="${CORE_DEVICES} src/uxncli.c -o bin/uxncli" # find X11 libs on various systems if [ -e /usr/X11R6 ]; then @@ -12,31 +13,20 @@ if [ -e /usr/X11R6 ]; then DEBUG_FLAGS="-L/usr/X11R6/lib/ -I/usr/X11R6/include/ $DEBUG_FLAGS" fi - if [ "${1}" = '--format' ]; then - echo "Formatting.." clang-format -i src/uxn11.c clang-format -i src/uxnasm.c clang-format -i src/uxncli.c clang-format -i src/devices/* fi -echo "Cleaning.." rm -f bin/* mkdir -p bin -echo "Building.." -cc -DNDEBUG -Os -g0 -s src/uxnasm.c -o bin/uxnasm -if [ "${1}" = '--install' ]; -then - echo "Installing.." - gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC} - gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC} - cp bin/uxnasm ~/bin - cp bin/uxncli ~/bin - cp bin/uxn11 ~/bin -elif [ "${1}" = '--release' ]; +cc ${RELEASE_FLAGS} src/uxnasm.c -o bin/uxnasm + +if [ "${1}" = '--release' ]; then gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${EMU_INC} gcc ${C_FLAGS} ${LD_FLAGS} ${RELEASE_FLAGS} ${CLI_INC} @@ -45,10 +35,6 @@ else gcc ${C_FLAGS} ${LD_FLAGS} ${DEBUG_FLAGS} ${CLI_INC} fi -echo "Assembling.." bin/uxnasm etc/polycat.tal bin/polycat.rom - -echo "Running.." bin/uxn11 bin/polycat.rom -echo "Done." diff --git a/src/uxnasm.c b/src/uxnasm.c index 644b67d..4df21ae 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -39,7 +39,7 @@ typedef struct { Uint16 llen, mlen, rlen; Label labels[0x400]; Macro macros[0x100]; - Reference refs[0x400]; + Reference refs[0x800]; char scope[0x40]; } Program; @@ -179,7 +179,7 @@ makereference(char *scope, char *label, char rune, Uint16 addr) { char subw[0x40], parent[0x40]; Reference *r; - if(p.rlen == 0x1000) + if(p.rlen >= 0x800) return error("References limit exceeded", label); r = &p.refs[p.rlen++]; if(label[0] == '&') { @@ -253,6 +253,7 @@ parse(char *w, FILE *f) { int i; char word[0x40], subw[0x40], c; + Label *l; Macro *m; if(slen(w) >= 63) return error("Invalid token", w); @@ -278,14 +279,30 @@ parse(char *w, FILE *f) return error("Invalid macro", w); break; case '|': /* pad-absolute */ - if(!sihx(w + 1)) - return error("Invalid padding", w); - p.ptr = shex(w + 1); + if(sihx(w + 1)) + p.ptr = shex(w + 1); + else if(w[1] == '&') { + if(!sublabel(subw, p.scope, w + 2) || !(l = findlabel(subw))) + return error("Invalid sublabel", w); + p.ptr = l->addr; + } else { + if(!(l = findlabel(w + 1))) + return error("Invalid label", w); + p.ptr = l->addr; + } break; case '$': /* pad-relative */ - if(!sihx(w + 1)) - return error("Invalid padding", w); - p.ptr += shex(w + 1); + if(sihx(w + 1)) + p.ptr += shex(w + 1); + else if(w[1] == '&') { + if(!sublabel(subw, p.scope, w + 2) || !(l = findlabel(subw))) + return error("Invalid sublabel", w); + p.ptr += l->addr; + } else { + if(!(l = findlabel(w + 1))) + return error("Invalid label", w); + p.ptr += l->addr; + } break; case '@': /* label */ if(!makelabel(w + 1))