nanvm_lib/vm/internal/mod.rs
1mod icomplex;
2mod icontainer;
3mod ifunction;
4mod istatic_function;
5
6pub use icomplex::IComplex;
7pub use icontainer::IContainer;
8pub use ifunction::IFunction;
9pub use istatic_function::{IStaticFunction, StaticCode};
10
11use crate::{
12 sign::Sign,
13 vm::{Any, Array, Function, Property, Unpacked},
14};
15
16/// A VM's value representation.
17///
18/// A VM is built from an [`Unpacked`] value alone, so a number reaches it
19/// only as a [`Number`](crate::vm::Number), which holds one `NaN` by
20/// construction — there is no `From<f64>` here on purpose — so a NaN-boxing
21/// VM, which reads a negative quiet `NaN` as a boxed value, can store its
22/// bits as they are.
23///
24/// A VM is `'static`: a type with no lifetime, which a function's text
25/// names behind a `'static` reference. The runtime is not the VM's to
26/// bind: it is a value, [`runtime`](crate::vm::runtime), built once by
27/// whoever runs compiled modules and handed to each as its parameter, for
28/// any VM.
29pub trait IVm: Sized + Clone + From<Unpacked<Self>> + 'static {
30 // types
31 type InternalString: IContainer<Self, Header = (), Item = u16>;
32 type InternalBigInt: IContainer<Self, Header = Sign, Item = u64>;
33 type InternalObject: IContainer<Self, Header = (), Item = Property<Self>>;
34 type InternalArray: IContainer<Self, Header = (), Item = Any<Self>>;
35 type InternalFunction: IFunction<Self>;
36 // functions
37 fn to_unpacked(self) -> Unpacked<Self>;
38 /// A function made out of a Rust static function, [`StaticCode`], over
39 /// the frame it captures: what every closure of a compiled module is,
40 /// and what the runtime's member functions answer, a closure over the
41 /// receiver, which is why the capability is every VM's and not a
42 /// capability apart ([`IStaticFunction`] names it). `text` is the
43 /// function's text, what `String(f)` answers: the compiler renders it
44 /// from the function's EDAG, one `&'static str` per arrow in the source,
45 /// shared by every function the arrow makes. `None` is a function with
46 /// no text — a host or hand-written one, with no EDAG, or one whose body
47 /// the renderer cannot spell yet — whose conversion to a string is
48 /// refused.
49 fn static_function(
50 code: StaticCode<Self>,
51 length: u32,
52 frame: Array<Self>,
53 text: Option<&'static str>,
54 ) -> Function<Self>;
55 /// The frame `static_function` was given, read by the code through its `self_`.
56 fn frame(self_: &Self::InternalFunction) -> &Array<Self>;
57}