summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-09 11:06:37 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-09 11:26:41 +0200
commit3932bb2cb93be95d67fc56998423eb9ce047fdfa (patch)
treec36bd4df1d2c74f8ae100d2f3bd3a0b232b797f5 /src/lib.rs
parent3c92bad9a7cd6b880de197806443ffcce2cac9d8 (diff)
New source loading architecture
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0f556989..7447dad7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,26 +53,26 @@ use std::rc::Rc;
use crate::diag::TypResult;
use crate::eval::{ModuleCache, Scope};
use crate::exec::State;
-use crate::font::FontCache;
-use crate::image::ImageCache;
+use crate::font::FontStore;
+use crate::image::ImageStore;
use crate::layout::Frame;
#[cfg(feature = "layout-cache")]
use crate::layout::LayoutCache;
use crate::loading::Loader;
-use crate::source::{SourceFile, SourceMap};
+use crate::source::{SourceId, SourceStore};
/// The core context which holds the loader, configuration and cached artifacts.
pub struct Context {
/// The loader the context was created with.
pub loader: Rc<dyn Loader>,
/// Stores loaded source files.
- pub sources: SourceMap,
+ pub sources: SourceStore,
+ /// Stores parsed font faces.
+ pub fonts: FontStore,
+ /// Stores decoded images.
+ pub images: ImageStore,
/// Caches evaluated modules.
pub modules: ModuleCache,
- /// Caches parsed font faces.
- pub fonts: FontCache,
- /// Caches decoded images.
- pub images: ImageCache,
/// Caches layouting artifacts.
#[cfg(feature = "layout-cache")]
pub layouts: LayoutCache,
@@ -93,24 +93,25 @@ impl Context {
ContextBuilder::default()
}
- /// Garbage-collect caches.
- pub fn turnaround(&mut self) {
- #[cfg(feature = "layout-cache")]
- self.layouts.turnaround();
- }
-
/// Typeset a source file into a collection of layouted frames.
///
/// Returns either a vector of frames representing individual pages or
/// diagnostics in the form of a vector of error message with file and span
/// information.
- pub fn typeset(&mut self, source: &SourceFile) -> TypResult<Vec<Rc<Frame>>> {
+ pub fn typeset(&mut self, id: SourceId) -> TypResult<Vec<Rc<Frame>>> {
+ let source = self.sources.get(id);
let ast = parse::parse(source)?;
- let module = eval::eval(self, source.file(), Rc::new(ast))?;
+ let module = eval::eval(self, id, Rc::new(ast))?;
let tree = exec::exec(self, &module.template);
let frames = layout::layout(self, &tree);
Ok(frames)
}
+
+ /// Garbage-collect caches.
+ pub fn turnaround(&mut self) {
+ #[cfg(feature = "layout-cache")]
+ self.layouts.turnaround();
+ }
}
/// A builder for a [`Context`].
@@ -140,10 +141,10 @@ impl ContextBuilder {
/// fonts, images, source files and other resources.
pub fn build(self, loader: Rc<dyn Loader>) -> Context {
Context {
- loader: Rc::clone(&loader),
- sources: SourceMap::new(),
- fonts: FontCache::new(Rc::clone(&loader)),
- images: ImageCache::new(loader),
+ sources: SourceStore::new(Rc::clone(&loader)),
+ fonts: FontStore::new(Rc::clone(&loader)),
+ images: ImageStore::new(Rc::clone(&loader)),
+ loader,
modules: ModuleCache::new(),
#[cfg(feature = "layout-cache")]
layouts: LayoutCache::new(),