Iterative dumbification
This commit is contained in:
parent
a1077f7c03
commit
55bfa2289e
@ -185,10 +185,12 @@ static AST *xopify(AST *tlc, AST *chunk, AST *stmtPrev, AST *stmt, AST *e) {
|
||||
return varify(tlc, chunk, stmtPrev, stmt, e);
|
||||
}
|
||||
|
||||
static void dumben_chunk(AST *tlc, AST *chu) {
|
||||
static int dumben_chunk(AST *tlc, AST *chu) {
|
||||
AST *sPrev = NULL;
|
||||
AST *s = chu->chunk.statementFirst;
|
||||
|
||||
int effective = 0;
|
||||
|
||||
while(s) {
|
||||
|
||||
if(s->nodeKind == AST_STMT_IF) {
|
||||
@ -199,25 +201,33 @@ static void dumben_chunk(AST *tlc, AST *chu) {
|
||||
|
||||
if(is_xop(e->exprBinOp.operands[0]) == XOP_NOT_XOP) {
|
||||
e->exprBinOp.operands[0] = xopify(tlc, chu, sPrev, s, e->exprBinOp.operands[0]);
|
||||
effective = 1;
|
||||
}
|
||||
|
||||
if(is_xop(e->exprBinOp.operands[1]) == XOP_NOT_XOP) {
|
||||
e->exprBinOp.operands[1] = xopify(tlc, chu, sPrev, s, e->exprBinOp.operands[1]);
|
||||
effective = 1;
|
||||
}
|
||||
|
||||
if(is_xop(e->exprBinOp.operands[0]) == XOP_MEM && is_xop(e->exprBinOp.operands[1]) == XOP_MEM) {
|
||||
// Can't have two mems; put one in var
|
||||
|
||||
e->exprBinOp.operands[1] = varify(tlc, chu, sPrev, s, e->exprBinOp.operands[1]);
|
||||
effective = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
s->stmtIf.expression = varify(tlc, chu, sPrev, s, e);
|
||||
effective = 1;
|
||||
|
||||
}
|
||||
|
||||
dumben_chunk(tlc, s->stmtIf.then);
|
||||
effective |= dumben_chunk(tlc, s->stmtIf.then);
|
||||
|
||||
} else if(s->nodeKind == AST_STMT_LOOP) {
|
||||
|
||||
dumben_chunk(tlc, s->stmtLoop.body);
|
||||
effective |= dumben_chunk(tlc, s->stmtLoop.body);
|
||||
|
||||
} else if(s->nodeKind == AST_STMT_ASSIGN) {
|
||||
|
||||
@ -225,6 +235,7 @@ static void dumben_chunk(AST *tlc, AST *chu) {
|
||||
&& s->stmtAssign.to->nodeKind == AST_EXPR_UNARY_OP && s->stmtAssign.to->exprUnOp.operator == UNOP_DEREF) {
|
||||
|
||||
s->stmtAssign.to = varify(tlc, chu, sPrev, s, s->stmtAssign.to);
|
||||
effective = 1;
|
||||
}
|
||||
|
||||
} else if(s->nodeKind == AST_STMT_EXPR && s->stmtExpr.expr->nodeKind == AST_EXPR_CALL) {
|
||||
@ -234,6 +245,7 @@ static void dumben_chunk(AST *tlc, AST *chu) {
|
||||
for(int i = 0; i < argCount; i++) {
|
||||
if(is_xop(s->stmtExpr.expr->exprCall.args[i]) == XOP_NOT_XOP) {
|
||||
s->stmtExpr.expr->exprCall.args[i] = xopify(tlc, chu, sPrev, s, s->stmtExpr.expr->exprCall.args[i]);
|
||||
effective = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,8 +254,10 @@ static void dumben_chunk(AST *tlc, AST *chu) {
|
||||
sPrev = s;
|
||||
s = s->statement.next;
|
||||
}
|
||||
|
||||
return effective;
|
||||
}
|
||||
|
||||
void dumben_go(AST* tlc) {
|
||||
dumben_chunk(tlc, tlc);
|
||||
while(dumben_chunk(tlc, tlc));
|
||||
}
|
Loading…
Reference in New Issue
Block a user