Smarter clean up of dirty registers
This commit is contained in:
parent
19d03dc116
commit
7c247d7181
20
src/modal.c
20
src/modal.c
|
@ -5,13 +5,12 @@ typedef struct {
|
||||||
char *a, *b;
|
char *a, *b;
|
||||||
} Rule;
|
} Rule;
|
||||||
|
|
||||||
static unsigned char rmin = 0xff, rmax = 0x00;
|
|
||||||
static int flip, quiet, debug, cycles = 0x10000;
|
static int flip, quiet, debug, cycles = 0x10000;
|
||||||
static Rule rules[0x1000], *rules_ = rules, lambda;
|
static Rule rules[0x1000], *rules_ = rules, lambda;
|
||||||
static char dict[0x8000], *dict_ = dict, empty;
|
static char dict[0x8000], *dict_ = dict, empty;
|
||||||
static char bank_a[0x4000], *src_ = bank_a;
|
static char bank_a[0x4000], *src_ = bank_a;
|
||||||
static char bank_b[0x4000], *dst_ = bank_b;
|
static char bank_b[0x4000], *dst_ = bank_b;
|
||||||
static char *regs[0x100];
|
static char *regs[0x100], stack[0x10], *stack_ = stack;
|
||||||
|
|
||||||
#define spacer(c) (c <= ' ' || c == '(' || c == ')')
|
#define spacer(c) (c <= ' ' || c == '(' || c == ')')
|
||||||
|
|
||||||
|
@ -148,14 +147,10 @@ write_tail(char *s)
|
||||||
static int
|
static int
|
||||||
apply_rule(Rule *r, char *s)
|
apply_rule(Rule *r, char *s)
|
||||||
{
|
{
|
||||||
unsigned char i, rid;
|
unsigned char rid;
|
||||||
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
|
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
|
||||||
/* phase: clean regs */
|
/* phase: clean regs */
|
||||||
if(rmax) {
|
while(stack_ != stack) regs[(int)*(--stack_)] = 0;
|
||||||
for(i = 0; i <= rmax; i++)
|
|
||||||
regs[i] = 0;
|
|
||||||
rmin = 0xff, rmax = 0x00;
|
|
||||||
}
|
|
||||||
/* phase: match rule */
|
/* phase: match rule */
|
||||||
while((c = *a++)) {
|
while((c = *a++)) {
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
|
@ -165,11 +160,8 @@ apply_rule(Rule *r, char *s)
|
||||||
char *rcap = walk(reg), *pp = s;
|
char *rcap = walk(reg), *pp = s;
|
||||||
while(reg < rcap || pp < pcap)
|
while(reg < rcap || pp < pcap)
|
||||||
if(*reg++ != *pp++) return 0;
|
if(*reg++ != *pp++) return 0;
|
||||||
} else { /* reg set */
|
} else /* reg set */
|
||||||
regs[rid] = s;
|
regs[rid] = s, *stack_++ = rid;
|
||||||
if(rid < rmin) rmin = rid;
|
|
||||||
if(rid > rmax) rmax = rid;
|
|
||||||
}
|
|
||||||
s = pcap;
|
s = pcap;
|
||||||
} else if(c != *s++)
|
} else if(c != *s++)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -294,7 +286,7 @@ main(int argc, char **argv)
|
||||||
return !printf("usage: modal [-vqn] source.modal\n");
|
return !printf("usage: modal [-vqn] source.modal\n");
|
||||||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||||
switch(argv[i][1]) {
|
switch(argv[i][1]) {
|
||||||
case 'v': /* version */ return !printf("Modal Interpreter, 2 May 2024.\n");
|
case 'v': /* version */ return !printf("Modal Interpreter, 4 May 2024.\n");
|
||||||
case 'q': /* quiet */ quiet = 1; break;
|
case 'q': /* quiet */ quiet = 1; break;
|
||||||
case 'p': /* debug */ debug = 1; break;
|
case 'p': /* debug */ debug = 1; break;
|
||||||
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
||||||
|
|
Loading…
Reference in New Issue