#include <iostream>
#include <cstdlib>
#include <cstring>
#include <memory>
struct cell {
int c, d;
// void *label;
};
size_t width(const char* s)
{
const char* p;
for (p = s; *p && *p == *s; p++);
return p - s;
}
size_t nop_width(const char* s)
{
const char *p;
for (p = s; *p; p++) {
if (*p == '>' || *p == '<' || *p == '+' || *p == '-')
break;
if (*p == '.' || *p == ',' || *p == '[' || *p == ']')
break;
}
return p - s;
}
cell* find_square_bracket_right(cell* p)
{
int depth = 0;
for (; p->c; p++) {
if (p->c == '[')
depth++;
else if (p->c == ']') {
if (depth == 0)
break;
else depth--;
}
}
return p;
}
cell* init_square_brackets(cell* b)
{
cell* p;
cell* q;
for (p = b; p->c; p++) {
if (p->c == '[') {
q = find_square_bracket_right(p + 1);
p->d = static_cast<int>(q - p + 1);
q->d = static_cast<int>(-(q - p) + 1);
}
}
return b;
}
cell* reject_d0(cell* cells)
{
cell* p;
cell* q;
for (p = cells; p->c && p->d; p++);
for (q = p; p->c; p++) {
if (p->d == 0)
continue;
for (; q->c; q++) {
if (q->d != 0)
continue;
*q++ = *p;
p->d = 0;
break;
}
}
q->c = '\0';
q->d = 0;
return cells;
}
cell* optimize_flat_loop(cell* cells)
{
cell *p, *a, *b, *c, *d, *e, *f, *g;
for (p = cells; p->c; p++) {
if (p->c != '[')
continue;
a = p + 1; b = p + 2;
if (a->c == '>' && b->c == ']') {
p->c = 'G';
p->d = a->d;
a->d = b->d = 0;
p += 3;
continue;
}
if (!(a->c == '+' && a->d == -1))
continue;
c = p + 3; d = p + 4; e = p + 5; f = p + 6; g = p + 7;
if (b->c == ']') {
p->c = 'H';
p->d = 1;
a->d = b->d = 0;
p += 2;
} else if (b->c == '>' && c->c == '+' && d->c == '>' && e->c == ']' && abs(c->d) == 1 && b->d + d->d == 0) {
p->c = (0 < c->d) ? 'I' : 'J';
p->d = b->d;
a->c = 'H';
a->d = 1;
b->d = c->d = d->d = e->d = 0;
p += 5;
} else if (b->c == '>' && c->c == '+' && d->c == '>' && e->c == '+' && f->c == '>' && g->c == ']' && abs(c->d) == 1 && abs(e->d) == 1 && b->d + d->d + f->d == 0) {
p->c = (0 < c->d) ? 'I' : 'J';
p->d = b->d;
a->c = (0 < e->d) ? 'I' : 'J';
a->d = b->d + d->d;
b->c = 'H';
b->d = 1;
c->d = d->d = e->d = f->d = g->d = 0;
p += 7;
}
}
return reject_d0(cells);
}
cell* scan(const char* s)
{
cell* cells = static_cast<cell*>(std::malloc(sizeof(cell) * (std::strlen(s) + 1)));
cell* p;
for (p = cells; *s; ) {
switch (p->c = *s) {
case '>': case '+':
p->d = static_cast<int>(width(s)); s += p->d; p++;
break;
case '<':
p->c = '>'; p->d = -static_cast<int>(width(s)); s -= p->d; p++;
break;
case '-':
p->c = '+'; p->d = -static_cast<int>(width(s)); s -= p->d; p++;
break;
case '.': case ',': case '[': case ']':
p->d = 1; s++; p++; break;
default:
s += nop_width(s); break;
}
}
p->c = '\0';
p->d = 0;
return init_square_brackets(optimize_flat_loop(cells));
}
cell* f(cell* ip0, char* dp)
{
cell *ip = ip0;
static char buff[10000] = {0};
char* bufp = buff;
while (true) {
switch (ip->c) {
case '>':
dp += ip->d; ip++;
break;
case '+':
*dp += ip->d; ip++;
break;
case '.':
// putchar(*dp);
*bufp++ = *dp;
ip++;
break;
case ',':
*dp = getchar(); ip++;
break;
case '[':
(*dp) ? ip++ : (ip += ip->d);
break;
case ']':
(*dp) ? (ip += ip->d) : ip++;
break;
case 'G':
while (*dp)
dp += ip->d;
ip++;
break;
case 'H':
*dp = 0; ip++;
break;
case 'I':
*(dp + ip->d) += *dp; ip++;
break;
case 'J':
*(dp + ip->d) -= *dp; ip++;
break;
case '\0':
goto end;
default:
ip++;
break;
}
}
end:
puts(buff);
return ip0;
}
void g(const char* s)
{
char data[30000] = {0};
// auto sw = std::make_unique<Stopwatch>();
// sw->Start();
free(f(scan(s), data));
// sw->Stop();
// std::cout << "Elapsed " << sw->ElapsedMillisecond() << "ms." << std::endl;
}
int main()
{
const char *s =
" A mandelbrot set f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