Fix for the lambda assignment issue.

Refs #27.
This commit is contained in:
Darryl Pogue
2013-06-28 23:22:25 -07:00
parent 4a64f7fee9
commit 4b335fb248

View File

@@ -1,3 +1,4 @@
#include <cstring>
#include "ASTree.h"
#include "FastStack.h"
#include "pyc_numeric.h"
@@ -2511,13 +2512,24 @@ void print_src(PycRef<ASTNode> node, PycModule* mod)
PycRef<ASTNode> src = node.cast<ASTStore>()->src();
PycRef<ASTNode> dest = node.cast<ASTStore>()->dest();
if (src->type() == ASTNode::NODE_FUNCTION) {
PycRef<ASTNode> code = src.cast<ASTFunction>()->code();
PycRef<PycCode> code_src = code.cast<ASTObject>()->object().cast<PycCode>();
bool isLambda = false;
if (strncmp(code_src->name()->value(), "<lambda>", 8) == 0) {
fprintf(pyc_output, "\n");
start_line(cur_indent);
print_src(dest, mod);
fprintf(pyc_output, " = lambda ");
isLambda = true;
} else {
fprintf(pyc_output, "\n");
start_line(cur_indent);
fprintf(pyc_output, "def ");
print_src(dest, mod);
fprintf(pyc_output, "(");
PycRef<ASTNode> code = src.cast<ASTFunction>()->code();
PycRef<PycCode> code_src = code.cast<ASTObject>()->object().cast<PycCode>();
}
ASTFunction::defarg_t defargs = src.cast<ASTFunction>()->defargs();
ASTFunction::defarg_t::iterator da = defargs.begin();
bool first = true;
@@ -2548,9 +2560,20 @@ void print_src(PycRef<ASTNode> node, PycModule* mod)
fprintf(pyc_output, "**%s", code_src->getVarName(idx)->value());
first = false;
}
if (isLambda) {
fprintf(pyc_output, " : ");
} else {
fprintf(pyc_output, "):\n");
printGlobals = true;
}
bool preLambda = inLambda;
inLambda |= isLambda;
print_src(code, mod);
inLambda = preLambda;
} else if (src->type() == ASTNode::NODE_CLASS) {
fprintf(pyc_output, "\n");
start_line(cur_indent);