diff options
| author | Martin <mhaug@live.de> | 2021-08-18 18:12:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-18 18:12:26 +0200 |
| commit | c44ecbfbd2706bf8e09728f2c85135aa2299d542 (patch) | |
| tree | 1a7fe1b7f1627ed63817030468476ef4a5dc2b9e /src | |
| parent | 011865ab5c8943abcb64c7b545e265d1a65db32a (diff) | |
Move to exclusively oneshot benchmarks with Iai fork (#41)
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -49,7 +49,8 @@ pub mod util; use std::rc::Rc; use crate::diag::TypResult; -use crate::eval::{Scope, State}; +use crate::eval::{Scope, State, Module}; +use crate::syntax::SyntaxTree; use crate::font::FontStore; use crate::image::ImageStore; #[cfg(feature = "layout-cache")] @@ -88,11 +89,30 @@ impl Context { ContextBuilder::default() } + /// A read-only reference to the standard library scope. + pub fn std(&self) -> &Scope { + &self.std + } + + /// A read-only reference to the state. + pub fn state(&self) -> &State { + &self.state + } + + /// Parse a source file and return the resulting syntax tree. + pub fn parse(&mut self, id: SourceId) -> TypResult<SyntaxTree> { + parse::parse(self.sources.get(id)) + } + + /// Evaluate a source file and return the resulting module. + pub fn evaluate(&mut self, id: SourceId) -> TypResult<Module> { + let ast = self.parse(id)?; + eval::eval(self, id, &ast) + } + /// Execute a source file and produce the resulting layout tree. pub fn execute(&mut self, id: SourceId) -> TypResult<LayoutTree> { - let source = self.sources.get(id); - let ast = parse::parse(source)?; - let module = eval::eval(self, id, &ast)?; + let module = self.evaluate(id)?; Ok(module.template.to_tree(&self.state)) } |
