diff --git a/examples/test.modal b/examples/test.modal index ba31c3a..7bf0ba0 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,5 +1,4 @@ <> (dup ?x) (?x ?x) -<> (?x ?y swap) (?y ?x) -((hey) (there) swap) +(dup (123)) diff --git a/src/modal.c b/src/modal.c index 12a5877..0619992 100644 --- a/src/modal.c +++ b/src/modal.c @@ -20,8 +20,11 @@ walk(char *s) char c; while((c = *s++)) { if(c == '(') depth++; - if(c == ')') --depth; - if(spacer(c) && !depth) break; + if(c == ')') { + --depth; + if(!depth) break; + } + if(depth < 0) break; } return s; } @@ -46,10 +49,13 @@ writereg(char r) int depth = 0; char c, *s = regs[(int)r]; while((c = *s++)) { - *outp_++ = c; if(c == '(') depth++; - if(c == ')') --depth; - if(!depth) break; + if(c == ')') { + --depth; + if(!depth) break; + } + if(depth < 0) break; + *outp_++ = c; } return 1; }