pr47/vm/al31f/
compiled.rs

1use std::any::TypeId;
2use std::ptr::NonNull;
3
4use crate::data::Value;
5use crate::data::tyck::TyckInfo;
6use crate::ffi::sync_fn::Function as FFIFunction;
7use crate::vm::al31f::Combustor;
8use crate::vm::al31f::alloc::Alloc;
9use crate::vm::al31f::insc::Insc;
10
11#[cfg(feature = "async")] use crate::ffi::async_fn::AsyncFunction as FFIAsyncFunction;
12#[cfg(feature = "async")] use crate::vm::al31f::AsyncCombustor;
13
14pub struct ExceptionHandlingBlock {
15    pub insc_ptr_range: (usize, usize),
16    pub exception_id: TypeId,
17    pub handler_addr: usize
18}
19
20impl ExceptionHandlingBlock {
21    pub fn new(
22        insc_ptr_start: usize,
23        insc_ptr_end: usize,
24        exception_id: TypeId,
25        handler_addr: usize
26    ) -> Self {
27        Self {
28            insc_ptr_range: (insc_ptr_start, insc_ptr_end),
29            exception_id,
30            handler_addr
31        }
32    }
33}
34
35pub struct CompiledFunction {
36    pub start_addr: usize,
37    pub arg_count: usize,
38    pub ret_count: usize,
39    pub stack_size: usize,
40
41    pub param_tyck_info: Box<[Option<NonNull<TyckInfo>>]>,
42    pub exc_handlers: Option<Box<[ExceptionHandlingBlock]>>
43}
44
45impl CompiledFunction {
46    pub fn new(
47        start_addr: usize,
48        arg_count: usize,
49        ret_count: usize,
50        stack_size: usize,
51        param_tyck_info: Box<[Option<NonNull<TyckInfo>>]>
52    ) -> Self {
53        Self {
54            start_addr,
55            arg_count,
56            ret_count,
57            stack_size,
58            param_tyck_info,
59            exc_handlers: None
60        }
61    }
62
63    pub fn new_with_exc(
64        start_addr: usize,
65        arg_count: usize,
66        ret_count: usize,
67        stack_size: usize,
68        param_tyck_info: Box<[Option<NonNull<TyckInfo>>]>,
69        exc_handlers: Box<[ExceptionHandlingBlock]>
70    ) -> Self {
71        Self {
72            start_addr,
73            arg_count,
74            ret_count,
75            stack_size,
76            param_tyck_info,
77            exc_handlers: Some(exc_handlers)
78        }
79    }
80}
81
82pub struct CompiledProgram<A: Alloc> {
83    pub code: Box<[Insc]>,
84    pub const_pool: Box<[Value]>,
85    pub init_proc: usize,
86    pub functions: Box<[CompiledFunction]>,
87
88    pub ffi_funcs: Box<[Box<dyn FFIFunction<Combustor<A>>>]>,
89    #[cfg(feature = "async")]
90    pub async_ffi_funcs: Box<[Box<dyn FFIAsyncFunction<AsyncCombustor<A>>>]>
91}