diff options
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 65b21e22..b7cac1ee 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -229,12 +229,11 @@ fn compile(command: CompileCommand) -> StrResult<()> { /// Compile a single time. fn compile_once(world: &mut SystemWorld, command: &CompileCommand) -> StrResult<()> { status(command, Status::Compiling).unwrap(); - world.reset(); - let main = world.resolve(&command.input).map_err(|err| err.to_string())?; - let source = world.source(main); + world.reset(); + world.main = world.resolve(&command.input).map_err(|err| err.to_string())?; - match typst::compile(world, source) { + match typst::compile(world) { // Export the PDF. Ok(document) => { let buffer = typst::export::pdf(&document); @@ -372,6 +371,7 @@ struct SystemWorld { hashes: RefCell<HashMap<PathBuf, FileResult<PathHash>>>, paths: RefCell<HashMap<PathHash, PathSlot>>, sources: FrozenVec<Box<Source>>, + main: SourceId, } /// Holds details about the location of a font and lazily the font itself. @@ -401,6 +401,7 @@ impl SystemWorld { hashes: RefCell::default(), paths: RefCell::default(), sources: FrozenVec::new(), + main: SourceId::detached(), } } } @@ -414,6 +415,25 @@ impl World for SystemWorld { &self.library } + fn main(&self) -> &Source { + self.source(self.main) + } + + fn resolve(&self, path: &Path) -> FileResult<SourceId> { + self.slot(path)? + .source + .get_or_init(|| { + let buf = read(path)?; + let text = String::from_utf8(buf)?; + Ok(self.insert(path, text)) + }) + .clone() + } + + fn source(&self, id: SourceId) -> &Source { + &self.sources[id.into_u16() as usize] + } + fn book(&self) -> &Prehashed<FontBook> { &self.book } @@ -434,21 +454,6 @@ impl World for SystemWorld { .get_or_init(|| read(path).map(Buffer::from)) .clone() } - - fn resolve(&self, path: &Path) -> FileResult<SourceId> { - self.slot(path)? - .source - .get_or_init(|| { - let buf = read(path)?; - let text = String::from_utf8(buf)?; - Ok(self.insert(path, text)) - }) - .clone() - } - - fn source(&self, id: SourceId) -> &Source { - &self.sources[id.into_u16() as usize] - } } impl SystemWorld { |
