diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5475a73 --- /dev/null +++ b/.clang-format @@ -0,0 +1,22 @@ +AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign +AlignOperands: DontAlign +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: TopLevel +BreakBeforeTernaryOperators: false +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: WebKit +IndentCaseLabels: false +TabWidth: 4 +IndentWidth: 4 +ContinuationIndentWidth: 4 +UseTab: ForContinuationAndIndentation +ColumnLimit: 0 +ReflowComments: false +SortIncludes: false +SpaceBeforeParens: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad2e80e --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.DS* +*jpg~ +*png~ +*gif~ +*bmp~ +/bin +*io.bit +*.bak +/*-test +/screenshot-*.bmp + +*snarf +*theme + +*.[o0125678vqki] diff --git a/makefile b/makefile new file mode 100644 index 0000000..c11ef42 --- /dev/null +++ b/makefile @@ -0,0 +1,26 @@ +RELEASE_flags=-DNDEBUG -O2 -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 + +.PHONY: all debug dest run test install uninstall format clean + +all: dest bin/modal + +dest: + @ mkdir -p bin +run: all + @ bin/modal test.modal +test: all + @ bin/modal -v + @ bin/modal test.modal +install: all + @ cp bin/modal ~/bin/ +uninstall: + @ rm -f ~/bin/modal +format: + @ clang-format -i src/modal.c +clean: + @ rm -fr bin + +bin/modal: src/modal.c + @ cc ${DEBUG_flags} ${CFLAGS} src/modal.c -o bin/modal + diff --git a/modal.py b/modal.py index 9e8dfd7..e3afa9b 100644 --- a/modal.py +++ b/modal.py @@ -303,7 +303,7 @@ def run(rules, queue, limit=pow(2, 32)): result, queue = operation(queue, rules, pattern, *parameters) if result == True: failures = 0 - #print("<>: ", inspect(seek(queue, ["SRT"]))) + print("<>: ", inspect(seek(queue, ["SRT"]))) #print("<>: ", inspect(queue)) #input() steps = steps + 1 diff --git a/src/modal.c b/src/modal.c new file mode 100644 index 0000000..6b84083 --- /dev/null +++ b/src/modal.c @@ -0,0 +1,41 @@ +#include + +static int +walk(FILE *f) +{ + char c, token[0x40], *cptr = token; + while(f && fread(&c, 1, 1, f)) { + if(c < 0x21) { + *cptr++ = 0x00; + printf("> %s\n", token); + cptr = token; + } else if(cptr - token < 0x3f) + *cptr++ = c; + else + return printf("Token too long: %s\n", token); + } + *cptr++ = 0; + return 1; +} + +static int +eval(char *path) +{ + FILE *f; + if(!(f = fopen(path, "r"))) + return !printf("Invalid file: %s\n", path); + walk(f); + + fclose(f); + return 1; +} + +int +main(int argc, char **argv) +{ + if(argc < 2) + return !printf("usage: modal [-v] source.modal\n"); + if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v') + return !printf("Modal - Modal Interpreter, 3 Apr 2024.\n"); + return !eval(argv[1]); +} \ No newline at end of file diff --git a/test.modal b/test.modal index 44f5e43..d6d2fc2 100644 --- a/test.modal +++ b/test.modal @@ -1,7 +1,3 @@ -define nil ((0)) -define (pair (?x) (?y)) ((?x ?y)) -define (first (?x ?y)) (?x) -define (second (?x ?y)) (?y) -define (quote ?x) (quote ?x) +<> (hello) (bye) -define test (first pair (A) (pair (B) (pair (C) nil))) \ No newline at end of file +hello world \ No newline at end of file