86 char*
argv = (
char*)
"";
204 else {
WerrorS(
"Importing pyobject to Singular failed"); }
216 Werror(
"Cannot delete attribute %s.", arg.
repr());
241 WerrorS(
"pyobject error occurred");
263 case '<':
return Py_LT;
264 case '>':
return Py_GT;
302template <
class CastType = PythonObject::ptr_type>
324template <
class CastType>
329 for (
int idx = 0; idx < value->
length(); ++idx)
377template <
class CastType>
382 for (
int i = 0;
i <= value->
nr; ++
i)
435 WerrorS(
"expected python_eval('string')");
448 WerrorS(
"expected python_run('string')");
467 return python_eval(
"[str for str in dir(modules[SINGULAR_MODULE_NAME]) if str[0] != '_']");
482 WerrorS(
"expected python_import('string')");
539 WerrorS(
"'pyobject` cannot be converted to integer");
543 res->data = (
void*) value;
609 res->data = (
void *)a->blackbox_String(a, args->
Data());
616 unsigned long len =
obj.size();
619 for(
unsigned long idx = 0; idx != len; ++idx)
622 (*vec)[idx] =
static_cast<int>(value);
629 if (value !=
long((*
vec)[idx]))
632 WerrorS(
"'pyobject` cannot be converted to intvec");
667 for (_k, _e) in _SINGULAR_NEW.iteritems() \
668 if _k not in _SINGULAR_IMPORTED or not _SINGULAR_IMPORTED[_k] is _e]");
671 for (
long idx = 0; idx < len; ++idx)
685 python_eval(
"list(set(_SINGULAR_IMPORTED.iterkeys()) - \
686 set(_SINGULAR_NEW.iterkeys()))");
689 for (
long idx = 0; idx < len; ++idx)
713#define PYOBJECT_ADD_C_PROC(name) \
714 psModulFunctions->iiAddCproc((currPack->libname? currPack->libname: ""),\
715 (char*)#name, FALSE, name);
742#undef PYOBJECT_ADD_C_PROC
746 PrintS(
"no pyobject support\n");
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
BOOLEAN blackboxDefaultOp3(int, leftv, leftv, leftv, leftv)
default procedure blackboxDefaultOp3, to be called as "default:" branch
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
This class does conversion of Singular objects to python objects on runtime.
PythonObject get(leftv value, int typeId)
PythonCastDynamic(leftv value)
void append_to(leftv iter) const
size_t size(leftv iter, size_t distance=0) const
PythonCastStatic(leftv value)
This template class does conversion of Singular objects to python objects on compile-time.
ptr_type get(char *value)
ptr_type get(const char *value)
PythonCastStatic(leftv value)
PythonCastStatic(void *value)
ptr_type get(ptr_type value)
This class initializes and finalized the python interpreter.
void set_python_defaults()
PythonInterpreter()
Singleton: Only init() is allowed to construct an instance.
static id_type id()
Get Singular type identitfier.
static void init(id_type num)
Initialize unique (singleton) python interpreter instance, and set Singular type identifier.
static PythonInterpreter & instance()
Static initialization - safely takes care of destruction on program termination.
This class defines an interface for calling PyObject from Singular.
self attr(const self &arg) const
int py_opid(int op) const
void import_as(const char *name) const
ptr_type check_context(ptr_type ptr) const
BOOLEAN none_to(leftv result) const
self args2list(const self &args) const
self operator()(int op) const
Unary operations.
void append_iter(self iterator)
self operator[](long idx) const
char * str() const
Extract C-style string.
PythonObject(ptr_type ptr)
BOOLEAN python_to(leftv result) const
self operator()(int op, const self &arg1, const self &arg2) const
Ternary operations.
self del_attr(const self &arg) const
self operator()(int op, const self &arg) const
Binary and n-ary operations.
char * repr() const
Get representative as C-style string.
self operator[](const self &idx) const
Get item.
BOOLEAN assign_to(leftv result)
BOOLEAN handle_exception() const
ptr_type m_ptr
The actual pointer.
int compare(int op, const self &arg) const
Class used for (list of) interpreter objects.
void WerrorS(const char *s)
char * feGetResource(const char id, int warn)
const char * iiTwoOps(int t)
void killid(const char *id, idhdl *ih)
idhdl ggetid(const char *n)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
BOOLEAN newstruct_Op2(int op, leftv res, leftv a1, leftv a2)
BOOLEAN newstruct_Assign_user(int op, leftv l, leftv r)
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
BOOLEAN newstruct_OpM(int op, leftv res, leftv args)
int newstruct_desc_size()
BOOLEAN python_import(leftv result, leftv value)
import python module and export identifiers in Singular namespace
int SI_MOD_INIT pyobject(SModulFunctions *psModulFunctions)
void * pyobject_Init(blackbox *)
blackbox support - initialization
BOOLEAN pyobject_OpM(int op, leftv res, leftv args)
blackbox support - n-ary operations
BOOLEAN pyobject_Assign(leftv l, leftv r)
blackbox support - assign element
PythonObject get_attrib_name(leftv arg)
#define PYOBJECT_ADD_C_PROC(name)
PyObject * get_current_definition(const char *name)
BOOLEAN python_run(leftv result, leftv arg)
Execute string in python from Singular.
PythonObject python_eval(const char *arg)
Evaluate string in python.
PythonObject names_from_module(const char *module_name)
void pyobject_destroy(blackbox *, void *ptr)
blackbox support - destruction
BOOLEAN pyobject_Op1(int op, leftv res, leftv head)
blackbox support - unary operations
void sync_contexts()
getting stuff from python to Singular namespace
void from_module_import_all(const char *module_name)
blackbox * pyobject_blackbox(int &tok)
BOOLEAN pyobject_Op2(int op, leftv res, leftv arg1, leftv arg2)
blackbox support - binary operations
char * pyobject_String(blackbox *, void *ptr)
blackbox support - convert to string representation
BOOLEAN pyobject_Op3(int op, leftv res, leftv arg1, leftv arg2, leftv arg3)
blackbox support - ternary operations
void * pyobject_Copy(blackbox *, void *ptr)
blackbox support - copy element
void PrintS(const char *s)
void Werror(const char *fmt,...)
int name
New type name for int.