diff --git a/ASTree.cpp b/ASTree.cpp index 6d80b23..ba31382 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -580,6 +580,34 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.push(call); } break; + case Pyc::CALL_METHOD_A: + { + ASTCall::pparam_t pparamList; + for (int i = 0; i < operand; i++) { + PycRef param = stack.top(); + stack.pop(); + if (param.type() == ASTNode::NODE_FUNCTION) { + PycRef fun_code = param.cast()->code(); + PycRef code_src = fun_code.cast()->object().cast(); + PycRef function_name = code_src->name(); + if (function_name->isEqual("")) { + pparamList.push_front(param); + } else { + // Decorator used + PycRef decor_name = new ASTName(function_name); + curblock->append(new ASTStore(param, decor_name)); + + pparamList.push_front(decor_name); + } + } else { + pparamList.push_front(param); + } + } + PycRef func = stack.top(); + stack.pop(); + stack.push(new ASTCall(func, pparamList, ASTCall::kwparam_t())); + } + break; case Pyc::CONTINUE_LOOP_A: curblock->append(new ASTKeyword(ASTKeyword::KW_CONTINUE)); break; @@ -1476,6 +1504,14 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) case Pyc::STORE_LOCALS: stack.pop(); break; + case Pyc::LOAD_METHOD_A: + { + // Behave like LOAD_ATTR + PycRef name = stack.top(); + stack.pop(); + stack.push(new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR)); + } + break; case Pyc::LOAD_NAME_A: stack.push(new ASTName(code->getName(operand))); break; diff --git a/tests/compiled/load_method.3.7.pyc b/tests/compiled/load_method.3.7.pyc new file mode 100644 index 0000000..c07bd56 Binary files /dev/null and b/tests/compiled/load_method.3.7.pyc differ diff --git a/tests/compiled/load_method.3.9.pyc b/tests/compiled/load_method.3.9.pyc new file mode 100644 index 0000000..fd5ed60 Binary files /dev/null and b/tests/compiled/load_method.3.9.pyc differ diff --git a/tests/xfail/private_name.3.7.pyc b/tests/compiled/private_name.3.7.pyc similarity index 100% rename from tests/xfail/private_name.3.7.pyc rename to tests/compiled/private_name.3.7.pyc diff --git a/tests/compiled/test_class_method_py3.3.7.pyc b/tests/compiled/test_class_method_py3.3.7.pyc new file mode 100644 index 0000000..0e2f280 Binary files /dev/null and b/tests/compiled/test_class_method_py3.3.7.pyc differ diff --git a/tests/input/load_method.py b/tests/input/load_method.py new file mode 100644 index 0000000..07794a4 --- /dev/null +++ b/tests/input/load_method.py @@ -0,0 +1,15 @@ +class C: + def test1(self): + a = 1 + + def test2(self, x, y, z): + a = x * y + z + + # @staticmethod -- TODO: Fix decorators + def testS(): + a = 3 + +c = C() +c.test1() +c.test2(42, 5, -1) +C.testS() diff --git a/tests/tokenized/load_method.txt b/tests/tokenized/load_method.txt new file mode 100644 index 0000000..86803de --- /dev/null +++ b/tests/tokenized/load_method.txt @@ -0,0 +1,19 @@ +class C : + +def test1 ( self ) : + +a = 1 + +def test2 ( self , x , y , z ) : + +a = x * y + z + +def testS ( ) : + +a = 3 + + +c = C ( ) +c . test1 ( ) +c . test2 ( 42 , 5 , - 1 ) +C . testS ( ) diff --git a/tests/xfail/loadbuild_class.3.7.pyc b/tests/xfail/loadbuild_class.3.7.pyc new file mode 100644 index 0000000..aa688fe Binary files /dev/null and b/tests/xfail/loadbuild_class.3.7.pyc differ