Compress program on load
This commit is contained in:
parent
135204131a
commit
2250f9231e
|
@ -1,4 +1,5 @@
|
|||
<> (plode (String ?*)) (String ?*)
|
||||
|
||||
(plode (plode (String hello)))
|
||||
<> (?x dup) (?x ?x)
|
||||
<> (?x ?y swap) (?y ?x)
|
||||
<> ( ?x pop) ()
|
||||
|
||||
(1 2 3) (4 5 6) swap pop dup
|
||||
|
|
25
src/modal.c
25
src/modal.c
|
@ -213,18 +213,37 @@ print_rules(void)
|
|||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static int
|
||||
load(char *path)
|
||||
{
|
||||
char c, *w = bank_a;
|
||||
FILE *f = fopen(path, "r");
|
||||
if(!f) return 0;
|
||||
while(fread(&c, 1, 1, f)) {
|
||||
if(prog_ > bank_a) {
|
||||
if(c == ')' && *(w - 1) == ' ') w--;
|
||||
if(c == '(' && *(w - 1) == ' ') w--;
|
||||
if(c == ' ' && *(w - 1) == ' ') w--;
|
||||
if(c == ' ' && *(w - 1) == '(') continue;
|
||||
if(c == ' ' && *(w - 1) == ')') continue;
|
||||
}
|
||||
*w++ = c;
|
||||
}
|
||||
*w++ = 0;
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
if(argc < 2)
|
||||
return !printf("usage: modal [-v] source.modal\n");
|
||||
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
||||
return !printf("Modal - Modal Interpreter, 4 Apr 2024.\n");
|
||||
if(!(f = fopen(argv[1], "r")))
|
||||
if(!load(argv[1]))
|
||||
return !printf("Invalid Modal file: %s.\n", argv[1]);
|
||||
queue = 2;
|
||||
fread(bank_a, 1, 0x1000, f), fclose(f);
|
||||
while(rewrite(argv[queue]))
|
||||
;
|
||||
print_rules();
|
||||
|
|
Loading…
Reference in New Issue