[−][src]Struct rosy::vm::InstrSeq
An instance of Ruby's RubyVM::InstructionSequence
class.
Note: The binary data that comes from an instruction sequence is not portable and should not be used in another version or architecture of Ruby.
Methods
impl InstrSeq
[src]
pub fn compile(script: impl Into<String>) -> Result<Self>
[src]
Compiles script
into an instruction sequence.
pub fn compile_with(
script: impl Into<String>,
options: impl Into<Hash>
) -> Result<Self>
[src]
script: impl Into<String>,
options: impl Into<Hash>
) -> Result<Self>
Compiles script
with options
into an instruction sequence.
pub fn compile_file(path: impl Into<String>) -> Result<Self>
[src]
Compiles the contents of a file at path
into an instruction sequence.
pub fn compile_file_with(
path: impl Into<String>,
options: impl Into<Hash>
) -> Result<Self>
[src]
path: impl Into<String>,
options: impl Into<Hash>
) -> Result<Self>
Compiles the contents of a file at path
with `options into an
instruction sequence.
pub unsafe fn from_binary(binary: impl Into<String>) -> Self
[src]
Loads an instruction sequence from a binary formatted string created by
to_binary
.
Safety
This loader does not have a verifier, so loading broken/modified binary causes critical problems.
Examples
This is equivalent to calling
RubyVM::InstructionSequence.load_from_binary
:
use rosy::{vm::InstrSeq, String}; let script = "'hi' * 3"; let seq1 = InstrSeq::compile(script).expect("Invalid script"); let seq2 = unsafe { InstrSeq::from_binary(seq1.to_binary()) }; assert_eq!(String::from("hihihi"), unsafe { seq2.eval() });
pub unsafe fn eval(self) -> AnyObject
[src]
Evaluates self
and returns the result.
Safety
Code executed from self
may void the type safety of objects accessible
from Rust. For example, if one calls push
on an Array<A>
with an
object of type B
, then the inserted object will be treated as being of
type A
.
If this instruction sequence throws an exception, it must be caught.
pub fn eval_protected(self) -> Result<AnyObject>
[src]
Evaluates self
and returns the result.
Safety
Code executed from self
may void the type safety of objects accessible
from Rust. For example, if one calls push
on an Array<A>
with an
object of type B
, then the inserted object will be treated as being of
type A
.
Examples
This is equivalent to calling eval
in a protected context:
use rosy::{vm::InstrSeq, String}; let script = "'hi' * 3"; let instr_seq = InstrSeq::compile(script).expect("Invalid script"); let output = unsafe { instr_seq.eval_protected().unwrap() }; assert_eq!(String::from("hihihi"), output);
pub fn to_binary(self) -> String
[src]
Returns the serialized binary data.
pub fn write_binary(self, w: impl Write) -> Result<()>
[src]
Writes the serialized binary data of self
to w
.
This makes it easy to write the contents of self
to a
File
or any other
common I/O type.
pub fn disassemble(self) -> String
[src]
Returns a human-readable form of self
.
pub fn path(self) -> String
[src]
Returns the file path of self
, or <compiled>
if it was compiled from
a string.
pub fn absolute_path(self) -> Option<String>
[src]
Returns the absolute path of self
if it was compiled from a file.
Trait Implementations
impl Classify for InstrSeq
[src]
impl Object for InstrSeq
[src]
fn unique_id() -> Option<u128>
[src]
fn cast<A: Object>(obj: A) -> Option<Self>
[src]
unsafe fn from_raw(raw: usize) -> Self
[src]
Creates a new object from raw
without checking. Read more
unsafe fn cast_unchecked(obj: impl Object) -> Self
[src]
Casts obj
to Self
without checking its type.
fn into_any_object(self) -> AnyObject
[src]
Returns self
as an AnyObject
.
fn as_any_object(&self) -> &AnyObject
[src]
Returns a reference to self
as an AnyObject
.
fn as_any_slice(&self) -> &[AnyObject]
[src]
Returns self
as a reference to a single-element slice.
fn raw(self) -> usize
[src]
Returns the raw object pointer.
unsafe fn as_unchecked<O: Object>(&self) -> &O
[src]
Casts self
to O
without checking whether it is one.
unsafe fn into_unchecked<O: Object>(self) -> O
[src]
Converts self
to O
without checking whether it is one.
fn id(self) -> u64
[src]
Returns the object's identifier.
fn ty(self) -> Ty
[src]
Returns the virtual type of self
.
fn is_ty(self, ty: Ty) -> bool
[src]
Returns whether the virtual type of self
is ty
.
fn class(self) -> Class<Self>
[src]
Returns the Class
for self
. Read more
fn singleton_class(self) -> Class<Self>
[src]
Returns the singleton Class
of self
, creating one if it doesn't exist already. Read more
fn mark(self)
[src]
Marks self
for Ruby to avoid garbage collecting it.
unsafe fn force_recycle(self)
[src]
Forces the garbage collector to free the contents of self
. Read more
fn def_singleton_method<N, F>(self, name: N, f: F) -> Result where
N: Into<SymbolId>,
F: MethodFn<Self>,
[src]
N: Into<SymbolId>,
F: MethodFn<Self>,
Defines a method for name
on the singleton class of self
that calls f
when invoked. Read more
unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F) where
N: Into<SymbolId>,
F: MethodFn<Self>,
[src]
N: Into<SymbolId>,
F: MethodFn<Self>,
Defines a method for name
on the singleton class of self
that calls f
when invoked. Read more
unsafe fn call(self, method: impl Into<SymbolId>) -> AnyObject
[src]
Calls method
on self
and returns its output. Read more
unsafe fn call_protected(self, method: impl Into<SymbolId>) -> Result<AnyObject>
[src]
Calls method
on self
and returns its output, or an exception if one is raised. Read more
unsafe fn call_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
Calls method
on self
with args
and returns its output. Read more
unsafe fn call_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
Calls method
on self
with args
and returns its output, or an exception if one is raised. Read more
unsafe fn call_public(self, method: impl Into<SymbolId>) -> AnyObject
[src]
Calls the public method
on self
and returns its output. Read more
unsafe fn call_public_protected(
self,
method: impl Into<SymbolId>
) -> Result<AnyObject>
[src]
self,
method: impl Into<SymbolId>
) -> Result<AnyObject>
Calls the public method
on self
and returns its output, or an exception if one is raised. Read more
unsafe fn call_public_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> AnyObject
Calls the public method
on self
with args
and returns its output. Read more
unsafe fn call_public_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
[src]
self,
method: impl Into<SymbolId>,
args: &[impl Object]
) -> Result<AnyObject>
Calls the public method
on self
with args
and returns its output, or an exception if one is raised. Read more
fn inspect(self) -> String
[src]
Returns a printable string representation of self
. Read more
fn to_s(self) -> String
[src]
Returns the result of calling the to_s
method on self
.
fn is_frozen(self) -> bool
[src]
Returns whether modifications can be made to self
.
fn freeze(self)
[src]
Freezes self
, preventing any further mutations.
fn is_eql<O: Object>(self, other: &O) -> bool
[src]
Returns whether self
is equal to other
in terms of the eql?
method. Read more
fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject
[src]
Returns the value for the attribute of self
associated with name
.
unsafe fn eval(self, args: impl EvalArgs) -> AnyObject
[src]
Evaluates args
in the context of self
. Read more
unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>
[src]
Evaluates args
in the context of self
, returning any raised exceptions. Read more
impl PartialEq<AnyObject> for InstrSeq
[src]
fn eq(&self, obj: &AnyObject) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Copy for InstrSeq
[src]
impl Clone for InstrSeq
[src]
fn clone(&self) -> InstrSeq
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl AsRef<AnyObject> for InstrSeq
[src]
impl From<InstrSeq> for AnyObject
[src]
impl Debug for InstrSeq
[src]
impl Display for InstrSeq
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,