This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#![feature(is_some_with)]
|
||||
#![feature(core_ffi_c)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(get_mut_unchecked)]
|
||||
|
||||
//! PkmnLib
|
||||
//! PkmnLib is a full featured implementation of Pokemon. while currently focused on implementing
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use core::ffi::c_char;
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::CString;
|
||||
use std::mem::{align_of, size_of};
|
||||
use std::mem::align_of;
|
||||
|
||||
use wasmer::wasmparser::Data;
|
||||
use wasmer::{Exports, Function, Store};
|
||||
|
||||
use crate::dynamic_data::DynamicLibrary;
|
||||
@@ -82,7 +80,7 @@ fn const_string_get_hash(env: &WebAssemblyEnv, string_key: ExternRef<StringKey>)
|
||||
|
||||
fn const_string_get_str(env: &WebAssemblyEnv, string_key: ExternRef<StringKey>) -> u32 {
|
||||
let string_key = string_key.value(env).str();
|
||||
let mut s: CString = CString::new(string_key.as_bytes()).unwrap();
|
||||
let s: CString = CString::new(string_key.as_bytes()).unwrap();
|
||||
let wasm_string_ptr = env
|
||||
.resolver()
|
||||
.allocate_mem(string_key.len() as u32, align_of::<CString>() as u32);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use std::any::{Any, TypeId};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
@@ -46,7 +44,7 @@ struct ScriptCapabilitiesKey {
|
||||
|
||||
impl WebAssemblyScriptResolver {
|
||||
/// Instantiates a new WebAssemblyScriptResolver.
|
||||
pub fn new() -> Self {
|
||||
pub fn new() -> Box<WebAssemblyScriptResolver> {
|
||||
let config = Cranelift::default();
|
||||
let mut features = Features::new();
|
||||
features.multi_value = true;
|
||||
@@ -54,7 +52,7 @@ impl WebAssemblyScriptResolver {
|
||||
let universal = Universal::new(config).features(features);
|
||||
let engine = universal.engine();
|
||||
let store = Store::new(&engine);
|
||||
Self {
|
||||
let s = Self {
|
||||
engine,
|
||||
store,
|
||||
module: Default::default(),
|
||||
@@ -69,7 +67,8 @@ impl WebAssemblyScriptResolver {
|
||||
extern_ref_pointers: Default::default(),
|
||||
extern_ref_pointers_lookup: Default::default(),
|
||||
extern_ref_type_lookup: Default::default(),
|
||||
}
|
||||
};
|
||||
Box::new(s)
|
||||
}
|
||||
|
||||
/// Load a compiled WASM module.
|
||||
@@ -146,7 +145,7 @@ impl WebAssemblyScriptResolver {
|
||||
/// its proper value, validates its type, and returns the value.
|
||||
pub fn get_extern_ref_value<T: UniqueTypeId<u64>>(&self, index: u32) -> &T {
|
||||
let read_guard = self.extern_ref_pointers.read();
|
||||
let ptr = read_guard.get(index as usize).unwrap();
|
||||
let ptr = read_guard.get((index - 1) as usize).unwrap();
|
||||
let expected_type_id = self.extern_ref_type_lookup.read()[&ptr];
|
||||
if expected_type_id != T::id().0 {
|
||||
panic!("Extern ref was accessed with wrong type");
|
||||
|
||||
Reference in New Issue
Block a user