This commit is contained in:
Devine Lu Linvega 2024-04-04 16:52:09 -07:00
parent 6ad9490f45
commit d0acff37be
2 changed files with 7 additions and 4 deletions

View File

@ -1,3 +1,4 @@
<> (duppre ?x) (?x ?x) <> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
what (duppre twice) (1234 dup)

View File

@ -11,15 +11,17 @@ static char prog[0x1000], *prog_ = prog;
static char outp[0x1000], *outp_ = outp; static char outp[0x1000], *outp_ = outp;
static char *regs[0x100]; static char *regs[0x100];
#define spacer(c) (c == ' ' || c == '(' || c == ')')
static char * static char *
walk(char *s) walk(char *s)
{ {
int depth = 0; int depth = 0;
char c; char c;
while((c = *s++)) { while((c = *s++)) {
if(spacer(c) && !depth) break;
if(c == '(') depth++; if(c == '(') depth++;
if(c == ')') --depth; if(c == ')') --depth;
if(c == ' ' && !depth) break;
} }
return s - 1; return s - 1;
} }
@ -42,9 +44,9 @@ writereg(char r)
int depth = 0; int depth = 0;
char c, *s = regs[(int)r]; char c, *s = regs[(int)r];
while((c = *s++)) { while((c = *s++)) {
if(spacer(c) && !depth) break;
if(c == '(') depth++; if(c == '(') depth++;
if(c == ')') --depth; if(c == ')') --depth;
if(c == ' ' && !depth) break;
*outp_++ = c; *outp_++ = c;
} }
return 1; return 1;