1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pub mod alloc;
pub mod compiled;
pub mod executor;
pub mod insc;
pub mod stack;
#[cfg(test)] pub mod test;
#[cfg(any(test, feature = "bench"))] pub mod test_program;
use std::ptr::NonNull;
use xjbutil::wide_ptr::WidePointer;
use crate::ffi::sync_fn::VMContext;
use crate::vm::al31f::alloc::Alloc;
#[cfg(feature = "async")] use crate::ffi::async_fn::AsyncVMContext;
#[cfg(feature = "async")] use crate::util::serializer::{CoroutineSharedData, Serializer};
pub struct AL31F<A: Alloc> {
pub alloc: A
}
impl<A: Alloc> AL31F<A> {
pub fn new(alloc: A) -> Self {
Self { alloc }
}
}
pub struct Combustor<A: Alloc> {
vm: NonNull<AL31F<A>>
}
impl<A: Alloc> Combustor<A> {
pub fn new(vm: NonNull<AL31F<A>>) -> Self {
Self { vm }
}
}
impl<A: Alloc> VMContext for Combustor<A> {
fn allocate(&mut self, wide_ptr: WidePointer) {
unsafe { self.vm.as_mut().alloc.add_managed(wide_ptr); }
}
fn mark(&mut self, wide_ptr: WidePointer) {
unsafe { self.vm.as_mut().alloc.mark_object(wide_ptr); }
}
}
#[cfg(feature = "async")]
pub struct AsyncCombustor<A: Alloc> {
vm: Serializer<(CoroutineSharedData, AL31F<A>)>
}
#[cfg(feature = "async")]
impl<A: Alloc> AsyncCombustor<A> {
pub fn new(vm: Serializer<(CoroutineSharedData, AL31F<A>)>) -> Self {
Self { vm }
}
}
#[cfg(feature = "async")]
unsafe impl<A: Alloc> Send for AsyncCombustor<A> {}
#[cfg(feature = "async")]
unsafe impl<A: Alloc> Sync for AsyncCombustor<A> {}
#[cfg(feature = "async")]
impl<A: Alloc> AsyncVMContext for AsyncCombustor<A> {
type VMData = AL31F<A>;
fn serializer(&self) -> &Serializer<(CoroutineSharedData, Self::VMData)> {
&self.vm
}
}