From d0acff37be332cbfebeab0c4224d66a3a124ed62 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 16:52:09 -0700 Subject: [PATCH] * --- examples/test.modal | 5 +++-- src/modal.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/test.modal b/examples/test.modal index a520c1c..729485c 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,3 +1,4 @@ -<> (duppre ?x) (?x ?x) +<> (?x dup) (?x ?x) +<> (?x ?y swap) (?y ?x) -what (duppre twice) \ No newline at end of file +(1234 dup) \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index 8ab0a04..f4aed5a 100644 --- a/src/modal.c +++ b/src/modal.c @@ -11,15 +11,17 @@ static char prog[0x1000], *prog_ = prog; static char outp[0x1000], *outp_ = outp; static char *regs[0x100]; +#define spacer(c) (c == ' ' || c == '(' || c == ')') + static char * walk(char *s) { int depth = 0; char c; while((c = *s++)) { + if(spacer(c) && !depth) break; if(c == '(') depth++; if(c == ')') --depth; - if(c == ' ' && !depth) break; } return s - 1; } @@ -42,9 +44,9 @@ writereg(char r) int depth = 0; char c, *s = regs[(int)r]; while((c = *s++)) { + if(spacer(c) && !depth) break; if(c == '(') depth++; if(c == ')') --depth; - if(c == ' ' && !depth) break; *outp_++ = c; } return 1;