[][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<PyBaseExceptionRef>>,
    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,
    pub recursion_limit: Cell<usize>,
    pub codec_registry: RefCell<Vec<PyObjectRef>>,
    pub initialized: bool,
}

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<PyBaseExceptionRef>>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: PySettingsrecursion_limit: Cell<usize>codec_registry: RefCell<Vec<PyObjectRef>>initialized: bool

Methods

impl VirtualMachine[src]

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

Create a new VirtualMachine structure.

pub fn initialize(&mut self, initialize_parameter: InitParameter)[src]

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 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> + ToPrimitive>(&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_exception(
    &self,
    exc_type: PyClassRef,
    args: Vec<PyObjectRef>
) -> PyBaseExceptionRef
[src]

Instantiate an exception with arguments. This function should only be used with builtin exception types; if a user-defined exception type is passed in, it may not be fully initialized; try using exceptions::invoke or exceptions::ExceptionCtor instead.

pub fn new_exception_empty(&self, exc_type: PyClassRef) -> PyBaseExceptionRef[src]

Instantiate an exception with no arguments. This function should only be used with builtin exception types; if a user-defined exception type is passed in, it may not be fully initialized; try using exceptions::invoke or exceptions::ExceptionCtor instead.

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

Instantiate an exception with msg as the only argument. This function should only be used with builtin exception types; if a user-defined exception type is passed in, it may not be fully initialized; try using exceptions::invoke or exceptions::ExceptionCtor instead.

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

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

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

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

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

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

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

pub fn new_unicode_encode_error(&self, msg: String) -> PyBaseExceptionRef[src]

pub fn new_value_error(&self, msg: String) -> PyBaseExceptionRef[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) -> PyBaseExceptionRef[src]

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

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

pub fn new_recursion_error(&self, msg: String) -> PyBaseExceptionRef[src]

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

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

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

pub fn new_import_error(&self, msg: String) -> PyBaseExceptionRef[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
) -> PyResult<String>
[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,
    descr: PyObjectRef,
    obj: PyObjectRef
) -> Option<PyResult>
[src]

pub fn call_if_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 extract_elements<T: TryFromObject>(
    &self,
    value: &PyObjectRef
) -> PyResult<Vec<T>>
[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]

CPython _PyObject_GenericGetAttrWithDict

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

pub fn check_signals(&self) -> PyResult<()>[src]

Checks for triggered signals and calls the appropriate handlers. A no-op on platforms where signals are not supported.

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

pub fn decode(
    &self,
    obj: PyObjectRef,
    encoding: Option<PyStringRef>,
    errors: Option<PyStringRef>
) -> PyResult
[src]

pub fn encode(
    &self,
    obj: PyObjectRef,
    encoding: Option<PyStringRef>,
    errors: Option<PyStringRef>
) -> PyResult
[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: PyBaseExceptionRef)[src]

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

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

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

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

pub fn bool_seq_lt(
    &self,
    a: PyObjectRef,
    b: PyObjectRef
) -> PyResult<Option<bool>>
[src]

pub fn bool_seq_gt(
    &self,
    a: PyObjectRef,
    b: PyObjectRef
) -> PyResult<Option<bool>>
[src]

Trait Implementations

impl Default for VirtualMachine[src]

impl<F, R> IntoPyNativeFunc<(), R, VirtualMachine> for F where
    F: Fn(&VirtualMachine) -> R + 'static,
    R: IntoPyObject
[src]

impl<F, A, B, C, D, E, R> IntoPyNativeFunc<(OwnedParam<A>, OwnedParam<B>, OwnedParam<C>, OwnedParam<D>, OwnedParam<E>), R, VirtualMachine> for F where
    F: Fn(A, B, C, D, E, &VirtualMachine) -> R + 'static,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    D: FromArgs,
    E: FromArgs,
    R: IntoPyObject
[src]

impl<F, A, B, C, D, R> IntoPyNativeFunc<(OwnedParam<A>, OwnedParam<B>, OwnedParam<C>, OwnedParam<D>), R, VirtualMachine> for F where
    F: Fn(A, B, C, D, &VirtualMachine) -> R + 'static,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    D: FromArgs,
    R: IntoPyObject
[src]

impl<F, A, B, C, R> IntoPyNativeFunc<(OwnedParam<A>, OwnedParam<B>, OwnedParam<C>), R, VirtualMachine> for F where
    F: Fn(A, B, C, &VirtualMachine) -> R + 'static,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    R: IntoPyObject
[src]

impl<F, A, B, R> IntoPyNativeFunc<(OwnedParam<A>, OwnedParam<B>), R, VirtualMachine> for F where
    F: Fn(A, B, &VirtualMachine) -> R + 'static,
    A: FromArgs,
    B: FromArgs,
    R: IntoPyObject
[src]

impl<F, A, R> IntoPyNativeFunc<(OwnedParam<A>,), R, VirtualMachine> for F where
    F: Fn(A, &VirtualMachine) -> R + 'static,
    A: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, A, B, C, D, E, R> IntoPyNativeFunc<(RefParam<S>, OwnedParam<A>, OwnedParam<B>, OwnedParam<C>, OwnedParam<D>, OwnedParam<E>), R, VirtualMachine> for F where
    F: Fn(&S, A, B, C, D, E, &VirtualMachine) -> R + 'static,
    S: PyValue,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    D: FromArgs,
    E: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, A, B, C, D, R> IntoPyNativeFunc<(RefParam<S>, OwnedParam<A>, OwnedParam<B>, OwnedParam<C>, OwnedParam<D>), R, VirtualMachine> for F where
    F: Fn(&S, A, B, C, D, &VirtualMachine) -> R + 'static,
    S: PyValue,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    D: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, A, B, C, R> IntoPyNativeFunc<(RefParam<S>, OwnedParam<A>, OwnedParam<B>, OwnedParam<C>), R, VirtualMachine> for F where
    F: Fn(&S, A, B, C, &VirtualMachine) -> R + 'static,
    S: PyValue,
    A: FromArgs,
    B: FromArgs,
    C: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, A, B, R> IntoPyNativeFunc<(RefParam<S>, OwnedParam<A>, OwnedParam<B>), R, VirtualMachine> for F where
    F: Fn(&S, A, B, &VirtualMachine) -> R + 'static,
    S: PyValue,
    A: FromArgs,
    B: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, A, R> IntoPyNativeFunc<(RefParam<S>, OwnedParam<A>), R, VirtualMachine> for F where
    F: Fn(&S, A, &VirtualMachine) -> R + 'static,
    S: PyValue,
    A: FromArgs,
    R: IntoPyObject
[src]

impl<F, S, R> IntoPyNativeFunc<(RefParam<S>,), R, VirtualMachine> for F where
    F: Fn(&S, &VirtualMachine) -> R + 'static,
    S: PyValue,
    R: IntoPyObject
[src]

impl<F> IntoPyNativeFunc<PyFuncArgs, Result<Rc<PyObject<dyn PyObjectPayload + 'static>>, PyRef<PyBaseException>>, VirtualMachine> for F where
    F: Fn(&VirtualMachine, PyFuncArgs) -> PyResult + 'static, 
[src]

Auto Trait Implementations

impl !RefUnwindSafe for VirtualMachine

impl !Send for VirtualMachine

impl !Sync for VirtualMachine

impl Unpin for VirtualMachine

impl !UnwindSafe for VirtualMachine

Blanket Implementations

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

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

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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<V, T> VZip<V> for T where
    V: MultiLane<T>,