diff --git a/ASTree.cpp b/ASTree.cpp index 63a894e87..5e0f729ef 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1467,9 +1467,6 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) case Pyc::LOAD_BUILD_CLASS: stack.push(new ASTLoadBuildClass(new PycObject())); break; - case Pyc::LOAD_CLOSURE_A: - /* Ignore this */ - break; case Pyc::LOAD_CONST_A: { PycRef t_ob = new ASTObject(code->getConst(operand)); @@ -1487,6 +1484,7 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } break; case Pyc::LOAD_DEREF_A: + case Pyc::LOAD_CLOSURE_A: stack.push(new ASTName(code->getCellVar(mod, operand))); break; case Pyc::LOAD_FAST_A: @@ -1545,15 +1543,42 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } ASTFunction::defarg_t defArgs, kwDefArgs; - const int defCount = operand & 0xFF; - const int kwDefCount = (operand >> 8) & 0xFF; - for (int i = 0; i < defCount; ++i) { - defArgs.push_front(stack.top()); - stack.pop(); - } - for (int i = 0; i < kwDefCount; ++i) { - kwDefArgs.push_front(stack.top()); - stack.pop(); + + if (mod->verCompare(3, 6) < 0) { + const int defCount = operand & 0xFF; + const int kwDefCount = (operand >> 8) & 0xFF; + for (int i = 0; i < defCount; ++i) { + defArgs.push_front(stack.top()); + stack.pop(); + } + for (int i = 0; i < kwDefCount; ++i) { + kwDefArgs.push_front(stack.top()); + stack.pop(); + } + } else { + if (operand & 0x08) { + stack.pop(); + } + + if (operand & 0x04) { + stack.pop(); + } + + if (operand & 0x02) { + PycRef defaultsDict = stack.top().cast(); + stack.pop(); + + for (PycRef value : defaultsDict->values()) + kwDefArgs.push_front(value); + } + + if (operand & 0x01) { + PycRef defaultsTuple = stack.top().cast()->object().cast(); + stack.pop(); + + for (PycRef value : defaultsTuple->values()) + defArgs.push_back(new ASTObject(value)); + } } stack.push(new ASTFunction(fun_code, defArgs, kwDefArgs)); } diff --git a/tests/compiled/test_functions_py3.3.0.pyc b/tests/compiled/test_functions_py3.3.0.pyc index f29f67148..a5a6b3091 100644 Binary files a/tests/compiled/test_functions_py3.3.0.pyc and b/tests/compiled/test_functions_py3.3.0.pyc differ diff --git a/tests/compiled/test_functions_py3.3.4.pyc b/tests/compiled/test_functions_py3.3.4.pyc index 6c0fe16ae..045bd7384 100644 Binary files a/tests/compiled/test_functions_py3.3.4.pyc and b/tests/compiled/test_functions_py3.3.4.pyc differ diff --git a/tests/xfail/test_functions_py3.3.7.pyc b/tests/compiled/test_functions_py3.6.15.pyc similarity index 82% rename from tests/xfail/test_functions_py3.3.7.pyc rename to tests/compiled/test_functions_py3.6.15.pyc index 763ba8e6b..5a246cbae 100644 Binary files a/tests/xfail/test_functions_py3.3.7.pyc and b/tests/compiled/test_functions_py3.6.15.pyc differ diff --git a/tests/tokenized/test_functions_py3.txt b/tests/tokenized/test_functions_py3.txt index 8308e0b70..b9d25db24 100644 --- a/tests/tokenized/test_functions_py3.txt +++ b/tests/tokenized/test_functions_py3.txt @@ -34,18 +34,46 @@ def x4c ( foo , bar = 1 , bla = 2 , * args , ** kwargs ) : pass -def x5a ( * , bar = 1 ) : +def x5a ( * , bar ) : pass -def x5b ( * , bar = 1 , ** kwargs ) : +def x5b ( * , bar = 1 ) : pass -def x6a ( foo , * , bar = 1 ) : +def x5c ( * , bar = 1 , ** kwargs ) : pass -def x7a ( foo , * , bar = 1 , ** kwargs ) : +def x6a ( foo , * , bar ) : + +pass + +def x6b ( foo , * , bar = 1 ) : + +pass + +def x6c ( foo = 1 , * , bar ) : + +pass + +def x6d ( foo = 1 , * , bar = 2 ) : + +pass + +def x7a ( foo , * , bar , ** kwargs ) : + +pass + +def x7b ( foo , * , bar = 1 , ** kwargs ) : + +pass + +def x7c ( foo = 1 , * , bar , ** kwargs ) : + +pass + +def x7d ( foo = 1 , * , bar = 2 , ** kwargs ) : pass