Hacky attempts at if statements. If someone wants to clean this up and make it work, they have eternal gratitude.

This commit is contained in:
Darryl Pogue
2010-08-31 23:20:40 -07:00
parent 49c15b324c
commit 96235c9290

View File

@@ -330,6 +330,31 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
stack.push(new ASTBinary(src, right, ASTBinary::BIN_SUBTRACT));
}
break;
case (PY_1000 | Py1k::JUMP_IF_FALSE):
case (PY_2000 | Py2k::JUMP_IF_FALSE):
case (PY_3000 | Py3k::JUMP_IF_FALSE):
{
PycRef<ASTNode> cond = stack.top();
stack.pop();
stack.push(new ASTJump(operand, ASTJump::JMP_FALSE, cond));
}
break;
case (PY_1000 | Py1k::JUMP_IF_TRUE):
case (PY_2000 | Py2k::JUMP_IF_TRUE):
case (PY_3000 | Py3k::JUMP_IF_TRUE):
{
PycRef<ASTNode> cond = stack.top();
stack.pop();
stack.push(new ASTJump(operand, ASTJump::JMP_TRUE, cond));
}
break;
case (PY_1000 | Py1k::JUMP_FORWARD):
case (PY_2000 | Py2k::JUMP_FORWARD):
case (PY_3000 | Py3k::JUMP_FORWARD):
{
stack.push(new ASTJump(operand, ASTJump::JUMP, NULL));
}
break;
case (PY_1000 | Py1k::LOAD_ATTR):
case (PY_2000 | Py2k::LOAD_ATTR):
case (PY_3000 | Py3k::LOAD_ATTR):
@@ -854,6 +879,27 @@ void print_src(PycRef<ASTNode> node, PycModule* mod, int indent)
printf(")");
}
break;
case ASTNode::NODE_JUMP:
{
ASTJump::Condition jtype = node.cast<ASTJump>()->jtype();
if (jtype != ASTJump::JUMP) {
printf("if (");
if (jtype == ASTJump::JMP_TRUE)
printf("not ");
print_src(node.cast<ASTJump>()->cond(), mod, indent);
printf("):");
cur_indent++;
} else {
if (node.cast<ASTJump>()->dest() != 1) {
printf("else:"); /* HAX! */
cur_indent++;
}
}
}
break;
case ASTNode::NODE_POP_HACK:
cur_indent--;
break;
default:
printf("<NODE:%d>", node->type());
fprintf(stderr, "Unsupported Node type: %d\n", node->type());