?~ register now takes in an argument

This commit is contained in:
Devine Lu Linvega 2024-04-14 17:33:42 -07:00
parent dacb9836a0
commit b5b6472ebc
4 changed files with 41 additions and 46 deletions

View File

@ -1,9 +1,9 @@
<> ((You said: quit\n) send) ((You quit.) print ') <> ((You said: quit\n) send) ((You quit.) print ')
<> (?: print ') (?:) <> (?: print ') (?:)
<> (?: send) (?: wait) <> (?: send) (?: wait stdin)
<> (wait) ((You said: ?~\n) send) <> (wait ?~) ((You said: ?~\n) send)
<> (' ?x) (?x ') <> (' ?x) (?x ')
(Say something, or type "quit": \n) print ' (Say something, or type "quit": \n) print '
wait wait stdin

View File

@ -1,5 +1,4 @@
<> (NAME) (Modal)
<> (?: print $) (?:)
<> ($ ?x) (?x $)
$ (Welcome to NAME \nHave fun!\n\n) print <> (listen ?~) (?~ done.)
foo listen stdin bar

View File

@ -1,7 +1,7 @@
-- (Tic Tac Toe) -- (Tic Tac Toe)
<> (-- ?x) () <> (-- ?x) ()
<> (READ) (?~) <> (READ ?~) (?~)
-- (Print) -- (Print)
@ -34,8 +34,8 @@
-- (Play) -- (Play)
<> (ready) (display READ play) <> (ready) (display READ stdin play)
<> (?x run wait) (READ play) <> (?x run wait) (READ stdin play)
<> (?x victory) ((?x wins!\n) put-str) <> (?x victory) ((?x wins!\n) put-str)
-- (Interface) -- (Interface)

View File

@ -45,29 +45,24 @@ set_reg(int r, char *b)
static void static void
put_reg(char r) put_reg(char r)
{ {
char c, *s = regs[(int)r]; char c, *s = regs[(int)r], *ss;
if(r == '~') { if(!s) {
/* special stdin */ *outp_++ = '?', *outp_++ = r;
while(fread(&c, 1, 1, stdin) && c >= ' ') return;
*outp_++ = c; }
} else if(s) { *ss = walk(s);
char *ss = walk(s);
if(r == '*') { if(r == '*') {
/* special implode */ if(*s == '(') { /* special implode */
if(*s == '(') {
while(s < ss && (c = *s++)) while(s < ss && (c = *s++))
if(!spacer(c)) *outp_++ = c; if(!spacer(c)) *outp_++ = c;
} } else { /* special explode */
/* special explode */
else {
int i, depth = 0; int i, depth = 0;
while((c = *s++) && !spacer(c)) while((c = *s++) && !spacer(c))
*outp_++ = c, *outp_++ = ' ', *outp_++ = '(', depth++; *outp_++ = c, *outp_++ = ' ', *outp_++ = '(', depth++;
for(i = 0; i < depth; i++) for(i = 0; i < depth; i++)
*outp_++ = ')'; *outp_++ = ')';
} }
} else if(r == ':') { } else if(r == ':') { /* special stdout */
/* special stdout */
if(*s == '(') s++, --ss; if(*s == '(') s++, --ss;
while(s < ss) { while(s < ss) {
c = *s++; c = *s++;
@ -80,10 +75,11 @@ put_reg(char r)
} else } else
putc(c, stdout); putc(c, stdout);
} }
} else if(r == '~') { /* special stdin */
while(fread(&c, 1, 1, stdin) && c >= ' ')
*outp_++ = c;
} else } else
while(s < ss) *outp_++ = *s++; while(s < ss) *outp_++ = *s++;
} else
*outp_++ = '?', *outp_++ = r;
} }
static char * static char *