mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
repl: rename Wasm32TestResult -> Wasm32Result
This commit is contained in:
parent
1783fa8009
commit
c5ccc99e20
3 changed files with 42 additions and 42 deletions
|
@ -5,8 +5,8 @@ mod storage;
|
||||||
pub mod wasm_module;
|
pub mod wasm_module;
|
||||||
|
|
||||||
// Helpers for interfacing to a Wasm module from outside
|
// Helpers for interfacing to a Wasm module from outside
|
||||||
|
pub mod wasm32_result;
|
||||||
pub mod wasm32_sized;
|
pub mod wasm32_sized;
|
||||||
pub mod wasm32_test_result;
|
|
||||||
|
|
||||||
use bumpalo::{self, collections::Vec, Bump};
|
use bumpalo::{self, collections::Vec, Bump};
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ use crate::wasm_module::{
|
||||||
};
|
};
|
||||||
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
||||||
|
|
||||||
pub trait Wasm32TestResult {
|
pub trait Wasm32Result {
|
||||||
fn insert_test_wrapper<'a>(
|
fn insert_wrapper<'a>(
|
||||||
arena: &'a bumpalo::Bump,
|
arena: &'a bumpalo::Bump,
|
||||||
module: &mut WasmModule<'a>,
|
module: &mut WasmModule<'a>,
|
||||||
wrapper_name: &str,
|
wrapper_name: &str,
|
||||||
|
@ -64,9 +64,9 @@ macro_rules! build_wrapper_body_primitive {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wasm_test_result_primitive {
|
macro_rules! wasm_result_primitive {
|
||||||
($type_name: ident, $store_instruction: ident, $align: expr) => {
|
($type_name: ident, $store_instruction: ident, $align: expr) => {
|
||||||
impl Wasm32TestResult for $type_name {
|
impl Wasm32Result for $type_name {
|
||||||
build_wrapper_body_primitive!($store_instruction, $align);
|
build_wrapper_body_primitive!($store_instruction, $align);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -89,9 +89,9 @@ fn build_wrapper_body_stack_memory(
|
||||||
code_builder.build_fn_header_and_footer(local_types, size as i32, frame_pointer);
|
code_builder.build_fn_header_and_footer(local_types, size as i32, frame_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wasm_test_result_stack_memory {
|
macro_rules! wasm_result_stack_memory {
|
||||||
($type_name: ident) => {
|
($type_name: ident) => {
|
||||||
impl Wasm32TestResult for $type_name {
|
impl Wasm32Result for $type_name {
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
|
@ -103,47 +103,47 @@ macro_rules! wasm_test_result_stack_memory {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_test_result_primitive!(bool, i32_store8, Align::Bytes1);
|
wasm_result_primitive!(bool, i32_store8, Align::Bytes1);
|
||||||
wasm_test_result_primitive!(RocOrder, i32_store8, Align::Bytes1);
|
wasm_result_primitive!(RocOrder, i32_store8, Align::Bytes1);
|
||||||
|
|
||||||
wasm_test_result_primitive!(u8, i32_store8, Align::Bytes1);
|
wasm_result_primitive!(u8, i32_store8, Align::Bytes1);
|
||||||
wasm_test_result_primitive!(i8, i32_store8, Align::Bytes1);
|
wasm_result_primitive!(i8, i32_store8, Align::Bytes1);
|
||||||
wasm_test_result_primitive!(u16, i32_store16, Align::Bytes2);
|
wasm_result_primitive!(u16, i32_store16, Align::Bytes2);
|
||||||
wasm_test_result_primitive!(i16, i32_store16, Align::Bytes2);
|
wasm_result_primitive!(i16, i32_store16, Align::Bytes2);
|
||||||
wasm_test_result_primitive!(u32, i32_store, Align::Bytes4);
|
wasm_result_primitive!(u32, i32_store, Align::Bytes4);
|
||||||
wasm_test_result_primitive!(i32, i32_store, Align::Bytes4);
|
wasm_result_primitive!(i32, i32_store, Align::Bytes4);
|
||||||
wasm_test_result_primitive!(u64, i64_store, Align::Bytes8);
|
wasm_result_primitive!(u64, i64_store, Align::Bytes8);
|
||||||
wasm_test_result_primitive!(i64, i64_store, Align::Bytes8);
|
wasm_result_primitive!(i64, i64_store, Align::Bytes8);
|
||||||
wasm_test_result_primitive!(usize, i32_store, Align::Bytes4);
|
wasm_result_primitive!(usize, i32_store, Align::Bytes4);
|
||||||
|
|
||||||
wasm_test_result_primitive!(f32, f32_store, Align::Bytes4);
|
wasm_result_primitive!(f32, f32_store, Align::Bytes4);
|
||||||
wasm_test_result_primitive!(f64, f64_store, Align::Bytes8);
|
wasm_result_primitive!(f64, f64_store, Align::Bytes8);
|
||||||
|
|
||||||
wasm_test_result_stack_memory!(u128);
|
wasm_result_stack_memory!(u128);
|
||||||
wasm_test_result_stack_memory!(i128);
|
wasm_result_stack_memory!(i128);
|
||||||
wasm_test_result_stack_memory!(RocDec);
|
wasm_result_stack_memory!(RocDec);
|
||||||
wasm_test_result_stack_memory!(RocStr);
|
wasm_result_stack_memory!(RocStr);
|
||||||
|
|
||||||
impl<T: Wasm32TestResult> Wasm32TestResult for RocList<T> {
|
impl<T: Wasm32Result> Wasm32Result for RocList<T> {
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
build_wrapper_body_stack_memory(code_builder, main_function_index, 12)
|
build_wrapper_body_stack_memory(code_builder, main_function_index, 12)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Wasm32TestResult> Wasm32TestResult for &'_ T {
|
impl<T: Wasm32Result> Wasm32Result for &'_ T {
|
||||||
build_wrapper_body_primitive!(i32_store, Align::Bytes4);
|
build_wrapper_body_primitive!(i32_store, Align::Bytes4);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, const N: usize> Wasm32TestResult for [T; N]
|
impl<T, const N: usize> Wasm32Result for [T; N]
|
||||||
where
|
where
|
||||||
T: Wasm32TestResult + Wasm32Sized,
|
T: Wasm32Result + Wasm32Sized,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
build_wrapper_body_stack_memory(code_builder, main_function_index, N * T::ACTUAL_WIDTH)
|
build_wrapper_body_stack_memory(code_builder, main_function_index, N * T::ACTUAL_WIDTH)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wasm32TestResult for () {
|
impl Wasm32Result for () {
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
// Main's symbol index is the same as its function index, since the first symbols we created were for procs
|
// Main's symbol index is the same as its function index, since the first symbols we created were for procs
|
||||||
let main_symbol_index = main_function_index;
|
let main_symbol_index = main_function_index;
|
||||||
|
@ -153,10 +153,10 @@ impl Wasm32TestResult for () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, U> Wasm32TestResult for (T, U)
|
impl<T, U> Wasm32Result for (T, U)
|
||||||
where
|
where
|
||||||
T: Wasm32TestResult + Wasm32Sized,
|
T: Wasm32Result + Wasm32Sized,
|
||||||
U: Wasm32TestResult + Wasm32Sized,
|
U: Wasm32Result + Wasm32Sized,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
|
@ -167,11 +167,11 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, U, V> Wasm32TestResult for (T, U, V)
|
impl<T, U, V> Wasm32Result for (T, U, V)
|
||||||
where
|
where
|
||||||
T: Wasm32TestResult + Wasm32Sized,
|
T: Wasm32Result + Wasm32Sized,
|
||||||
U: Wasm32TestResult + Wasm32Sized,
|
U: Wasm32Result + Wasm32Sized,
|
||||||
V: Wasm32TestResult + Wasm32Sized,
|
V: Wasm32Result + Wasm32Sized,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_function_index: u32) {
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
|
@ -9,7 +9,7 @@ use wasmer::{Memory, WasmPtr};
|
||||||
use crate::helpers::from_wasmer_memory::FromWasmerMemory;
|
use crate::helpers::from_wasmer_memory::FromWasmerMemory;
|
||||||
use roc_can::builtins::builtin_defs_map;
|
use roc_can::builtins::builtin_defs_map;
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::{MutMap, MutSet};
|
||||||
use roc_gen_wasm::wasm32_test_result::Wasm32TestResult;
|
use roc_gen_wasm::wasm32_result::Wasm32Result;
|
||||||
use roc_gen_wasm::{DEBUG_LOG_SETTINGS, MEMORY_NAME};
|
use roc_gen_wasm::{DEBUG_LOG_SETTINGS, MEMORY_NAME};
|
||||||
|
|
||||||
// Should manually match build.rs
|
// Should manually match build.rs
|
||||||
|
@ -40,7 +40,7 @@ pub enum TestType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn compile_and_load<'a, T: Wasm32TestResult>(
|
pub fn compile_and_load<'a, T: Wasm32Result>(
|
||||||
arena: &'a bumpalo::Bump,
|
arena: &'a bumpalo::Bump,
|
||||||
src: &str,
|
src: &str,
|
||||||
stdlib: &'a roc_builtins::std::StdLib,
|
stdlib: &'a roc_builtins::std::StdLib,
|
||||||
|
@ -72,7 +72,7 @@ fn src_hash(src: &str) -> u64 {
|
||||||
hash_state.finish()
|
hash_state.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>(
|
fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
|
||||||
arena: &'a bumpalo::Bump,
|
arena: &'a bumpalo::Bump,
|
||||||
stdlib: &'a roc_builtins::std::StdLib,
|
stdlib: &'a roc_builtins::std::StdLib,
|
||||||
preload_bytes: &[u8],
|
preload_bytes: &[u8],
|
||||||
|
@ -138,7 +138,7 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32TestResult>(
|
||||||
procedures,
|
procedures,
|
||||||
);
|
);
|
||||||
|
|
||||||
T::insert_test_wrapper(arena, &mut module, TEST_WRAPPER_NAME, main_fn_index);
|
T::insert_wrapper(arena, &mut module, TEST_WRAPPER_NAME, main_fn_index);
|
||||||
|
|
||||||
// Export the initialiser function for refcount tests
|
// Export the initialiser function for refcount tests
|
||||||
let init_refcount_bytes = INIT_REFCOUNT_NAME.as_bytes();
|
let init_refcount_bytes = INIT_REFCOUNT_NAME.as_bytes();
|
||||||
|
@ -193,7 +193,7 @@ fn load_bytes_into_runtime(bytes: Vec<u8>) -> wasmer::Instance {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn assert_wasm_evals_to_help<T>(src: &str, phantom: PhantomData<T>) -> Result<T, String>
|
pub fn assert_wasm_evals_to_help<T>(src: &str, phantom: PhantomData<T>) -> Result<T, String>
|
||||||
where
|
where
|
||||||
T: FromWasmerMemory + Wasm32TestResult,
|
T: FromWasmerMemory + Wasm32Result,
|
||||||
{
|
{
|
||||||
let arena = bumpalo::Bump::new();
|
let arena = bumpalo::Bump::new();
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ pub fn assert_wasm_refcounts_help<T>(
|
||||||
num_refcounts: usize,
|
num_refcounts: usize,
|
||||||
) -> Result<Vec<u32>, String>
|
) -> Result<Vec<u32>, String>
|
||||||
where
|
where
|
||||||
T: FromWasmerMemory + Wasm32TestResult,
|
T: FromWasmerMemory + Wasm32Result,
|
||||||
{
|
{
|
||||||
let arena = bumpalo::Bump::new();
|
let arena = bumpalo::Bump::new();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue