MRubyCompiler2Context

Struct MRubyCompiler2Context 

Source
pub struct MRubyCompiler2Context { /* private fields */ }

Implementations§

Source§

impl MRubyCompiler2Context

Source

pub unsafe fn new() -> Self

Creates a new MRubyCompiler2Context

Examples found in repository?
examples/cfunc.rs (line 6)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    unsafe {
6        let mut cxt = MRubyCompiler2Context::new();
7        cxt.compile_to_c_function(
8            "puts \"Hello, mruby-compiler2!\"",
9            "init_test_func",
10            std::path::Path::new("examples/out.c"),
11        )?;
12    }
13    println!("Created examples/out.c");
14    Ok(())
15}
More examples
Hide additional examples
examples/smoke.rs (line 6)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    unsafe {
6        let mut cxt = MRubyCompiler2Context::new();
7        cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9        let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11        let out = std::fs::File::create("examples/out.mrb")?;
12        std::io::Write::write_all(&mut &out, &bin)?;
13
14        println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15    }
16    Ok(())
17}
Source

pub unsafe fn compile( &mut self, code: &str, ) -> Result<Vec<u8>, MRubyCompiler2Error>

Compiles the given mruby code into mruby bytecode binary Returns the bytecode as a Vec<u8>

Examples found in repository?
examples/smoke.rs (line 9)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    unsafe {
6        let mut cxt = MRubyCompiler2Context::new();
7        cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9        let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11        let out = std::fs::File::create("examples/out.mrb")?;
12        std::io::Write::write_all(&mut &out, &bin)?;
13
14        println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15    }
16    Ok(())
17}
Source

pub unsafe fn dump_bytecode( &mut self, code: &str, ) -> Result<(), MRubyCompiler2Error>

Dumps the compiled bytecode of the given mruby code to stdout

Examples found in repository?
examples/smoke.rs (line 7)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    unsafe {
6        let mut cxt = MRubyCompiler2Context::new();
7        cxt.dump_bytecode("puts \"Hello, mruby-compiler2!\"")?;
8
9        let bin = cxt.compile("puts \"Hello, mruby-compiler2!\"")?;
10
11        let out = std::fs::File::create("examples/out.mrb")?;
12        std::io::Write::write_all(&mut &out, &bin)?;
13
14        println!("Compiled bytecode file: examples/out.mrb, size: {}", bin.len());
15    }
16    Ok(())
17}
Source

pub unsafe fn compile_to_file( &mut self, code: &str, path: &Path, ) -> Result<(), Box<dyn Error>>

Compiles the given mruby code and writes the bytecode to the specified file path

Source

pub unsafe fn compile_to_c_function( &mut self, code: &str, initname: &str, path: &Path, ) -> Result<(), MRubyCompiler2Error>

Compiles the given mruby code and writes the bytecode as a C function to the specified file path

Examples found in repository?
examples/cfunc.rs (lines 7-11)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    unsafe {
6        let mut cxt = MRubyCompiler2Context::new();
7        cxt.compile_to_c_function(
8            "puts \"Hello, mruby-compiler2!\"",
9            "init_test_func",
10            std::path::Path::new("examples/out.c"),
11        )?;
12    }
13    println!("Created examples/out.c");
14    Ok(())
15}

Trait Implementations§

Source§

impl Drop for MRubyCompiler2Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where 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>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where 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>

Performs the conversion.