summaryrefslogtreecommitdiff
path: root/src/model/vm.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-24 17:39:08 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-24 17:41:41 +0100
commit8d3c68a1deb28dce2b80ed61f85141180ce6a951 (patch)
treede007203d448d6b6a2df7838e802f85d23ccd1a6 /src/model/vm.rs
parent5ae81971f299688b05d77af208d7bb44ffce5e2d (diff)
Protect Vm
Diffstat (limited to 'src/model/vm.rs')
-rw-r--r--src/model/vm.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/model/vm.rs b/src/model/vm.rs
index d13be29c..d3509eae 100644
--- a/src/model/vm.rs
+++ b/src/model/vm.rs
@@ -9,19 +9,22 @@ use crate::util::PathExt;
use crate::World;
/// A virtual machine.
+///
+/// Holds the state needed to evaluate Typst sources. A new virtual machine is
+/// created for each module evaluation and function call.
pub struct Vm<'a> {
/// The core context.
- pub world: Tracked<'a, dyn World>,
+ pub(crate) world: Tracked<'a, dyn World>,
/// The route of source ids the VM took to reach its current location.
- pub route: Tracked<'a, Route>,
+ pub(crate) route: Tracked<'a, Route>,
/// The current location.
- pub location: SourceId,
+ pub(crate) location: SourceId,
/// The stack of scopes.
- pub scopes: Scopes<'a>,
+ pub(crate) scopes: Scopes<'a>,
/// A control flow event that is currently happening.
- pub flow: Option<Flow>,
+ pub(crate) flow: Option<Flow>,
/// The language items.
- pub items: LangItems,
+ pub(crate) items: LangItems,
}
impl<'a> Vm<'a> {
@@ -42,6 +45,11 @@ impl<'a> Vm<'a> {
}
}
+ /// Access the underlying world.
+ pub fn world(&self) -> Tracked<dyn World> {
+ self.world
+ }
+
/// Resolve a user-entered path to be relative to the compilation
/// environment's root.
pub fn locate(&self, path: &str) -> StrResult<PathBuf> {