text
stringlengths
14
100k
source
stringclasses
1 value
repo
stringclasses
810 values
language
stringclasses
13 values
<|fim_prefix|>#!/usr/bin/env python3 # Author: Volodymyr Shymanskyy # Usage: # ./run-wasi-test.py # ./run-wasi-test.py --exec ../custom_build/wasm3 --timeout 120 # ./run-wasi-test.py --exec "wasmer run --mapdir=/:." --separate-args # ./run-wasi-test.py --exec "wasmer run --mapdir=/:. wasm3.wasm --" --fast # ...
fim
wasm3/wasm3
python
<|fim_suffix|>r *sep; switch(argv[i][1]) { case 's': if(!isdigit(argv[++i][0]) || !(sep = strchr(argv[i], 'x')) || !isdigit(*(sep + 1))) { fputs("-s must be followed by something like \"640x480\"\n", stderr); return EXIT_FAILURE; } xres = atoi(argv[i]); yres = atoi(sep + 1); aspect =...
fim
wasm3/wasm3
c
<|fim_prefix|>#include <math.h> typedef struct { double hi; double lo; } DoubleDouble; static inline DoubleDouble dd_new(double hi, double lo) { DoubleDouble num; num.hi = hi; num.lo = lo; return num; } unsigned int dd_get_ui(DoubleDouble num) { return num.hi; } static inline DoubleDoubl...
fim
wasm3/wasm3
c
<|fim_suffix|>ailout - logl(logl(r))) * Q1LOG2; int idx = fmodl((logl(c/64+1)/LOG2+0.45), 1)*(GRADIENTLENGTH-1) + 0.5; fwrite(&colors[idx], 1, 3, stdout); } } } double tend = get_time(); fprintf(stderr, "\nElapsed time: %.2f ms\n", tend-tbeg); //fpr...
fim
wasm3/wasm3
c
<|fim_suffix|>_sqr(zx); //yy = zy * zy; yy = dd_sqr(zy); //if (xx + yy > bailout) { if (xx.hi + yy.hi > bailout) { inside = false; break; } // iterate //zy = 2 * zx * z...
fim
wasm3/wasm3
c
<|fim_suffix|>ct vec3 L = { 50.0f * sinf(t), 20.0f, 50.0f * cosf(t) }; L.normalize(); float dt = 1e-6; float current_val = sdf(pos); struct vec3 x = {pos.x + dt, pos.y, pos.z}; float dx = sdf(x) - current_val; struct vec3 y = {pos.x, pos.y +...
fim
wasm3/wasm3
cpp
<|fim_suffix|>pec now; clock_gettime(CLOCK_REALTIME, &now); printf("Now: %lld sec, %ld ns\n", now.tv_sec, now.tv_nsec); } void test_perf_fib(uint32_t n) { struct timespec start, finish; uint32_t result; printf("fib(%d) = ", n); fflush(stdout); // Chew up some CPU time clock_gettime(CLOCK_REALTIME, &s...
fim
wasm3/wasm3
c
<|fim_prefix|>#ifndef wasm_api_h #define wasm_api_h #include <stdint.h> #define WASM_EXPORT __attribute__((used)) __attribute__((<|fim_suffix|>tribute__((import_module(MODULE))) __attribute__((import_name(NAME))) #endif <|fim_middle|>visibility ("default"))) #define WASM_EXPORT_AS(NAME) WASM_EXPOR...
fim
wasm3/wasm3
c
#include <math.h> // smallpt, a Path Tracer by Kevin Beason, 2009 #include <stdlib.h> // Make : g++ -O3 -fopenmp explicit.cpp -o explicit #include <stdio.h> // Remove "-fopenmp" for g++ version < 4.2 #include <time.h> double get_time() { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return ts.tv...
fim
wasm3/wasm3
cpp
#include <math.h> // smallpt, a Path Tracer by Kevin Beason, 2008 #include <stdlib.h> // Make : g++ -O3 -fopenmp smallpt.cpp -o smallpt #include <stdio.h> // Remove "-fopenmp" for g++ version < 4.2 #include <time.h> double get_time() { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return ts.tv_s...
fim
wasm3/wasm3
cpp
/*-----------------------------------------------------------------------*/ /* Program: STREAM */ /* Revision: $Id: stream.c,v 5.10 2013/01/17 16:01:06 mccalpin Exp mccalpin $ */ /* Original code developed by John D. McCalpin */ /* Programm...
fim
wasm3/wasm3
c
<|fim_suffix|>ime import os # Define the S3 bucket name and the number of days to retain objects days_to_retain = 7 bucket_name = os.environ['AWS_BUCKET_NAME'] access_key = os.environ['AWS_ACCESS_KEY_ID'] secret_key = os.environ['AWS_SECRET_ACCESS_KEY'] endpoint = os.environ['AWS_ENDPOINT'] # Create a connection to ...
fim
wasmerio/wasmer
python
<|fim_suffix|> modules { let bytes = reqwest::blocking::get(format!("{BENCHMARKS_ARTIFACTS_BASE_URL}/{module}.wasm")) .unwrap() .bytes() .unwrap(); compile_wasm(c, bytes.as_ref(), &format!("exec/{name}/{module}")); } } pub fn download_and_...
fim
wasmerio/wasmer
rust
<|fim_suffix|> serialize_deserialize(c, &bytes, module); serialize_deserialize_unchecked(c, &bytes, module); } } criterion_group!( name = benches; config = Criterion::default().sample_size(60); targets = download_and_run ); criterion_main!(benches); <|fim_prefix|>use criterion::{Criteri...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use std::hint::black_box; use criterion::{Criterion, criterion_group, criterion_main}; use wasmer::*; pub fn run_import_inner(store: &mut S<|fim_suffix|>! {}; for i in 0..n_fn { let name = format!("f{i}"); imports.define( "env", ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use criterion::{Criterion, criterion_group, criterion_main}; use wasmer::*; static BENCHMARKS_ARTIFACTS_BASE_URL: &str = "https://pub-083d1a0568d446d1aa5b2e07bd16983b.r2.dev"; #[allow(unreachable_code)] fn get_engine() -> Engine { #[cfg(feature = "llvm")] return wasmer_compiler_llvm::LLVM::new()...
fim
wasmerio/wasmer
rust
<|fim_suffix|>elift")] { let mut store = Store::new(wasmer_compiler_cranelift::Cranelift::new()); run_basic_dynamic_function(&mut store, "cranelift", _c); } #[cfg(feature = "singlepass")] { let mut store = Store::new(wasmer_compiler_singlepass::Singlepass::new()); run_ba...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ement; the arg/result marshaling /// done by `TypedFunction` is the only thing on top of the trampoline. fn bench_typed_call_lit(c: &mut Criterion) { let (mut store, instance) = fresh_singlepass_instance(); let lit = instance .exports .get_typed_function::<(), i32>(&store, "lit") ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! The logic that gets executed before building the binary and tests. //! We use it to auto-generate the Wasm spectests for each of the //! available compilers. //! //! Please try to keep this file as clean as possible. use std::env; use std::fs; use std::path::PathBuf; use std::process::Command; use te...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can be compiled with multiple compilers. //! //! This example illustrates how to use the Cranelift compiler. //! //! You can run the example directly by executing in Wasmer root: //! //! ```shell //! cargo run --example compiler-cranelift --release --features "cranelift" //! ``` //! //! ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>"sum" (func $sum_f))) "# .as_bytes(), )?; // Use LLVM compiler with the default settings let compiler = LLVM::default(); // Create the store let mut store = Store::new(compiler); println!("Compiling module..."); // Let's compile the Wasm module. let module = Modu...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can be compiled with multiple compilers. //! //! This example illustrates how to use the Singlepass compiler. //! //! You can run the example directly by executing in Wasmer root: //! //! ```shell //! cargo run --example compiler-singlepass --release --features "singlepass" //! ``` //! /...
fim
wasmerio/wasmer
rust
<|fim_suffix|>intln!("Exited early with exit code: {exit_code}"); Ok(()) } Err(e) => { bail!("Unknown error `{e}` found. expected `ExitCode`"); } }, } } #[test] fn test_early_exit() -> anyhow::Result<()> { main() } <|fim_prefix|>//! T...
fim
wasmerio/wasmer
rust
<|fim_suffix|>e our Wasm module didn't declare // any imports, it's an empty object. let import_object = imports! {}; println!("Instantiating module..."); // And here we go again. Let's instantiate the Wasm module. let instance = Instance::new(&mut store, &module, &import_object)?; println!("C...
fim
wasmerio/wasmer
rust
<|fim_suffix|> Box<dyn std::error::Error>> { main() } <|fim_prefix|>//! Defining an engine in Wasmer is one of the fundamental steps. //! //! As a reminder, an engine applies roughly 2 steps: //! //! 1. It compiles the Wasm module bytes to executable code, through //! the intervention of a compiler, //! 2....
fim
wasmerio/wasmer
rust
<|fim_suffix|>le into executable code. let compiler_config = Cranelift::default(); println!("Creating Dylib engine..."); // Define the engine that will drive everything. // // In this case, the engine is `wasmer_engine_dylib` which means // that a shared object is going ...
fim
wasmerio/wasmer
rust
//! Defining an engine in Wasmer is one of the fundamental steps. //! //! This example illustrates a neat feature of engines: their ability //! to run in a headless mode. At the time of writing, all engines //! have a headless mode, but it's not a requirement of the `Engine` //! trait (defined in the `wasmer_engine` cr...
fim
wasmerio/wasmer
rust
<|fim_suffix|> // Let's declare the Wasm module with the text representation. let wasm_bytes = wat2wasm( br#" (module (type $do_div_by_zero_t (func (result i32))) (func $do_div_by_zero_f (type $do_div_by_zero_t) (result i32) i32.const 4 i32.const 0 i32.div_s) (type $div_by_zero_t (func (...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can export entities, like functions, memories, //! globals and tables. //! //! This example illustrates how to use exported functions. They come //! in 2 flavors: //! //! 1. Dynamic functions, where parameters and results are of a //! slice of `Value`, //! 2. Native function, wh...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can export entities, like functions, memories, //! globals and tables. //! //! This example illustrates how to use exported globals. They come //! in 2 flavors: //! //! 1. Immutable globals (const), //! 2. Mutable globals. //! //! You can run the example directly by executing in Wasm...
fim
wasmerio/wasmer
rust
<|fim_suffix|>4).write(str).unwrap(); } // And now, let's see the result. // // Since the new strings is bigger than the older one, we // query the length again. The offset remains the same as // before. println!("New string length: {:?}", new_str.len()); let str = ptr .read_ut...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! WebAssembly is a living standard. Wasmer integrates some //! WebAssembly features that aren't yet stable but can still be //! turned on. This example explains how. //! //! You can run the example directly by executing in Wasmer root: //! //! ```shell //! cargo run --example features --release --featur...
fim
wasmerio/wasmer
rust
<|fim_suffix|> (export "add_one" (func $add_one)) )"#; // 3) Our second WAT module ("module B") that imports the table and uses `call_ref`. let module_b_wat = r#"(module (type $t0 (func (param i32) (result i32))) (import "env" "table" (table 1 funcref)) (func $call_func (param i32) (result i32) (loca...
fim
wasmerio/wasmer
rust
<|fim_suffix|> // We then use our store and Wasm bytes to compile a `Module`. // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. let module = Module::new(&store, wasm_bytes)?; // We define a function to act as our "env" "say_hello" function imported in the // Wasm progra...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ttps://postman-echo.com/bytes/5/mb?type=json")) "#, )?; // Load module let mut store = Store::default(); let module = Module::new(&store, wasm_bytes)?; // Add host functions let function_env = FunctionEnv::new(&mut store, ExampleEnv { memory: None }); let import_object = impo...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can import and export entities, like functions, memories, globals and tables. //! This example illustrates the basics of using these entities. //! //! In this example we'll be using a sample Wasm module which exports some entities and requires us //! to also import some of them. //! //! ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>.."); let result = a * 3; println!("Result of `multiply_typed`: {result:?}"); result } let multiply_typed = Function::new_typed_with_env(&mut store, &env, multiply); // Create an import object. let import_object = imports! { "env" => { "multip...
fim
wasmerio/wasmer
rust
<|fim_suffix|>unter_loop" (func $increment_f))) "#, )?; // Create a Store. let mut store = Store::default(); println!("Compiling module..."); // Let's compile the Wasm module. let module = Module::new(&store, wasm_bytes)?; // We create some shared data here, `Arc` is required because we m...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can import entities, like functions, memories, //! globals and tables. //! //! In this example, we'll create a system for getting and adjusting a counter value. However, host //! functions are not limited to storing data outside of Wasm, they're normal host functions and //! can do anyth...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! A Wasm module can import entities, like functions, memories, //! globals and tables. //! //! This example illustrates how to use imported globals. They come //! in 2 flavors: //! //! 1. Immutable globals (const), //! 2. Mutable globals. //! //! You can run the example directly by executing in Wasm...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ule..."); // Let's compile the Wasm module. let module = Module::new(&store, wasm_bytes)?; // Create an empty import object. let import_object = imports! {}; println!("Instantiating module..."); // Let's instantiate the Wasm module. let instance = Instance::new(&mut store, &m...
fim
wasmerio/wasmer
rust
<|fim_suffix|>odule exports some utility functions, let's get them. // // These function will be used later in this example. let mem_size: TypedFunction<(), i32> = instance.exports.get_typed_function(&store, "mem_size")?; let get_at: TypedFunction<i32, i32> = instance.exports.get_typed_function(...
fim
wasmerio/wasmer
rust
//! Example demonstrating WebAssembly memory growth limits //! //! Tests growing memory to maximum allowed size according to the spec //! You can run the example directly by executing: //! ```shell //! cargo run --example memory-grow --release --features "cranelift" //! ``` use wasmer::{Instance, Module, Store, import...
fim
wasmerio/wasmer
rust
//! Wasmer will let you easily run Wasm module in a Rust host. //! //! This example illustrates the basics of using Wasmer metering features: //! //! 1. How to enable metering in a module //! 2. How to meter a specific function call //! 3. How to make execution fails if cost exceeds a given limit //! //! You can ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! Defining an engine in Wasmer is one of the fundamental steps. //! //! This example builds on that of 'engine_headless.rs' but instead of //! serializing a module and then deserializing it again for your host machines target, //! We instead create an engine for our target architecture (In this case an ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use wasmer::{ Function, Instance, Module, Store, TableType, Type, TypedFunction, Value, imports, wat2wasm, }; /// A function we'll call through a table. fn host_callback(arg1: i32, arg2: i32) -> i32 { arg1 + arg2 } fn main() -> anyhow::Result<()> { let wasm_bytes = wat2wasm( r#" (mod...
fim
wasmerio/wasmer
rust
use std::sync::{Arc, atomic::AtomicUsize}; use wasmer::{ Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module, RuntimeError, Store, Type, TypedFunction, Value, imports, sys::Target, wat2wasm, }; use wasmer_types::Features; fn main() -> Result<(), Box<dyn std::error::Error>> { // Let's dec...
fim
wasmerio/wasmer
rust
<|fim_suffix|>::new(engine); println!("Compiling module..."); let module = Module::new(&store, wasm_bytes)?; println!("Instantiating module..."); let import_object = imports! {}; // Now at this point, our custom tunables are used let instance = Instance::new(&mut store, &module, &import_objec...
fim
wasmerio/wasmer
rust
<|fim_suffix|>thread() .enable_all() .build() .unwrap(); let _guard = tokio_runtime.enter(); let tokio_task_manager = TokioTaskManager::new(tokio_runtime.handle().clone()); let runtime = PluggableRuntime::new(Arc::new(tokio_task_manager)); println!("Compiling module..."); //...
fim
wasmerio/wasmer
rust
<|fim_suffix|>tion("_start")?; start.call(&mut store, &[])?; wasi_env.on_exit(&mut store, None); Ok(()) } #[test] #[cfg(feature = "wasi")] fn test_wasi() -> Result<(), Box<dyn std::error::Error>> { main() } <|fim_prefix|>//! Running a WASI compiled WebAssembly module with Wasmer. //! //! This example...
fim
wasmerio/wasmer
rust
<|fim_suffix|> end end i32.const 12 local.get $n i32.store i32.const 1 i32.const 8 i32.const 1 i32.const 20 call $fd_write drop)) "#; fn main() -> Result<(), Box<dyn std::error::Error>> { let wasm_bytes = wat2wasm(REVERSE_WASI_WAT)?.into_owned(); // We need at leas...
fim
wasmerio/wasmer
rust
<|fim_suffix|>nd always) as we might hit a crash or a validation error. save_wasm_file(&wasm_bytes); let module = Module::new(&store, &wasm_bytes); let module = match module { Ok(m) => m, Err(e) => { if ignore_compilation_error(&e.to_string()) { return; ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>#![no_main] use libfuzzer_sys::fuzz_target; use wasmer::{Module, Store}; use wasmer_compiler::Engine; use wasmer_compiler::{CompilerConfig, EngineBuilder}; use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_llvm::LLVM; use wasmer_compiler_singlepass::Singlepass; mod misc; use misc::{SinglePass...
fim
wasmerio/wasmer
rust
#![no_main] #![deny(unused_variables)] #[cfg(not(any(feature = "cranelift", feature = "llvm", feature = "singlepass")))] compile_error!( "the `equivalence` fuzzer requires at least one of: `cranelift`, `llvm`, `singlepass`" ); use anyhow::Result; use libfuzzer_sys::fuzz_target; use wasmer::{Instance, Module, Stor...
fim
wasmerio/wasmer
rust
<|fim_prefix|>#![no_main] use libfuzzer_sys::{arbitrary::Arbitrary, fuzz_target}; mod misc; use misc::{ignore_compilation_error, ignore_runtime_error, save_wasm_file}; use wasmer::{Instance, Module, Store, imports}; use wasmer_compiler::{CompilerConfig, EngineBuilder}; use wasmer_compiler_llvm::LLVM; struct LLVMPassF...
fim
wasmerio/wasmer
rust
<|fim_prefix|>#![no_main] use libfuzzer_sys::fuzz_tar<|fim_suffix|>I32Add { .. } => 2, _ => 0, } } fuzz_target!(|module: SinglePassFuzzModule| { let wasm_bytes = module.0.to_bytes(); let mut compiler = Cranelift::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use libfuzzer_sys::arbitrary::Arbitrary; #[allow(dead_code)] pub(crate) struct SinglePassFuzzModule(pub(crate) wasm_smith::Module); impl Arbitrary<'_> for SinglePassFuzzModule { fn arbitrary( u: &mut libfuzzer_sys::arbitrary::Unstructured, ) -> libfuzzer_sys::arbitrary::Result<Self> { ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>#![no_main] use libfuzzer_sys::fuzz_target; mod misc; use misc::{SinglePassFuzzModule, ignore_compilation_error, ignore_runtime_error, save_wasm_file}; use wasmer::{Instance, Module, Store, import<|fim_suffix|>!(|module: SinglePassFuzzModule| { let wasm_bytes = module.0.to_bytes(); let compiler ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>)) .generate() .expect("Unable to generate bindings for `v8`!"); bindings .write_to_file(out_path.join("v8_bindings.rs")) .expect("Couldn't write bindings"); let objcopy_names = ["llvm-objcopy", "objcopy", "gobjcopy"]; let mut objcopy = None; for n in obj...
fim
wasmerio/wasmer
rust
<|fim_suffix|>put.parse()?; let sig: Signature = input.parse()?; let inner_attrs = input.call(Attribute::parse_inner)?; let block: TokenStream = input.parse()?; Ok(Self { outer_attrs, inner_attrs, vis, sig, block, }) ...
fim
wasmerio/wasmer
rust
<|fim_suffix|> `js` runtime. pub fn is_js(&self) -> bool { matches!(self.be, crate::BackendEngine::Js(_)) } } impl From<Engine> for crate::Engine { fn from(val: Engine) -> Self { Self { be: crate::BackendEngine::Js(val), id: Self::atomic_next_engine_id(), } ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! Data types, functions and traits for `sys` runtime's `Tag` implementation. use super::store::StoreHandle; use crate::{ AsStoreMut, AsStoreRef, Tag,<|fim_suffix|>e]) -> Self { unimplemented!("Exception handling is not yet supported in js"); } } <|fim_middle|> Value, js::vm::{VMExce...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ernRef { unimplemented!("ExternRef is not yet supported in Javascript"); } pub(crate) unsafe fn from_vm_externref( _store: &mut impl AsStoreMut, _vm_externref: VMExternRef, ) -> Self { unimplemented!("ExternRef is not yet supported in Javascript"); } p...
fim
wasmerio/wasmer
rust
<|fim_suffix|> FunctionEnvMut { store_mut: store.as_store_mut(), func_env: self, } } } impl<T> PartialEq for FunctionEnv<T> { fn eq(&self, other: &Self) -> bool { self.handle == other.handle } } impl<T> Eq for FunctionEnv<T> {} impl<T> std::hash::Hash for Fu...
fim
wasmerio/wasmer
rust
<|fim_suffix|>l)) .collect::<Vec<_>>() .into_boxed_slice()) } } } pub(crate) fn from_vm_extern(_store: &mut impl AsStoreMut, internal: VMExternFunction) -> Self { Self { handle: internal.unwrap_js(), } } pub(crate)...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! Native Functions. //! //! This module creates the helper `TypedFunction` that let us call WebAssembly //! functions with the native ABI, that is: //! //! ```ignore //! let add_one = instance.exports.get_function("function_name")?; //! let add_one_native: TypedFunction<i32, i32> = add_one.typed().unwra...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use wasm_bindgen::{JsValue, prelude::*}; use wasmer_types::{GlobalType, Mutability, RawValue, Type}; use crate::{ AsStoreMut, AsStoreRef, BackendGlobal, RuntimeError, Value, js::vm::VMGlobal, vm::{VMExtern, VMExternGlobal}, }; use js_sys::WebAssembly; #[derive(Debug, Clone, PartialEq, Eq)] /...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use js_sys::WebAssembly; use crate::{ AsStoreMut, BackendInstance, Exports, Extern, Imports, InstantiationError, Module, js::{ utils::{convert::AsJs, js_handle::JsHandle}, vm::VMInstance, }, }; #[derive(Clone, PartialEq, Eq)] /// A WebAssembly `instance` in `js`. pub struct I...
fim
wasmerio/wasmer
rust
<|fim_suffix|> end, view.length() ); return Err(MemoryAccessError::HeapOutOfBounds); } let buf_ptr = buf.as_mut_ptr() as *mut u8; let mut slice = unsafe { slice::from_raw_parts_mut(buf_ptr, buf.len()) }; view.subarray(offset as _, end as _).copy...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ould exceed the maximum /// memory. /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) #[wasm_bindgen(catch, method, js_namespace = WebAssembly)] pub fn grow(this: &JSMemory, pages: u32) -> Result<u32, J...
fim
wasmerio/wasmer
rust
<|fim_suffix|>ref s) => s, _ => panic!("Not a `js` memory!"), } } /// Convert a mutable reference to [`self`] into a mutable reference to [`crate::backend::js::mem::Memory`]. pub fn as_js_mut(&mut self) -> &mut crate::backend::js::memory::Memory { match self.0 { Back...
fim
wasmerio/wasmer
rust
use std::{marker::PhantomData, mem::MaybeUninit, ops::Range, slice}; use wasm_bindgen::JsCast; use wasmer_types::{Bytes, Pages}; use crate::{AsStoreRef, MemoryAccessError}; use super::{Memory, MemoryBuffer}; /// A WebAssembly `memory` view. /// /// A memory view is used to read and write to the linear memory. /// /...
fim
wasmerio/wasmer
rust
<|fim_prefix|>pub(crate) mod engine; pub(crate) mod exception; pub(crate) mod external; pub(crate) mod function; pub(crat<|fim_suffix|>obal; pub(crate) mod instance; pub(crate) mod memory; pub(crate) mod module; pub(crate) mod store; pub(crate) mod table; pub(crate) mod tag; <|fim_middle|>e) mod gl<|endoftext|>
fim
wasmerio/wasmer
rust
<|fim_suffix|> } "memory" => { let memory_type = MemoryType::new(Pages(1), None, false); ExternType::Memory(memory_type) } "table" => { let table_...
fim
wasmerio/wasmer
rust
<|fim_suffix|>context associated with the handle. #[allow(unused)] pub fn store_id(&self) -> StoreId { self.id } /// Overrides the store id with a new ID #[allow(unused)] pub fn set_store_id(&mut self, id: StoreId) { self.id = id; } /// Constructs a `StoreHandle` from a...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use crate::{AsEngineRef, Engine, EngineRef}; pub(crate) mod handle; pub(crate) mod obj; pub(crate) use handle::*; pub(crate) use obj::*; #[derive(Debug)] pub(crate) struct Store { pub(crate) engine: Engine, } impl Store { pub(crate) fn new(engine: Engine) -> Self { Self { engine } ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>nce the other JS objects (table, globals, memory and functions) // live in the JS VM Store by default function_environments => VMFunctionEnvironment, } /// Set of objects managed by a context. #[derive(Default, Debug)] pub struct StoreObjects { id: StoreId, globals: Vec<VMGlobal>, fun...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use crate::{ AsStoreMut, AsStoreRef, BackendTable, RuntimeError, Value, js::vm::{VMFunction, VMTable}, vm::{VMExtern, VMExternTable}, }; use js_sys::Function; use wasmer_types::{FunctionType, TableType}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Table { pub(crate) handle: VMTable,...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use wasmer_types::{TagType, Type}; use crate::{ AsStoreMut, AsStoreRef, BackendTag, TagKind, js::vm::VMTag, vm::{VMExtern, VMExternTag}, }; #[derive(Debug, Clone, PartialEq, Eq)] /// A WebAssembly `tag` in the `v8` runtime. pub(crate) struct Tag { pub(crate) handle: VMTag, } unsafe impl...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use std::error::Error; use js_sys::Reflect; use wasm_bindgen::{JsValue, prelude::*}; use crate::{ RuntimeError, js::{exception::Exception, vm::VMExceptionRef}, }; #[derive(Debug)] enum InnerTrap { User(Box<dyn Error + Send + Sync>), Js(JsTrap), } /// A struct representing a Trap #[wasm...
fim
wasmerio/wasmer
rust
<|fim_prefix|>//! Data types, functions and traits for the `js` backend. pub(crate) mod entities; pub(crate) mod error; pub(crate) mod utils; pub(crate) mod vm<|fim_suffix|>ities::*; pub use utils::*; <|fim_middle|>; pub use ent<|endoftext|>
fim
wasmerio/wasmer
rust
<|fim_suffix|>e instance: {e:?}")))?; Ok(Self { _inner: crate::BackendInstance::Js(instance), module: module.clone(), exports, }) } } impl AsJs for Memory { type DefinitionType = crate::MemoryType; fn as_jsvalue(&self, _store: &impl AsStoreRef) -> wasm_b...
fim
wasmerio/wasmer
rust
<|fim_suffix|> writeln!(error_message, "{bt}").unwrap(); writeln!(error_message).unwrap(); } panic!("{error_message}"); } } } fn record_backtrace() -> Option<String> { let err = js_sys::Error::new(""); let stack = J...
fim
wasmerio/wasmer
rust
<|fim_suffix|>le::*; <|fim_prefix|>pub(crate) mod convert; pub(crate) mod js_handle; pub use convert::*; pub use <|fim_middle|>js_hand<|endoftext|>
fim
wasmerio/wasmer
rust
<|fim_suffix|>mory::Js(m), )), Self::Global(g) => Extern::Global(crate::Global::from_vm_extern( store, crate::vm::VMExternGlobal::Js(g), )), Self::Table(t) => Extern::Table(crate::Table::from_vm_extern( store, ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>/// The type of function bodies in the `js` VM. pub struct VMFunctionBody(u8); #[repr(transparent)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] /// The type of function references in the `js` VM. pub(crate) struct VMFuncRef; impl VMFuncRef { /// Converts the `VMFuncRef` into a `RawValue`. ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use js_sys::WebAssembly::Global as JsGlobal; use wasmer_types::GlobalType; /// The VM Global type #[derive(Clone, Debug, PartialEq, Eq)] pub struct VMGlobal { pub(crate) global: JsGlobal, pub<|fim_suffix|> {} unsafe impl Sync for VMGlobal {} <|fim_middle|>(crate) ty: GlobalType, } impl VMGlobal ...
fim
wasmerio/wasmer
rust
<|fim_suffix|> return 0; } dummy.byte_length / WASM_PAGE_SIZE as u32 } /// Attempts to clone this memory (if its cloneable) pub(crate) fn try_clone(&self) -> Result<Self, MemoryError> { Ok(self.clone()) } /// Copies this memory to a new memory pub fn copy(&self) -...
fim
wasmerio/wasmer
rust
<|fim_prefix|>pub(crate) mod external; pub(crate) mod function; pub(crate) mod global; pub(crate) mod memory; pub(crate) mod table; pub(crate) mod tag; pub use super::error::Trap; pub use external::*; pub use function::*; pub use global::*; pub use memory::*; pub use table::*; pub use tag::*; /// The type of instance...
fim
wasmerio/wasmer
rust
use js_sys::WebAssembly::Table as JsTable; use wasmer_types::TableType; /// The VM Table type #[derive(Clone, Debug, PartialEq, Eq)] pub struct VMTable { pub(crate) table: JsTable, pub(crate) ty: TableType, } unsafe impl Send for VMTable {} unsafe impl Sync for VMTable {} impl VMTable { pub(crate) fn new...
fim
wasmerio/wasmer
rust
<|fim_suffix|>lf { tag, ty } } } unsafe impl Send for VMTag {} unsafe impl Sync for VMTag {} <|fim_prefix|>use js_sys::WebAssembly::Tag as JsTag; use wasmer_types::TagType; /// The VM Tag type #[derive(Clone, Debug, PartialEq, Eq)] pub struct VMTag { pub(crate) tag: JsTag, pub(crate) ty: TagType, } impl ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>{ return Self::Js; } panic!("No runtime enabled!") } } <|fim_prefix|>//! This submodule has the concrete definitions for all the available implenters of the WebAssembly //! types needed to create a runtime. #[cfg(feature = "sys")] pub mod sys; #[cfg(feature = "v8")] pub ...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use std::{ cell::RefCell, collections::HashMap, future::Future, marker::PhantomData, pin::Pin, ptr, rc::Rc, sync::{LazyLock, atomic::AtomicU64}, task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, }; use corosensei::{Coroutine, CoroutineResult, Yielder}; use dashma...
fim
wasmerio/wasmer
rust
<|fim_suffix|>d Tunable of this engine fn tunables(&self) -> &dyn Tunables; /// Compile a module from bytes with a progress callback. /// /// The callback is invoked with progress updates during the compilation process. /// The callback also may return an error to abort the compilation. /// ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>rate() .map(|(i, v)| { if v.ty() != tag_ty[i] { panic!("payload type mismatch"); } v.as_raw(store) }) .collect::<Vec<_>>() .into_boxed_slice(); let ctx = store.objects_mut().as_sys_...
fim
wasmerio/wasmer
rust
<|fim_suffix|> pub(crate) unsafe fn from_vm_externref( store: &mut impl AsStoreMut, vm_externref: VMExternRef, ) -> Self { Self { handle: unsafe { StoreHandle::from_internal(store.objects_mut().id(), vm_externref.0) }, } } /// Checks whether this `ExternRef` can...
fim
wasmerio/wasmer
rust
<|fim_prefix|>use std::{any::Any, fmt::Debug, marker::PhantomData}; #[cfg(feature = "experimental-async")] use crate::{AsStoreAsync, StoreAsync, StoreAsyncReadLock, StoreAsyncWriteLock}; use crate::{ Store, StoreContext, StoreInner, StoreMut, StorePtrWrapper, store::{AsStoreMut, AsStoreRef, StoreRef}, }; use ...
fim
wasmerio/wasmer
rust
<|fim_suffix|>rupted(store.objects.id()) { raise_lib_trap(Trap::lib(TrapCode::HostInterrupt)) } wasmer_vm::libcalls::throw( store.objects.as_sys(), exception.vm_exceptionref().unwrap_sys_r...
fim
wasmerio/wasmer
rust
#[cfg(feature = "experimental-host-interrupt")] use crate::backend::sys::vm::interrupt_registry; use crate::backend::sys::{ engine::NativeEngineExt, vm::{Trap, TrapCode}, }; use crate::{ FromToNativeWasmType, Function, NativeWasmTypeInto, RuntimeError, StoreContext, TypedFunction, Value, WasmTypeList, ...
fim
wasmerio/wasmer
rust
<|fim_suffix|> is_from_store(&self, store: &impl AsStoreRef) -> bool { self.handle.store_id() == store.as_store_ref().objects().id() } pub(crate) fn to_vm_extern(&self) -> VMExtern { VMExtern::Sys(wasmer_vm::VMExtern::Global(self.handle.internal_handle())) } } impl std::cmp::PartialEq for ...
fim
wasmerio/wasmer
rust