 |
My Project
UNKNOWN_GIT_VERSION
|
Go to the source code of this file.
|
void | sync_contexts () |
| getting stuff from python to Singular namespace More...
|
|
PythonObject | get_attrib_name (leftv arg) |
|
PythonObject | python_eval (const char *arg) |
| Evaluate string in python. More...
|
|
BOOLEAN | python_eval (leftv result, leftv arg) |
| Evaluate string in python from Singular. More...
|
|
BOOLEAN | python_run (leftv result, leftv arg) |
| Execute string in python from Singular. More...
|
|
PythonObject | names_from_module (const char *module_name) |
|
void | from_module_import_all (const char *module_name) |
|
BOOLEAN | python_import (leftv result, leftv value) |
| import python module and export identifiers in Singular namespace More...
|
|
void * | pyobject_Init (blackbox *) |
| blackbox support - initialization More...
|
|
char * | pyobject_String (blackbox *, void *ptr) |
| blackbox support - convert to string representation More...
|
|
void * | pyobject_Copy (blackbox *, void *ptr) |
| blackbox support - copy element More...
|
|
BOOLEAN | pyobject_Assign (leftv l, leftv r) |
| blackbox support - assign element More...
|
|
BOOLEAN | pyobject_Op1 (int op, leftv res, leftv head) |
| blackbox support - unary operations More...
|
|
BOOLEAN | pyobject_Op2 (int op, leftv res, leftv arg1, leftv arg2) |
| blackbox support - binary operations More...
|
|
BOOLEAN | pyobject_Op3 (int op, leftv res, leftv arg1, leftv arg2, leftv arg3) |
| blackbox support - ternary operations More...
|
|
BOOLEAN | pyobject_OpM (int op, leftv res, leftv args) |
| blackbox support - n-ary operations More...
|
|
void | pyobject_destroy (blackbox *, void *ptr) |
| blackbox support - destruction More...
|
|
PyObject * | get_current_definition (const char *name) |
|
blackbox * | pyobject_blackbox (int &tok) |
|
int SI_MOD_INIT() | pyobject (SModulFunctions *psModulFunctions) |
|
- Author
- Alexander Dreyer
- Date
- 2010-12-15
This file defines the blackbox
operations for the pyobject type.
- Copyright:
- (c) 2010 by The Singular Team, see LICENSE file
Definition in file pyobject.cc.
◆ PythonObject::sequence_tag
struct PythonObject::sequence_tag |
◆ PYOBJECT_ADD_C_PROC
#define PYOBJECT_ADD_C_PROC |
( |
|
name | ) |
|
◆ from_module_import_all()
void from_module_import_all |
( |
const char * |
module_name | ) |
|
Definition at line 470 of file pyobject.cc.
472 char buffer[strlen(module_name) + 20];
473 sprintf (buffer,
"from %s import *", module_name);
474 PyRun_SimpleString(buffer);
◆ get_attrib_name()
Definition at line 414 of file pyobject.cc.
418 return result_type(arg);
420 return result_type((
void*)arg->
Name());
◆ get_current_definition()
PyObject* get_current_definition |
( |
const char * |
name | ) |
|
◆ names_from_module()
Definition at line 459 of file pyobject.cc.
461 char buffer[strlen(module_name) + 30];
462 sprintf (buffer,
"SINGULAR_MODULE_NAME = '%s'", module_name);
463 PyRun_SimpleString(buffer);
464 PyRun_SimpleString(
"from sys import modules");
465 PyRun_SimpleString(
"exec('from ' + SINGULAR_MODULE_NAME + ' import *')");
467 return python_eval(
"[str for str in dir(modules[SINGULAR_MODULE_NAME]) if str[0] != '_']");
◆ pyobject()
◆ pyobject_Assign()
blackbox support - assign element
Definition at line 514 of file pyobject.cc.
516 Py_XDECREF(
l->Data());
◆ pyobject_blackbox()
blackbox* pyobject_blackbox |
( |
int & |
tok | ) |
|
◆ pyobject_Copy()
void* pyobject_Copy |
( |
blackbox * |
, |
|
|
void * |
ptr |
|
) |
| |
blackbox support - copy element
Definition at line 507 of file pyobject.cc.
◆ pyobject_destroy()
void pyobject_destroy |
( |
blackbox * |
, |
|
|
void * |
ptr |
|
) |
| |
blackbox support - destruction
Definition at line 649 of file pyobject.cc.
◆ pyobject_Init()
void* pyobject_Init |
( |
blackbox * |
| ) |
|
blackbox support - initialization
Definition at line 494 of file pyobject.cc.
◆ pyobject_Op1()
blackbox support - unary operations
Definition at line 530 of file pyobject.cc.
537 if( (value == -1) && PyErr_Occurred() )
539 WerrorS(
"'pyobject` cannot be converted to integer");
543 res->data = (
void*) value;
◆ pyobject_Op2()
blackbox support - binary operations
Definition at line 562 of file pyobject.cc.
579 if (!lhs(op, rhs).assign_to(
res))
◆ pyobject_Op3()
blackbox support - ternary operations
Definition at line 588 of file pyobject.cc.
594 if (!lhs(op, rhs1, rhs2).assign_to(
res))
◆ pyobject_OpM()
blackbox support - n-ary operations
Definition at line 602 of file pyobject.cc.
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)
621 long value = PyInt_AsLong(obj[idx]);
622 (*vec)[idx] =
static_cast<int>(value);
624 if ((value == -1) && PyErr_Occurred())
629 if (value !=
long((*
vec)[idx]))
632 WerrorS(
"'pyobject` cannot be converted to intvec");
◆ pyobject_String()
char* pyobject_String |
( |
blackbox * |
, |
|
|
void * |
ptr |
|
) |
| |
blackbox support - convert to string representation
Definition at line 501 of file pyobject.cc.
◆ python_eval() [1/2]
Evaluate string in python.
Definition at line 424 of file pyobject.cc.
426 PyObject* globals = PyModule_GetDict(PyImport_Import(PyString_FromString(
"__main__")));
427 return PyRun_String(arg, Py_eval_input, globals, globals);
◆ python_eval() [2/2]
Evaluate string in python from Singular.
Definition at line 431 of file pyobject.cc.
435 WerrorS(
"expected python_eval('string')");
◆ python_import()
import python module and export identifiers in Singular namespace
Definition at line 478 of file pyobject.cc.
482 WerrorS(
"expected python_import('string')");
◆ python_run()
Execute string in python from Singular.
Definition at line 444 of file pyobject.cc.
448 WerrorS(
"expected python_run('string')");
452 PyRun_SimpleString(
reinterpret_cast<const char*
>(arg->
Data()));
◆ sync_contexts()
getting stuff from python to Singular namespace
Definition at line 662 of file pyobject.cc.
664 PyRun_SimpleString(
"_SINGULAR_NEW = modules['__main__'].__dict__.copy()");
667 for (_k, _e) in _SINGULAR_NEW.iteritems() \
668 if _k not in _SINGULAR_IMPORTED or not _SINGULAR_IMPORTED[_k] is _e]");
670 long len = newElts.
size();
671 for (
long idx = 0; idx < len; ++idx)
685 python_eval(
"list(set(_SINGULAR_IMPORTED.iterkeys()) - \
686 set(_SINGULAR_NEW.iterkeys()))");
687 len = deletedElts.
size();
689 for (
long idx = 0; idx < len; ++idx)
691 char*
name = deletedElts[idx].
str();
696 PyRun_SimpleString(
"_SINGULAR_IMPORTED =_SINGULAR_NEW");
697 PyRun_SimpleString(
"del _SINGULAR_NEW");
PythonObject get_attrib_name(leftv arg)
Template specialization for getting handling sequence.
BOOLEAN pyobject_Op3(int op, leftv res, leftv arg1, leftv arg2, leftv arg3)
blackbox support - ternary operations
int newstruct_desc_size()
char * repr() const
Get representative as C-style string.
void killid(const char *id, idhdl *ih)
This template class does conversion of Singular objects to python objects on compile-time.
void import_as(const char *name) const
Class used for (list of) interpreter objects.
BOOLEAN python_import(leftv result, leftv value)
import python module and export identifiers in Singular namespace
BOOLEAN pyobject_Op1(int op, leftv res, leftv head)
blackbox support - unary operations
static void init(id_type num)
Initialize unique (singleton) python interpreter instance, and set Singular type identifier.
void sync_contexts()
getting stuff from python to Singular namespace
BOOLEAN blackboxDefaultOp3(int, leftv, leftv, leftv, leftv)
default procedure blackboxDefaultOp3, to be called as "default:" branch
This class does conversion of Singular objects to python objects on runtime.
BOOLEAN pyobject_Assign(leftv l, leftv r)
blackbox support - assign element
void * pyobject_Init(blackbox *)
blackbox support - initialization
#define PYOBJECT_ADD_C_PROC(name)
BOOLEAN newstruct_Op1(int op, leftv res, leftv arg)
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
PythonObject python_eval(const char *arg)
Evaluate string in python.
void from_module_import_all(const char *module_name)
BOOLEAN python_run(leftv result, leftv arg)
Execute string in python from Singular.
void pyobject_destroy(blackbox *, void *ptr)
blackbox support - destruction
char * pyobject_String(blackbox *, void *ptr)
blackbox support - convert to string representation
char * str() const
Extract C-style string.
BOOLEAN newstruct_OpM(int op, leftv res, leftv args)
static id_type id()
Get Singular type identitfier.
char name(const Variable &v)
void WerrorS(const char *s)
BOOLEAN newstruct_Op2(int op, leftv res, leftv a1, leftv a2)
idhdl ggetid(const char *n)
BOOLEAN pyobject_Op2(int op, leftv res, leftv arg1, leftv arg2)
blackbox support - binary operations
blackbox * pyobject_blackbox(int &tok)
PyObject * get_current_definition(const char *name)
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
This class defines an interface for calling PyObject from Singular.
BOOLEAN assign_to(leftv result)
void * pyobject_Copy(blackbox *, void *ptr)
blackbox support - copy element
BOOLEAN pyobject_OpM(int op, leftv res, leftv args)
blackbox support - n-ary operations
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type