@@ -47,6 +47,7 @@ pub struct PyContext {
4747 pub tuple_type : PyObjectRef ,
4848 pub dict_type : PyObjectRef ,
4949 pub function_type : PyObjectRef ,
50+ pub bound_method_type : PyObjectRef ,
5051}
5152
5253/*
@@ -70,6 +71,7 @@ impl PyContext {
7071 tuple_type : type_type. clone ( ) ,
7172 dict_type : type_type. clone ( ) ,
7273 function_type : objfunction:: create_type ( type_type. clone ( ) ) ,
74+ bound_method_type : objfunction:: create_bound_method_type ( type_type. clone ( ) ) ,
7375 type_type : type_type,
7476 }
7577 }
@@ -162,6 +164,16 @@ impl PyContext {
162164 )
163165 }
164166
167+ pub fn new_bound_method ( & self , function : PyObjectRef , object : PyObjectRef ) -> PyObjectRef {
168+ PyObject :: new (
169+ PyObjectKind :: BoundMethod {
170+ function : function,
171+ object : object,
172+ } ,
173+ self . bound_method_type . clone ( ) ,
174+ )
175+ }
176+
165177 /* TODO: something like this?
166178 pub fn new_instance(&self, name: String) -> PyObjectRef {
167179 PyObject::new(PyObjectKind::Class { name: name }, self.type_type.clone())
@@ -370,6 +382,10 @@ pub enum PyObjectKind {
370382 code : PyObjectRef ,
371383 scope : PyObjectRef ,
372384 } ,
385+ BoundMethod {
386+ function : PyObjectRef ,
387+ object : PyObjectRef ,
388+ } ,
373389 Scope {
374390 scope : Scope ,
375391 } ,
@@ -412,6 +428,10 @@ impl fmt::Debug for PyObjectKind {
412428 & PyObjectKind :: NameError { name : _ } => write ! ( f, "NameError" ) ,
413429 & PyObjectKind :: Code { ref code } => write ! ( f, "code: {:?}" , code) ,
414430 & PyObjectKind :: Function { code : _, scope : _ } => write ! ( f, "function" ) ,
431+ & PyObjectKind :: BoundMethod {
432+ function : _,
433+ object : _,
434+ } => write ! ( f, "bound-method" ) ,
415435 & PyObjectKind :: Module { name : _, dict : _ } => write ! ( f, "module" ) ,
416436 & PyObjectKind :: Scope { scope : _ } => write ! ( f, "scope" ) ,
417437 & PyObjectKind :: None => write ! ( f, "None" ) ,
@@ -482,6 +502,7 @@ impl PyObject {
482502 PyObjectKind :: Instance { dict : _ } => format ! ( "<instance>" ) ,
483503 PyObjectKind :: Code { code : _ } => format ! ( "<code>" ) ,
484504 PyObjectKind :: Function { code : _, scope : _ } => format ! ( "<func>" ) ,
505+ PyObjectKind :: BoundMethod { .. } => format ! ( "<bound-method>" ) ,
485506 PyObjectKind :: RustFunction { function : _ } => format ! ( "<rustfunc>" ) ,
486507 PyObjectKind :: Module { ref name, dict : _ } => format ! ( "<module '{}'>" , name) ,
487508 PyObjectKind :: Scope { ref scope } => format ! ( "<scope '{:?}'>" , scope) ,
0 commit comments