Merge pull request #30 from dpogue/lambdas
Lambda fix and test cases
This commit is contained in:
37
ASTree.cpp
37
ASTree.cpp
@@ -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);
|
||||
|
BIN
tests/25_test_applyEquiv.pyc
Normal file
BIN
tests/25_test_applyEquiv.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_augmentedAssign.pyc
Normal file
BIN
tests/25_test_augmentedAssign.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_class.pyc
Normal file
BIN
tests/25_test_class.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_del.pyc
Normal file
BIN
tests/25_test_del.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_divide_future.pyc
Normal file
BIN
tests/25_test_divide_future.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_divide_no_future.pyc
Normal file
BIN
tests/25_test_divide_no_future.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_docstring.pyc
Normal file
BIN
tests/25_test_docstring.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_empty.pyc
Normal file
BIN
tests/25_test_empty.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_exceptions.pyc
Normal file
BIN
tests/25_test_exceptions.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_exec.pyc
Normal file
BIN
tests/25_test_exec.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_expressions.pyc
Normal file
BIN
tests/25_test_expressions.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_extendedImport.pyc
Normal file
BIN
tests/25_test_extendedImport.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_extendedPrint.pyc
Normal file
BIN
tests/25_test_extendedPrint.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_functions.pyc
Normal file
BIN
tests/25_test_functions.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_global.pyc
Normal file
BIN
tests/25_test_global.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_globals.pyc
Normal file
BIN
tests/25_test_globals.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_import.pyc
Normal file
BIN
tests/25_test_import.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_import_as.pyc
Normal file
BIN
tests/25_test_import_as.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_integers.pyc
Normal file
BIN
tests/25_test_integers.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_iterators.pyc
Normal file
BIN
tests/25_test_iterators.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_lambda.pyc
Normal file
BIN
tests/25_test_lambda.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_listComprehensions.pyc
Normal file
BIN
tests/25_test_listComprehensions.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_loops.pyc
Normal file
BIN
tests/25_test_loops.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_loops2.pyc
Normal file
BIN
tests/25_test_loops2.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_misc.pyc
Normal file
BIN
tests/25_test_misc.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_nested_elif.pyc
Normal file
BIN
tests/25_test_nested_elif.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_nested_scopes.pyc
Normal file
BIN
tests/25_test_nested_scopes.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_prettyprint.pyc
Normal file
BIN
tests/25_test_prettyprint.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_print.pyc
Normal file
BIN
tests/25_test_print.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_print_to.pyc
Normal file
BIN
tests/25_test_print_to.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_single_stmt.pyc
Normal file
BIN
tests/25_test_single_stmt.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_slices.pyc
Normal file
BIN
tests/25_test_slices.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_tuple_params.pyc
Normal file
BIN
tests/25_test_tuple_params.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_tuples.pyc
Normal file
BIN
tests/25_test_tuples.pyc
Normal file
Binary file not shown.
BIN
tests/25_test_yield.pyc
Normal file
BIN
tests/25_test_yield.pyc
Normal file
Binary file not shown.
BIN
tests/27_lambdas_assignment.pyc
Normal file
BIN
tests/27_lambdas_assignment.pyc
Normal file
Binary file not shown.
BIN
tests/27_tuple_loops.pyc
Normal file
BIN
tests/27_tuple_loops.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user