Merge pull request #30 from dpogue/lambdas

Lambda fix and test cases
This commit is contained in:
Michael Hansen
2013-06-29 12:12:25 -07:00
38 changed files with 30 additions and 7 deletions

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) {
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>();
bool isLambda = false;
if (strcmp(code_src->name()->value(), "<lambda>") == 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, "(");
}
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;
}
fprintf(pyc_output, "):\n");
printGlobals = true;
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);

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_class.pyc Normal file

Binary file not shown.

BIN
tests/25_test_del.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_docstring.pyc Normal file

Binary file not shown.

BIN
tests/25_test_empty.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_exec.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_functions.pyc Normal file

Binary file not shown.

BIN
tests/25_test_global.pyc Normal file

Binary file not shown.

BIN
tests/25_test_globals.pyc Normal file

Binary file not shown.

BIN
tests/25_test_import.pyc Normal file

Binary file not shown.

BIN
tests/25_test_import_as.pyc Normal file

Binary file not shown.

BIN
tests/25_test_integers.pyc Normal file

Binary file not shown.

BIN
tests/25_test_iterators.pyc Normal file

Binary file not shown.

BIN
tests/25_test_lambda.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_loops.pyc Normal file

Binary file not shown.

BIN
tests/25_test_loops2.pyc Normal file

Binary file not shown.

BIN
tests/25_test_misc.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_print.pyc Normal file

Binary file not shown.

BIN
tests/25_test_print_to.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_slices.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
tests/25_test_tuples.pyc Normal file

Binary file not shown.

BIN
tests/25_test_yield.pyc Normal file

Binary file not shown.

Binary file not shown.

BIN
tests/27_tuple_loops.pyc Normal file

Binary file not shown.