mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
Create PythonTuple and PythonCallable wrapper classes.
This adds PythonTuple and PythonCallable classes to PythonDataObjects. Additionally, unit tests are provided that exercise this functionality, including invoking manipulating and checking for validity of tuples, and invoking and checking for validity of callables using a variety of different syntaxes. The goal here is to eventually replace the code in python-wrapper.swig that directly uses the Python C API to deal with callables and name resolution with this code that can be more easily tested and debugged. llvm-svn: 252787
This commit is contained in:
1 parent
51c402838c
commit
a140514733
3 files changed
+454
-17
No files matched your search
@@ -70,6 +70,8 @@ enum class PyObjectType
|
||||
List,
|
||||
String,
|
||||
Module,
|
||||
Callable,
|
||||
Tuple,
|
||||
File
|
||||
};
|
||||
|
||||
@@ -203,7 +205,7 @@ public:
|
||||
Str() const;
|
||||
|
||||
static PythonObject
|
||||
ResolveNameGlobal(llvm::StringRef name);
|
||||
ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict);
|
||||
|
||||
PythonObject
|
||||
ResolveName(llvm::StringRef name) const;
|
||||
@@ -295,6 +297,7 @@ public:
|
||||
class PythonList : public PythonObject
|
||||
{
|
||||
public:
|
||||
PythonList() {}
|
||||
explicit PythonList(PyInitialValue value);
|
||||
explicit PythonList(int list_size);
|
||||
PythonList(PyRefType type, PyObject *o);
|
||||
@@ -320,9 +323,39 @@ public:
|
||||
StructuredData::ArraySP CreateStructuredArray() const;
|
||||
};
|
||||
|
||||
class PythonTuple : public PythonObject
|
||||
{
|
||||
public:
|
||||
PythonTuple() {}
|
||||
explicit PythonTuple(PyInitialValue value);
|
||||
explicit PythonTuple(int tuple_size);
|
||||
PythonTuple(PyRefType type, PyObject *o);
|
||||
PythonTuple(const PythonTuple &tuple);
|
||||
PythonTuple(std::initializer_list<PythonObject> objects);
|
||||
PythonTuple(std::initializer_list<PyObject*> objects);
|
||||
|
||||
~PythonTuple() override;
|
||||
|
||||
static bool Check(PyObject *py_obj);
|
||||
|
||||
// Bring in the no-argument base class version
|
||||
using PythonObject::Reset;
|
||||
|
||||
void Reset(PyRefType type, PyObject *py_obj) override;
|
||||
|
||||
uint32_t GetSize() const;
|
||||
|
||||
PythonObject GetItemAtIndex(uint32_t index) const;
|
||||
|
||||
void SetItemAtIndex(uint32_t index, const PythonObject &object);
|
||||
|
||||
StructuredData::ArraySP CreateStructuredArray() const;
|
||||
};
|
||||
|
||||
class PythonDictionary : public PythonObject
|
||||
{
|
||||
public:
|
||||
PythonDictionary() {}
|
||||
explicit PythonDictionary(PyInitialValue value);
|
||||
PythonDictionary(PyRefType type, PyObject *o);
|
||||
PythonDictionary(const PythonDictionary &dict);
|
||||
@@ -357,7 +390,14 @@ class PythonModule : public PythonObject
|
||||
|
||||
static bool Check(PyObject *py_obj);
|
||||
|
||||
static PythonModule MainModule();
|
||||
static PythonModule
|
||||
BuiltinsModule();
|
||||
|
||||
static PythonModule
|
||||
MainModule();
|
||||
|
||||
static PythonModule
|
||||
AddModule(llvm::StringRef module);
|
||||
|
||||
// Bring in the no-argument base class version
|
||||
using PythonObject::Reset;
|
||||
@@ -367,6 +407,35 @@ class PythonModule : public PythonObject
|
||||
PythonDictionary GetDictionary() const;
|
||||
};
|
||||
|
||||
class PythonCallable : public PythonObject
|
||||
{
|
||||
public:
|
||||
PythonCallable();
|
||||
PythonCallable(PyRefType type, PyObject *o);
|
||||
PythonCallable(const PythonCallable &dict);
|
||||
|
||||
~PythonCallable() override;
|
||||
|
||||
static bool
|
||||
Check(PyObject *py_obj);
|
||||
|
||||
// Bring in the no-argument base class version
|
||||
using PythonObject::Reset;
|
||||
|
||||
void
|
||||
Reset(PyRefType type, PyObject *py_obj) override;
|
||||
|
||||
void
|
||||
GetNumArguments(size_t &num_args, bool &has_varargs, bool &has_kwargs) const;
|
||||
|
||||
PythonObject
|
||||
operator ()(std::initializer_list<PyObject*> args);
|
||||
|
||||
PythonObject
|
||||
operator ()(std::initializer_list<PythonObject> args);
|
||||
};
|
||||
|
||||
|
||||
class PythonFile : public PythonObject
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in new issue
Block a user