[][src]Struct rustpython_vm::VirtualMachine

pub struct VirtualMachine {
    pub builtins: PyObjectRef,
    pub sys_module: PyObjectRef,
    pub stdlib_inits: RefCell<HashMap<String, StdlibInitFunc>>,
    pub ctx: PyContext,
    pub frames: RefCell<Vec<PyRef<Frame>>>,
    pub wasm_id: Option<String>,
    pub exceptions: RefCell<Vec<PyObjectRef>>,
    pub frozen: RefCell<HashMap<String, FrozenModule>>,
    pub import_func: RefCell<PyObjectRef>,
    pub profile_func: RefCell<PyObjectRef>,
    pub trace_func: RefCell<PyObjectRef>,
    pub use_tracing: RefCell<bool>,
    pub signal_handlers: RefCell<[PyObjectRef; 64]>,
    pub settings: PySettings,
}

Top level container of a python virtual machine. In theory you could create more instances of this struct and have them operate fully isolated.

Fields

builtins: PyObjectRefsys_module: PyObjectRefstdlib_inits: RefCell<HashMap<String, StdlibInitFunc>>ctx: PyContextframes: RefCell<Vec<PyRef<Frame>>>wasm_id: Option<String>exceptions: RefCell<Vec<PyObjectRef>>frozen: RefCell<HashMap<String, FrozenModule>>import_func: RefCell<PyObjectRef>profile_func: RefCell<PyObjectRef>trace_func: RefCell<PyObjectRef>use_tracing: RefCell<bool>signal_handlers: RefCell<[PyObjectRef; 64]>settings: PySettings

Methods

impl VirtualMachine[src]

pub fn new(settings: PySettings) -> VirtualMachine[src]

Create a new VirtualMachine structure.

pub fn run_code_obj(&self, code: PyCodeRef, scope: Scope) -> PyResult[src]

pub fn run_frame_full(&self, frame: PyRef<Frame>) -> PyResult[src]

pub fn run_frame(&self, frame: PyRef<Frame>) -> PyResult<ExecutionResult>[src]

pub fn frame_throw(
    &self,
    frame: PyRef<Frame>,
    exception: PyObjectRef
) -> PyResult<ExecutionResult>
[src]

pub fn current_frame(&self) -> Option<Ref<PyRef<Frame>>>[src]

pub fn current_scope(&self) -> Ref<Scope>[src]

pub fn try_class(&self, module: &str, class: &str) -> PyResult<PyClassRef>[src]

pub fn class(&self, module: &str, class: &str) -> PyClassRef[src]

pub fn new_str(&self, s: String) -> PyObjectRef[src]

Create a new python string object.

pub fn new_int<T: Into<BigInt>>(&self, i: T) -> PyObjectRef[src]

Create a new python int object.

pub fn new_bool(&self, b: bool) -> PyObjectRef[src]

Create a new python bool object.

pub fn new_module(&self, name: &str, dict: PyDictRef) -> PyObjectRef[src]

pub fn new_empty_exception(&self, exc_type: PyClassRef) -> PyResult[src]

pub fn new_exception(&self, exc_type: PyClassRef, msg: String) -> PyObjectRef[src]

Create Python instance of exc_type with message as first element of args tuple

pub fn new_lookup_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_attribute_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_type_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_name_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_unsupported_operand_error(
    &self,
    a: PyObjectRef,
    b: PyObjectRef,
    op: &str
) -> PyObjectRef
[src]

pub fn new_os_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_unicode_decode_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_value_error(&self, msg: String) -> PyObjectRef[src]

Create a new python ValueError object. Useful for raising errors from python functions implemented in rust.

pub fn new_key_error(&self, obj: PyObjectRef) -> PyObjectRef[src]

pub fn new_index_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_not_implemented_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_zero_division_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_overflow_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_syntax_error(&self, error: &CompileError) -> PyObjectRef[src]

pub fn new_import_error(&self, msg: String) -> PyObjectRef[src]

pub fn new_scope_with_builtins(&self) -> Scope[src]

pub fn get_none(&self) -> PyObjectRef[src]

pub fn is_none(&self, obj: &PyObjectRef) -> bool[src]

Test whether a python object is None.

pub fn get_type(&self) -> PyClassRef[src]

pub fn get_object(&self) -> PyClassRef[src]

pub fn get_locals(&self) -> PyDictRef[src]

pub fn context(&self) -> &PyContext[src]

pub fn to_str(&self, obj: &PyObjectRef) -> PyResult<PyStringRef>[src]

pub fn to_pystr<'a, T: Into<&'a PyObjectRef>>(
    &'a self,
    obj: T
) -> Result<String, PyObjectRef>
[src]

pub fn to_repr(&self, obj: &PyObjectRef) -> PyResult<PyStringRef>[src]

pub fn to_ascii(&self, obj: &PyObjectRef) -> PyResult[src]

pub fn import(
    &self,
    module: &str,
    from_list: &[String],
    level: usize
) -> PyResult
[src]

pub fn isinstance(&self, obj: &PyObjectRef, cls: &PyClassRef) -> PyResult<bool>[src]

Determines if obj is an instance of cls, either directly, indirectly or virtually via the instancecheck magic method.

pub fn issubclass(
    &self,
    subclass: &PyClassRef,
    cls: &PyClassRef
) -> PyResult<bool>
[src]

Determines if subclass is a subclass of cls, either directly, indirectly or virtually via the subclasscheck magic method.

pub fn call_get_descriptor(
    &self,
    attr: PyObjectRef,
    obj: PyObjectRef
) -> PyResult
[src]

pub fn call_method<T>(
    &self,
    obj: &PyObjectRef,
    method_name: &str,
    args: T
) -> PyResult where
    T: Into<PyFuncArgs>, 
[src]

pub fn invoke<T>(&self, func_ref: &PyObjectRef, args: T) -> PyResult where
    T: Into<PyFuncArgs>, 
[src]

pub fn invoke_with_locals(
    &self,
    function: &PyObjectRef,
    cells: PyDictRef,
    locals: PyDictRef
) -> PyResult
[src]

pub fn extract_elements(
    &self,
    value: &PyObjectRef
) -> PyResult<Vec<PyObjectRef>>
[src]

pub fn get_attribute<T>(&self, obj: PyObjectRef, attr_name: T) -> PyResult where
    T: TryIntoRef<PyString>, 
[src]

pub fn set_attr<K, V>(
    &self,
    obj: &PyObjectRef,
    attr_name: K,
    attr_value: V
) -> PyResult where
    K: TryIntoRef<PyString>,
    V: Into<PyObjectRef>, 
[src]

pub fn del_attr(
    &self,
    obj: &PyObjectRef,
    attr_name: PyObjectRef
) -> PyResult<()>
[src]

pub fn get_method_or_type_error<F>(
    &self,
    obj: PyObjectRef,
    method_name: &str,
    err_msg: F
) -> PyResult where
    F: FnOnce() -> String
[src]

pub fn get_method(
    &self,
    obj: PyObjectRef,
    method_name: &str
) -> Option<PyResult>
[src]

May return exception, if __get__ descriptor raises one

pub fn call_or_unsupported<F>(
    &self,
    obj: PyObjectRef,
    arg: PyObjectRef,
    method: &str,
    unsupported: F
) -> PyResult where
    F: Fn(&VirtualMachine, PyObjectRef, PyObjectRef) -> PyResult
[src]

Calls a method on obj passing arg, if the method exists.

Otherwise, or if the result is the special NotImplemented built-in constant, calls unsupported to determine fallback value.

pub fn call_or_reflection(
    &self,
    lhs: PyObjectRef,
    rhs: PyObjectRef,
    default: &str,
    reflection: &str,
    unsupported: fn(_: &VirtualMachine, _: PyObjectRef, _: PyObjectRef) -> PyResult
) -> PyResult
[src]

Calls a method, falling back to its reflection with the operands reversed, and then to the value provided by unsupported.

For example: the following:

call_or_reflection(lhs, rhs, "__and__", "__rand__", unsupported)

  1. Calls __and__ with lhs and rhs.
  2. If above is not implemented, calls __rand__ with rhs and lhs.
  3. If above is not implemented, invokes unsupported for the result.

pub fn generic_getattribute(
    &self,
    obj: PyObjectRef,
    name_str: PyStringRef
) -> PyResult<Option<PyObjectRef>>
[src]

pub fn is_callable(&self, obj: &PyObjectRef) -> bool[src]

pub fn compile(
    &self,
    source: &str,
    mode: Mode,
    source_path: String
) -> Result<PyCodeRef, CompileError>
[src]

pub fn _sub(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _isub(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _add(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _iadd(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _mul(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _imul(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _matmul(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _imatmul(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _truediv(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _itruediv(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _floordiv(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ifloordiv(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _pow(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ipow(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _mod(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _imod(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _lshift(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ilshift(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _rshift(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _irshift(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _xor(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ixor(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _or(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ior(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _and(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _iand(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _eq(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ne(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _lt(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _le(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _gt(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _ge(&self, a: PyObjectRef, b: PyObjectRef) -> PyResult[src]

pub fn _hash(&self, obj: &PyObjectRef) -> PyResult<i64>[src]

pub fn _membership(
    &self,
    haystack: PyObjectRef,
    needle: PyObjectRef
) -> PyResult
[src]

pub fn push_exception(&self, exc: PyObjectRef)[src]

pub fn pop_exception(&self) -> Option<PyObjectRef>[src]

pub fn current_exception(&self) -> Option<PyObjectRef>[src]

Trait Implementations

impl Default for VirtualMachine[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self