Merge remote-tracking branch 'upstream/master' into d6/binary
This commit is contained in:
commit
dcd8b283e5
|
@ -1,7 +1,7 @@
|
||||||
?(?-) (This example joins two tokens.)
|
?(?-) (This example joins two tokens.)
|
||||||
|
|
||||||
<> (join (?a) (?*)) (join reverse (?a) List (?*))
|
<> (join (?a) (?*)) (join reverse (?a) List (?*))
|
||||||
<> (join List () List ?*) (?*)
|
<> (join List () List ?^) (?^)
|
||||||
<> (join List (?x ?y) List ?z) (join List ?y List (?x ?z))
|
<> (join List (?x ?y) List ?z) (join List ?y List (?x ?z))
|
||||||
|
|
||||||
<> (reverse List ()) (List)
|
<> (reverse List ()) (List)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
?(?-) (This example reverses the string modal, into ladom.)
|
?(?-) (This example reverses the string modal, into ladom.)
|
||||||
|
|
||||||
<> (reverse List () ?*) (?*)
|
<> (reverse List () ?^) (?^)
|
||||||
<> (reverse (?*)) (reverse List (?*) ())
|
<> (reverse (?*)) (reverse List (?*) ())
|
||||||
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
|
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
?(?-) (This example tests various aspects of the implementation.)
|
?(?-) (This example tests various aspects of the implementation.)
|
||||||
|
|
||||||
<> (?: print) (?:)
|
|
||||||
<> (?x = ?x test) (#ok)
|
|
||||||
<> (?x = ?y test) (#fail)
|
|
||||||
|
|
||||||
?(?-) (Inline rules)
|
?(?-) (Inline rules)
|
||||||
|
|
||||||
<> ((?x -> ?y)) (<> ?x ?y)
|
<> ((?x -> ?y)) (<> ?x ?y)
|
||||||
|
@ -15,9 +11,11 @@ nap tap test
|
||||||
|
|
||||||
<> (?x pop-plain)
|
<> (?x pop-plain)
|
||||||
<> (?x pop) ()
|
<> (?x pop) ()
|
||||||
|
<> (ghost) ()
|
||||||
|
|
||||||
abc def pop-plain = abc test
|
abc def pop-plain = abc test
|
||||||
abc def pop = abc test
|
abc def pop = abc test
|
||||||
|
(ghost) = () test
|
||||||
|
|
||||||
?(?-) (Basic replacements)
|
?(?-) (Basic replacements)
|
||||||
|
|
||||||
|
@ -57,17 +55,26 @@ abc ?(?x) def = abc test
|
||||||
<> (explode ?*) ((?*) =)
|
<> (explode ?*) ((?*) =)
|
||||||
|
|
||||||
explode cow (c (o (w ()))) test
|
explode cow (c (o (w ()))) test
|
||||||
|
explode (12 34 45) (12 (34 (45 ()))) test
|
||||||
|
|
||||||
?(?-) (Implode)
|
?(?-) (Implode)
|
||||||
|
|
||||||
<> (implode ?*) (?* =)
|
<> (implode ?^) (?^ =)
|
||||||
|
|
||||||
implode (b (a (t ()))) bat test
|
implode (b (a (t ()))) bat test
|
||||||
|
implode (12 (34 (56 ()))) 123456 test
|
||||||
|
|
||||||
|
?(?-) (Test Primitives)
|
||||||
|
|
||||||
|
<> (?: print) (?:)
|
||||||
|
<> (?x = ?x test) (#ok)
|
||||||
|
<> (?x = ?y test) (#fail)
|
||||||
|
|
||||||
?(?-) (List reversal)
|
?(?-) (List reversal)
|
||||||
|
|
||||||
<> (reverse List () ?*) (?*)
|
<> (reverse List () ?^) (?^)
|
||||||
<> (reverse (?*)) (reverse List (?*) ())
|
<> (reverse (?*)) (reverse List (?*) ())
|
||||||
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
|
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
|
||||||
|
|
||||||
reverse (modal) = ladom test
|
reverse (modal) = ladom test
|
||||||
|
|
||||||
|
|
4
makefile
4
makefile
|
@ -1,7 +1,7 @@
|
||||||
RELEASE_flags=-DNDEBUG -O2 -g0 -s
|
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
|
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 archive
|
.PHONY: all debug dest run debug test install uninstall format clean archive
|
||||||
|
|
||||||
all: dest
|
all: dest
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ dest:
|
||||||
@ mkdir -p bin
|
@ mkdir -p bin
|
||||||
run: all bin/modal
|
run: all bin/modal
|
||||||
@ bin/modal examples/hello.modal 2> /dev/null
|
@ bin/modal examples/hello.modal 2> /dev/null
|
||||||
|
debug: bin/modal-debug
|
||||||
|
@ bin/modal-debug examples/hello.modal
|
||||||
test: bin/modal-debug bin/modal
|
test: bin/modal-debug bin/modal
|
||||||
@ bin/modal -v
|
@ bin/modal -v
|
||||||
@ bin/modal-debug examples/tests.modal
|
@ bin/modal-debug examples/tests.modal
|
||||||
|
|
38
src/modal.c
38
src/modal.c
|
@ -55,16 +55,31 @@ put_reg(char r)
|
||||||
}
|
}
|
||||||
ss = walk(s);
|
ss = walk(s);
|
||||||
if(r == '*') {
|
if(r == '*') {
|
||||||
if(*s == '(') { /* special implode */
|
int i, depth = 0;
|
||||||
while(s < ss && (c = *s++))
|
if(*s == '(') { /* special explode tuple */
|
||||||
if(!spacer(c)) *dst_++ = c;
|
s++;
|
||||||
} else { /* special explode */
|
while(s < ss) {
|
||||||
int i, depth = 0;
|
while((c = *s) && !spacer(c))
|
||||||
|
*dst_++ = c, s++;
|
||||||
|
*dst_++ = ' ';
|
||||||
|
*dst_++ = '(', s++, depth++;
|
||||||
|
}
|
||||||
|
} else { /* special explode token */
|
||||||
while((c = *s++) && !spacer(c))
|
while((c = *s++) && !spacer(c))
|
||||||
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
|
*dst_++ = c, *dst_++ = ' ', *dst_++ = '(', depth++;
|
||||||
for(i = 0; i < depth; i++)
|
|
||||||
*dst_++ = ')';
|
|
||||||
}
|
}
|
||||||
|
for(i = 0; i < depth; i++)
|
||||||
|
*dst_++ = ')';
|
||||||
|
} else if(r == '.') { /* special unpack */
|
||||||
|
if(*s == '(') s++, --ss;
|
||||||
|
while(s < ss) *dst_++ = *s++;
|
||||||
|
} else if(r == '^') { /* special join */
|
||||||
|
if(*s == '(') s++, --ss;
|
||||||
|
while(s < ss && (c = *s++))
|
||||||
|
if(!spacer(c)) *dst_++ = c;
|
||||||
|
} else if(r == '~') { /* special stdin */
|
||||||
|
while(fread(&c, 1, 1, stdin) && c >= ' ')
|
||||||
|
*dst_++ = c;
|
||||||
} else if(r == ':') { /* special stdout */
|
} else if(r == ':') { /* special stdout */
|
||||||
if(*s == '(') s++, --ss;
|
if(*s == '(') s++, --ss;
|
||||||
while(s < ss) {
|
while(s < ss) {
|
||||||
|
@ -78,9 +93,6 @@ put_reg(char r)
|
||||||
} else
|
} else
|
||||||
putc(c, stdout);
|
putc(c, stdout);
|
||||||
}
|
}
|
||||||
} else if(r == '~') { /* special stdin */
|
|
||||||
while(fread(&c, 1, 1, stdin) && c >= ' ')
|
|
||||||
*dst_++ = c;
|
|
||||||
} else
|
} else
|
||||||
while(s < ss) *dst_++ = *s++;
|
while(s < ss) *dst_++ = *s++;
|
||||||
}
|
}
|
||||||
|
@ -134,8 +146,10 @@ write_rule(Rule *r, char last, char *res)
|
||||||
put_reg(*b++);
|
put_reg(*b++);
|
||||||
else
|
else
|
||||||
*dst_++ = c, last = c;
|
*dst_++ = c, last = c;
|
||||||
if(dst_ == origin)
|
if(dst_ == origin) {
|
||||||
while(*res == ' ') res++;
|
while(*res == ' ') res++;
|
||||||
|
if(*res == ')' && *(dst_ - 1) == ' ') dst_--;
|
||||||
|
}
|
||||||
return commit_rule(r, res, 0);
|
return commit_rule(r, res, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +220,7 @@ main(int argc, char **argv)
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
return !printf("usage: modal [-v] source.modal\n");
|
return !printf("usage: modal [-v] source.modal\n");
|
||||||
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
||||||
return !printf("Modal Interpreter, 16 Apr 2024.\n");
|
return !printf("Modal Interpreter, 17 Apr 2024.\n");
|
||||||
if(!(f = fopen(argv[1], "r")))
|
if(!(f = fopen(argv[1], "r")))
|
||||||
return !fprintf(stderr, "Invalid Modal file: %s.\n", argv[1]);
|
return !fprintf(stderr, "Invalid Modal file: %s.\n", argv[1]);
|
||||||
while(fread(&c, 1, 1, f)) {
|
while(fread(&c, 1, 1, f)) {
|
||||||
|
|
Loading…
Reference in New Issue