wasmtime 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +941 -627
- data/Cargo.toml +2 -14
- data/LICENSE +23 -21
- data/README.md +47 -118
- data/ext/Cargo.toml +17 -0
- data/ext/extconf.rb +6 -0
- data/ext/src/helpers/mod.rs +3 -0
- data/ext/src/helpers/wrapped_struct.rs +84 -0
- data/ext/src/lib.rs +9 -0
- data/ext/src/ruby_api/config.rs +68 -0
- data/ext/src/ruby_api/convert.rs +92 -0
- data/ext/src/ruby_api/engine.rs +66 -0
- data/ext/src/ruby_api/errors.rs +56 -0
- data/ext/src/ruby_api/externals.rs +113 -0
- data/ext/src/ruby_api/func.rs +388 -0
- data/ext/src/ruby_api/func_type.rs +139 -0
- data/ext/src/ruby_api/instance.rs +174 -0
- data/ext/src/ruby_api/linker.rs +296 -0
- data/ext/src/ruby_api/macros.rs +12 -0
- data/ext/src/ruby_api/memory.rs +142 -0
- data/ext/src/ruby_api/memory_type.rs +56 -0
- data/ext/src/ruby_api/mod.rs +48 -0
- data/ext/src/ruby_api/module.rs +107 -0
- data/ext/src/ruby_api/params.rs +42 -0
- data/ext/src/ruby_api/static_id.rs +57 -0
- data/ext/src/ruby_api/store.rs +182 -0
- data/ext/src/ruby_api/trap.rs +135 -0
- data/lib/wasmtime/version.rb +1 -1
- data/lib/wasmtime.rb +29 -4
- metadata +54 -30
- data/.cargo/config +0 -4
- data/CHANGELOG.md +0 -27
- data/ext/wasmtime/Makefile +0 -5
- data/ext/wasmtime/Rakefile +0 -3
- data/ext/wasmtime/extconf.rb +0 -5
- data/lib/tasks/compile.rake +0 -27
- data/lib/wasmtime/refinements.rb +0 -20
- data/lib/wasmtime/require.rb +0 -72
- data/src/export.rs +0 -19
- data/src/func.rs +0 -175
- data/src/instance.rs +0 -93
- data/src/lib.rs +0 -22
- data/src/memory.rs +0 -48
- data/src/ruby_type.rs +0 -32
- data/src/vm.rs +0 -6
data/src/instance.rs
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
use lazy_static::lazy_static;
|
2
|
-
use rutie::{class, methods, wrappable_struct, AnyObject, Hash, Module, Object, RString};
|
3
|
-
use std::collections::HashMap;
|
4
|
-
use std::fs;
|
5
|
-
use wasmtime as w;
|
6
|
-
|
7
|
-
use crate::export::Export;
|
8
|
-
use crate::func::Func;
|
9
|
-
|
10
|
-
pub struct Instance {
|
11
|
-
instance: w::Instance,
|
12
|
-
}
|
13
|
-
|
14
|
-
impl Instance {
|
15
|
-
pub fn new(path: String) -> Self {
|
16
|
-
let wasm = fs::read(path).expect("failed to read wasm file");
|
17
|
-
|
18
|
-
let config = w::Config::new();
|
19
|
-
// config.wasm_interface_types(true);
|
20
|
-
|
21
|
-
let engine = w::Engine::new(&config);
|
22
|
-
let store = w::Store::new(&engine);
|
23
|
-
let module = w::Module::new(&store, &wasm).expect("failed to create module");
|
24
|
-
let imports: Vec<w::Extern> = Vec::new();
|
25
|
-
let instance = w::Instance::new(&module, &imports).expect("failed to create instance");
|
26
|
-
|
27
|
-
Instance { instance }
|
28
|
-
}
|
29
|
-
|
30
|
-
fn exports(&self) -> HashMap<String, Export> {
|
31
|
-
let mut exports = HashMap::new();
|
32
|
-
|
33
|
-
for export in self.instance.exports() {
|
34
|
-
match export.ty() {
|
35
|
-
w::ExternType::Func(_) => {
|
36
|
-
let name = export.name().to_string();
|
37
|
-
let func = Func::new(export.into_func().unwrap());
|
38
|
-
exports.insert(name, Export::Func(func));
|
39
|
-
}
|
40
|
-
w::ExternType::Memory(_) => {
|
41
|
-
let name = export.name().to_string();
|
42
|
-
let memory = export.into_memory().unwrap();
|
43
|
-
exports.insert(name, Export::Memory(memory));
|
44
|
-
}
|
45
|
-
_ => {}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
exports
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
wrappable_struct!(Instance, InstanceWrapper, INSTANCE_WRAPPER);
|
54
|
-
class!(RubyInstance);
|
55
|
-
|
56
|
-
impl From<Instance> for RubyInstance {
|
57
|
-
fn from(instance: Instance) -> Self {
|
58
|
-
Module::from_existing("Wasmtime")
|
59
|
-
.get_nested_class("Instance")
|
60
|
-
.wrap_data(instance, &*INSTANCE_WRAPPER)
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
#[rustfmt::skip]
|
65
|
-
methods!(
|
66
|
-
RubyInstance,
|
67
|
-
itself,
|
68
|
-
|
69
|
-
fn ruby_instance_new(path: RString) -> RubyInstance {
|
70
|
-
Instance::new(path.expect("failed read path").to_string()).into()
|
71
|
-
}
|
72
|
-
|
73
|
-
fn ruby_instance_exports() -> Hash {
|
74
|
-
let mut exports = Hash::new();
|
75
|
-
|
76
|
-
for (export_name, export) in itself.get_data(&*INSTANCE_WRAPPER).exports().into_iter() {
|
77
|
-
exports.store::<RString, AnyObject>(RString::new_utf8(&export_name), export.into());
|
78
|
-
}
|
79
|
-
|
80
|
-
exports
|
81
|
-
}
|
82
|
-
);
|
83
|
-
|
84
|
-
pub fn ruby_init() {
|
85
|
-
Module::from_existing("Wasmtime").define(|module| {
|
86
|
-
module
|
87
|
-
.define_nested_class("Instance", None)
|
88
|
-
.define(|class| {
|
89
|
-
class.def_self("new", ruby_instance_new);
|
90
|
-
class.def("exports", ruby_instance_exports);
|
91
|
-
});
|
92
|
-
});
|
93
|
-
}
|
data/src/lib.rs
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
mod export;
|
2
|
-
mod func;
|
3
|
-
mod instance;
|
4
|
-
mod memory;
|
5
|
-
mod ruby_type;
|
6
|
-
mod vm;
|
7
|
-
|
8
|
-
#[allow(non_snake_case)]
|
9
|
-
#[no_mangle]
|
10
|
-
pub extern "C" fn Init_native() {
|
11
|
-
std::panic::set_hook(Box::new(|panic_info| {
|
12
|
-
if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
|
13
|
-
vm::raise("StandardError", s)
|
14
|
-
} else {
|
15
|
-
vm::raise("StandardError", &format!("{:?}", panic_info))
|
16
|
-
}
|
17
|
-
}));
|
18
|
-
|
19
|
-
instance::ruby_init();
|
20
|
-
func::ruby_init();
|
21
|
-
memory::ruby_init();
|
22
|
-
}
|
data/src/memory.rs
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
use lazy_static::lazy_static;
|
2
|
-
use rutie::{class, methods, wrappable_struct, AnyObject, Integer, Module, NilClass, Object};
|
3
|
-
use wasmtime as w;
|
4
|
-
|
5
|
-
wrappable_struct!(w::Memory, MemoryWrapper, MEMORY_WRAPPER);
|
6
|
-
class!(RubyMemory);
|
7
|
-
|
8
|
-
impl From<w::Memory> for RubyMemory {
|
9
|
-
fn from(memory: w::Memory) -> Self {
|
10
|
-
Module::from_existing("Wasmtime")
|
11
|
-
.get_nested_class("Memory")
|
12
|
-
.wrap_data(memory, &*MEMORY_WRAPPER)
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
#[rustfmt::skip]
|
17
|
-
methods!(
|
18
|
-
RubyMemory,
|
19
|
-
itself,
|
20
|
-
|
21
|
-
fn ruby_instance_data_size() -> Integer {
|
22
|
-
Integer::from(itself.get_data(&*MEMORY_WRAPPER).data_size() as u32)
|
23
|
-
}
|
24
|
-
|
25
|
-
fn ruby_instance_size() -> Integer {
|
26
|
-
Integer::from(itself.get_data(&*MEMORY_WRAPPER).size())
|
27
|
-
}
|
28
|
-
|
29
|
-
fn ruby_instance_grow(delta: Integer) -> AnyObject {
|
30
|
-
let memory = itself.get_data(&*MEMORY_WRAPPER);
|
31
|
-
let delta = delta.unwrap().to_i32();
|
32
|
-
if delta < 0 { return NilClass::new().into() }
|
33
|
-
match memory.grow(delta as u32) {
|
34
|
-
Ok(original) => Integer::from(original).into(),
|
35
|
-
Err(_) => NilClass::new().into()
|
36
|
-
}
|
37
|
-
}
|
38
|
-
);
|
39
|
-
|
40
|
-
pub fn ruby_init() {
|
41
|
-
Module::from_existing("Wasmtime").define(|module| {
|
42
|
-
module.define_nested_class("Memory", None).define(|class| {
|
43
|
-
class.def("data_size", ruby_instance_data_size);
|
44
|
-
class.def("size", ruby_instance_size);
|
45
|
-
class.def("grow", ruby_instance_grow);
|
46
|
-
});
|
47
|
-
});
|
48
|
-
}
|
data/src/ruby_type.rs
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
use rutie::{AnyObject, RString};
|
2
|
-
use wasmtime as w;
|
3
|
-
|
4
|
-
#[derive(Debug, Copy, Clone)]
|
5
|
-
pub enum RubyType {
|
6
|
-
Integer32,
|
7
|
-
Integer64,
|
8
|
-
Float32,
|
9
|
-
Float64,
|
10
|
-
// String,
|
11
|
-
// Boolean,
|
12
|
-
NilClass,
|
13
|
-
Unsupported,
|
14
|
-
}
|
15
|
-
|
16
|
-
impl From<RubyType> for AnyObject {
|
17
|
-
fn from(ruby_type: RubyType) -> AnyObject {
|
18
|
-
RString::new_utf8(&format!("{:?}", ruby_type)).into()
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
impl From<&w::ValType> for RubyType {
|
23
|
-
fn from(val_type: &w::ValType) -> Self {
|
24
|
-
match val_type {
|
25
|
-
w::ValType::I32 => RubyType::Integer32,
|
26
|
-
w::ValType::I64 => RubyType::Integer64,
|
27
|
-
w::ValType::F32 => RubyType::Float32,
|
28
|
-
w::ValType::F64 => RubyType::Float64,
|
29
|
-
_ => RubyType::Unsupported,
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|