Skip to content

Commit b8a4a94

Browse files
committed
refactor: enhance existing crates with new functionality integration
Update and improve existing crate implementations to integrate with new component model and advanced instruction support: - Enhanced component adapter and async execution support - Improved memory management and type handling - Updated instruction implementations with new operation support - Refined runtime execution and memory adapters - Enhanced validation and error handling across modules - Improved no_std compatibility and bounded collections - Updated build configurations and dependencies These changes ensure seamless integration of new features while maintaining backward compatibility and improving overall performance.
1 parent f6d7a3f commit b8a4a94

File tree

118 files changed

+10903
-4611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+10903
-4611
lines changed

wrt-component/src/adapter.rs

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use std::{fmt, mem};
1212
use alloc::{boxed::Box, string::String, vec::Vec};
1313

1414
use wrt_foundation::{
15-
bounded::BoundedVec,
16-
component::ComponentType,
17-
component_value::ComponentValue,
18-
prelude::*,
15+
bounded::BoundedVec, component::ComponentType, component_value::ComponentValue, prelude::*,
1916
};
2017

2118
use crate::{
@@ -37,25 +34,25 @@ pub struct CoreModuleAdapter {
3734
pub name: String,
3835
#[cfg(not(any(feature = "std", feature = "alloc")))]
3936
pub name: BoundedString<64>,
40-
37+
4138
/// Function adapters
4239
#[cfg(any(feature = "std", feature = "alloc"))]
4340
pub functions: Vec<FunctionAdapter>,
4441
#[cfg(not(any(feature = "std", feature = "alloc")))]
4542
pub functions: BoundedVec<FunctionAdapter, MAX_ADAPTED_FUNCTIONS>,
46-
43+
4744
/// Memory adapters
4845
#[cfg(any(feature = "std", feature = "alloc"))]
4946
pub memories: Vec<MemoryAdapter>,
5047
#[cfg(not(any(feature = "std", feature = "alloc")))]
5148
pub memories: BoundedVec<MemoryAdapter, 16>,
52-
49+
5350
/// Table adapters
5451
#[cfg(any(feature = "std", feature = "alloc"))]
5552
pub tables: Vec<TableAdapter>,
5653
#[cfg(not(any(feature = "std", feature = "alloc")))]
5754
pub tables: BoundedVec<TableAdapter, 16>,
58-
55+
5956
/// Global adapters
6057
#[cfg(any(feature = "std", feature = "alloc"))]
6158
pub globals: Vec<GlobalAdapter>,
@@ -347,18 +344,21 @@ impl CoreModuleAdapter {
347344
AdaptationMode::Lift => {
348345
// Lower component args to core args, call, then lift result
349346
let core_args = self.lower_args_to_core(args, &adapter.core_signature)?;
350-
let core_result = self.call_core_function_direct(adapter.core_index, &core_args, engine)?;
347+
let core_result =
348+
self.call_core_function_direct(adapter.core_index, &core_args, engine)?;
351349
self.lift_result_to_component(core_result, &adapter.component_signature)
352350
}
353351
AdaptationMode::Lower => {
354352
// Already have core args, call directly
355-
let core_result = self.call_core_function_direct(adapter.core_index, args, engine)?;
353+
let core_result =
354+
self.call_core_function_direct(adapter.core_index, args, engine)?;
356355
self.lift_result_to_component(core_result, &adapter.component_signature)
357356
}
358357
AdaptationMode::Bidirectional => {
359358
// Full bidirectional adaptation
360359
let core_args = self.lower_args_to_core(args, &adapter.core_signature)?;
361-
let core_result = self.call_core_function_direct(adapter.core_index, &core_args, engine)?;
360+
let core_result =
361+
self.call_core_function_direct(adapter.core_index, &core_args, engine)?;
362362
self.lift_result_to_component(core_result, &adapter.component_signature)
363363
}
364364
}
@@ -419,12 +419,7 @@ impl FunctionAdapter {
419419
core_signature: CoreFunctionSignature,
420420
mode: AdaptationMode,
421421
) -> Self {
422-
Self {
423-
core_index,
424-
component_signature,
425-
core_signature,
426-
mode,
427-
}
422+
Self { core_index, component_signature, core_signature, mode }
428423
}
429424

430425
/// Check if this adapter needs canonical ABI processing
@@ -475,9 +470,9 @@ impl CoreFunctionSignature {
475470
}
476471
#[cfg(not(any(feature = "std", feature = "alloc")))]
477472
{
478-
self.results.push(result_type).map_err(|_| {
479-
wrt_foundation::WrtError::ResourceExhausted("Too many results".into())
480-
})
473+
self.results
474+
.push(result_type)
475+
.map_err(|_| wrt_foundation::WrtError::ResourceExhausted("Too many results".into()))
481476
}
482477
}
483478
}
@@ -491,33 +486,21 @@ impl Default for CoreFunctionSignature {
491486
impl MemoryAdapter {
492487
/// Create a new memory adapter
493488
pub fn new(core_index: u32, min: u32, max: Option<u32>, shared: bool) -> Self {
494-
Self {
495-
core_index,
496-
limits: MemoryLimits { min, max },
497-
shared,
498-
}
489+
Self { core_index, limits: MemoryLimits { min, max }, shared }
499490
}
500491
}
501492

502493
impl TableAdapter {
503494
/// Create a new table adapter
504495
pub fn new(core_index: u32, element_type: CoreValType, min: u32, max: Option<u32>) -> Self {
505-
Self {
506-
core_index,
507-
element_type,
508-
limits: TableLimits { min, max },
509-
}
496+
Self { core_index, element_type, limits: TableLimits { min, max } }
510497
}
511498
}
512499

513500
impl GlobalAdapter {
514501
/// Create a new global adapter
515502
pub fn new(core_index: u32, global_type: CoreValType, mutable: bool) -> Self {
516-
Self {
517-
core_index,
518-
global_type,
519-
mutable,
520-
}
503+
Self { core_index, global_type, mutable }
521504
}
522505
}
523506

@@ -573,12 +556,8 @@ mod tests {
573556
core_sig.add_param(CoreValType::I32).unwrap();
574557
core_sig.add_result(CoreValType::I32).unwrap();
575558

576-
let adapter = FunctionAdapter::new(
577-
0,
578-
ComponentType::Unit,
579-
core_sig,
580-
AdaptationMode::Direct,
581-
);
559+
let adapter =
560+
FunctionAdapter::new(0, ComponentType::Unit, core_sig, AdaptationMode::Direct);
582561

583562
assert_eq!(adapter.core_index, 0);
584563
assert_eq!(adapter.mode, AdaptationMode::Direct);
@@ -624,4 +603,4 @@ mod tests {
624603
assert_eq!(adapter.global_type, CoreValType::I32);
625604
assert!(adapter.mutable);
626605
}
627-
}
606+
}

0 commit comments

Comments
 (0)