Split up model module

This commit is contained in:
Laurenz 2023-03-01 16:30:58 +01:00
parent ab841188e3
commit 6ab7760822
41 changed files with 150 additions and 155 deletions

View File

@ -18,8 +18,8 @@ use same_file::{is_same_file, Handle};
use siphasher::sip128::{Hasher128, SipHasher};
use termcolor::{ColorChoice, StandardStream, WriteColor};
use typst::diag::{FileError, FileResult, SourceError, StrResult};
use typst::eval::Library;
use typst::font::{Font, FontBook, FontInfo, FontVariant};
use typst::model::Library;
use typst::syntax::{Source, SourceId};
use typst::util::{Buffer, PathExt};
use typst::World;

View File

@ -15,9 +15,9 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_yaml as yaml;
use typst::doc::Frame;
use typst::eval::{CastInfo, Func, FuncInfo, Library, Module, ParamInfo, Value};
use typst::font::{Font, FontBook};
use typst::geom::{Abs, Sides, Smart};
use typst::model::{CastInfo, Func, FuncInfo, Library, Module, ParamInfo, Value};
use typst_library::layout::PageNode;
use unscanny::Scanner;
@ -43,7 +43,7 @@ static LIBRARY: Lazy<Prehashed<Library>> = Lazy::new(|| {
lib.styles.set(PageNode::HEIGHT, Smart::Auto);
lib.styles
.set(PageNode::MARGIN, Sides::splat(Some(Smart::Custom(Abs::pt(15.0).into()))));
typst::model::set_lang_items(lib.items.clone());
typst::eval::set_lang_items(lib.items.clone());
Prehashed::new(lib)
});
@ -630,7 +630,7 @@ fn symbol_page(resolver: &dyn Resolver, parent: &str, name: &str) -> PageModel {
.find(|&(_, x)| x == c)
.map(|(s, _)| s),
codepoint: c as u32,
accent: typst::model::combining_accent(c).is_some(),
accent: typst::eval::combining_accent(c).is_some(),
unicode_name: unicode_names2::name(c)
.map(|s| s.to_string().to_title_case()),
alternates: symbol

View File

@ -1,7 +1,7 @@
use std::cmp::Ordering;
use std::ops::Rem;
use typst::model::{Module, Scope};
use typst::eval::{Module, Scope};
use crate::prelude::*;

View File

@ -1,7 +1,7 @@
use std::str::FromStr;
use ecow::EcoVec;
use typst::model::Regex;
use typst::eval::Regex;
use crate::prelude::*;

View File

@ -137,5 +137,5 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> {
#[func]
pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?;
typst::model::eval_code_str(vm.world(), &text, span)
typst::eval::eval_code_str(vm.world(), &text, span)
}

View File

@ -10,8 +10,9 @@ pub mod symbols;
pub mod text;
pub mod visualize;
use typst::eval::{LangItems, Library, Module, Scope};
use typst::geom::{Align, Color, Dir, GenAlign};
use typst::model::{LangItems, Library, Module, Node, NodeId, Scope, StyleMap};
use typst::model::{Node, NodeId, StyleMap};
use self::layout::LayoutRoot;

View File

@ -1,4 +1,4 @@
use typst::model::combining_accent;
use typst::eval::combining_accent;
use super::*;

View File

@ -29,9 +29,9 @@ pub use self::style::*;
pub use self::underover::*;
use ttf_parser::{GlyphId, Rect};
use typst::font::Font;
use typst::font::FontWeight;
use typst::model::{Guard, Module, Scope, SequenceNode, StyledNode};
use typst::eval::{Module, Scope};
use typst::font::{Font, FontWeight};
use typst::model::{Guard, SequenceNode, StyledNode};
use unicode_math_class::MathClass;
use self::ctx::*;

View File

@ -1,4 +1,4 @@
use typst::model::Scope;
use typst::eval::Scope;
use super::*;

View File

@ -14,13 +14,17 @@ pub use typst::diag::{bail, error, At, SourceResult, StrResult};
#[doc(no_inline)]
pub use typst::doc::*;
#[doc(no_inline)]
pub use typst::eval::{
array, castable, dict, format_str, func, Args, Array, AutoValue, Cast, CastInfo,
Dict, Func, NoneValue, Str, Symbol, Value, Vm,
};
#[doc(no_inline)]
pub use typst::geom::*;
#[doc(no_inline)]
pub use typst::model::{
array, capability, capable, castable, dict, format_str, func, node, Args, Array,
AutoValue, Cast, CastInfo, Content, Dict, Finalize, Fold, Func, Introspector, Label,
Node, NodeId, NoneValue, Prepare, Resolve, Selector, Show, StabilityProvider, Str,
StyleChain, StyleMap, StyleVec, Symbol, Unlabellable, Value, Vm, Vt,
capability, capable, node, Content, Finalize, Fold, Introspector, Label, Node,
NodeId, Prepare, Resolve, Selector, Show, StabilityProvider, StyleChain, StyleMap,
StyleVec, Unlabellable, Vt,
};
#[doc(no_inline)]
pub use typst::syntax::{Span, Spanned};

View File

@ -1,4 +1,4 @@
use typst::model::{symbols, Module, Scope, Symbol};
use typst::eval::{symbols, Module, Scope, Symbol};
/// A module with all emoji.
pub fn emoji() -> Module {

View File

@ -1,4 +1,4 @@
use typst::model::{symbols, Module, Scope, Symbol};
use typst::eval::{symbols, Module, Scope, Symbol};
/// A module with all general symbols.
pub fn sym() -> Module {

View File

@ -18,20 +18,20 @@ pub fn castable(stream: TokenStream) -> Result<TokenStream> {
let describe_func = create_describe_func(&castable);
let dynamic_impls = castable.name.as_ref().map(|name| {
quote! {
impl ::typst::model::Type for #ty {
impl ::typst::eval::Type for #ty {
const TYPE_NAME: &'static str = #name;
}
impl From<#ty> for ::typst::model::Value {
impl From<#ty> for ::typst::eval::Value {
fn from(v: #ty) -> Self {
::typst::model::Value::Dyn(::typst::model::Dynamic::new(v))
::typst::eval::Value::Dyn(::typst::eval::Dynamic::new(v))
}
}
}
});
Ok(quote! {
impl ::typst::model::Cast for #ty {
impl ::typst::eval::Cast for #ty {
#is_func
#cast_func
#describe_func
@ -53,7 +53,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
}
Pattern::Ty(_, ty) => {
cast_checks.push(quote! {
if <#ty as ::typst::model::Cast>::is(value) {
if <#ty as ::typst::eval::Cast>::is(value) {
return true;
}
});
@ -63,7 +63,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
let dynamic_check = castable.name.is_some().then(|| {
quote! {
if let ::typst::model::Value::Dyn(dynamic) = &value {
if let ::typst::eval::Value::Dyn(dynamic) = &value {
if dynamic.is::<Self>() {
return true;
}
@ -73,7 +73,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
let str_check = (!string_arms.is_empty()).then(|| {
quote! {
if let ::typst::model::Value::Str(string) = &value {
if let ::typst::eval::Value::Str(string) = &value {
match string.as_str() {
#(#string_arms,)*
_ => {}
@ -83,7 +83,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
});
quote! {
fn is(value: &typst::model::Value) -> bool {
fn is(value: &::typst::eval::Value) -> bool {
#dynamic_check
#str_check
#(#cast_checks)*
@ -105,8 +105,8 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
}
Pattern::Ty(binding, ty) => {
cast_checks.push(quote! {
if <#ty as ::typst::model::Cast>::is(&value) {
let #binding = <#ty as ::typst::model::Cast>::cast(value)?;
if <#ty as ::typst::eval::Cast>::is(&value) {
let #binding = <#ty as ::typst::eval::Cast>::cast(value)?;
return Ok(#expr);
}
});
@ -116,7 +116,7 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
let dynamic_check = castable.name.is_some().then(|| {
quote! {
if let ::typst::model::Value::Dyn(dynamic) = &value {
if let ::typst::eval::Value::Dyn(dynamic) = &value {
if let Some(concrete) = dynamic.downcast::<Self>() {
return Ok(concrete.clone());
}
@ -126,7 +126,7 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
let str_check = (!string_arms.is_empty()).then(|| {
quote! {
if let ::typst::model::Value::Str(string) = &value {
if let ::typst::eval::Value::Str(string) = &value {
match string.as_str() {
#(#string_arms,)*
_ => {}
@ -136,11 +136,11 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
});
quote! {
fn cast(value: ::typst::model::Value) -> ::typst::diag::StrResult<Self> {
fn cast(value: ::typst::eval::Value) -> ::typst::diag::StrResult<Self> {
#dynamic_check
#str_check
#(#cast_checks)*
<Self as ::typst::model::Cast>::error(value)
<Self as ::typst::eval::Cast>::error(value)
}
}
}
@ -153,10 +153,10 @@ fn create_describe_func(castable: &Castable) -> TokenStream {
let docs = documentation(&cast.attrs);
infos.push(match &cast.pattern {
Pattern::Str(lit) => {
quote! { ::typst::model::CastInfo::Value(#lit.into(), #docs) }
quote! { ::typst::eval::CastInfo::Value(#lit.into(), #docs) }
}
Pattern::Ty(_, ty) => {
quote! { <#ty as ::typst::model::Cast>::describe() }
quote! { <#ty as ::typst::eval::Cast>::describe() }
}
});
}
@ -168,7 +168,7 @@ fn create_describe_func(castable: &Castable) -> TokenStream {
}
quote! {
fn describe() -> ::typst::model::CastInfo {
fn describe() -> ::typst::eval::CastInfo {
#(#infos)+*
}
}

View File

@ -21,7 +21,7 @@ pub fn func(item: syn::Item) -> Result<TokenStream> {
let docs = docs.trim();
let info = quote! {
::typst::model::FuncInfo {
::typst::eval::FuncInfo {
name,
display: #display,
category: #category,
@ -54,9 +54,9 @@ pub fn func(item: syn::Item) -> Result<TokenStream> {
#[doc(hidden)]
#vis enum #ty {}
impl::typst::model::FuncType for #ty {
fn create_func(name: &'static str) -> ::typst::model::Func {
::typst::model::Func::from_fn(#full, #info)
impl::typst::eval::FuncType for #ty {
fn create_func(name: &'static str) -> ::typst::eval::Func {
::typst::eval::Func::from_fn(#full, #info)
}
}
})
@ -72,9 +72,9 @@ pub fn func(item: syn::Item) -> Result<TokenStream> {
Ok(quote! {
#item
impl #params ::typst::model::FuncType for #ident #args #clause {
fn create_func(name: &'static str) -> ::typst::model::Func {
::typst::model::Func::from_node::<Self>(#info)
impl #params ::typst::eval::FuncType for #ident #args #clause {
fn create_func(name: &'static str) -> ::typst::eval::Func {
::typst::eval::Func::from_node::<Self>(#info)
}
}
})
@ -159,11 +159,11 @@ fn params(docs: &mut String) -> Result<(Vec<TokenStream>, Vec<String>)> {
let docs = docs.trim();
infos.push(quote! {
::typst::model::ParamInfo {
::typst::eval::ParamInfo {
name: #name,
docs: #docs,
cast: <#ty as ::typst::model::Cast<
::typst::syntax::Spanned<::typst::model::Value>
cast: <#ty as ::typst::eval::Cast<
::typst::syntax::Spanned<::typst::eval::Value>
>>::describe(),
named: #named,
positional: #positional,

View File

@ -270,8 +270,8 @@ fn create_node_construct_func(node: &Node) -> syn::ImplItemMethod {
node.construct.clone().unwrap_or_else(|| {
parse_quote! {
fn construct(
_: &::typst::model::Vm,
args: &mut ::typst::model::Args,
_: &::typst::eval::Vm,
args: &mut ::typst::eval::Args,
) -> ::typst::diag::SourceResult<::typst::model::Content> {
::typst::diag::bail!(args.span, "cannot be constructed manually");
}
@ -317,7 +317,7 @@ fn create_node_set_func(node: &Node) -> syn::ImplItemMethod {
parse_quote! {
fn set(
args: &mut ::typst::model::Args,
args: &mut ::typst::eval::Args,
constructor: bool,
) -> ::typst::diag::SourceResult<::typst::model::StyleMap> {
let mut styles = ::typst::model::StyleMap::new();
@ -340,11 +340,11 @@ fn create_node_properties_func(node: &Node) -> syn::ImplItemMethod {
let docs = docs.trim();
quote! {
::typst::model::ParamInfo {
::typst::eval::ParamInfo {
name: #name,
docs: #docs,
cast: <#value_ty as ::typst::model::Cast<
::typst::syntax::Spanned<::typst::model::Value>
cast: <#value_ty as ::typst::eval::Cast<
::typst::syntax::Spanned<::typst::eval::Value>
>>::describe(),
named: true,
positional: #shorthand,
@ -356,7 +356,7 @@ fn create_node_properties_func(node: &Node) -> syn::ImplItemMethod {
});
parse_quote! {
fn properties() -> ::std::vec::Vec<::typst::model::ParamInfo>
fn properties() -> ::std::vec::Vec<::typst::eval::ParamInfo>
where
Self: Sized
{
@ -372,7 +372,7 @@ fn create_node_field_method(node: &Node) -> syn::ImplItemMethod {
fn field(
&self,
_: &str,
) -> ::std::option::Option<::typst::model::Value> {
) -> ::std::option::Option<::typst::eval::Value> {
None
}
}

View File

@ -62,11 +62,11 @@ impl Parse for Kind {
impl Kind {
fn expand(&self) -> TokenStream {
match self {
Self::Single(c) => quote! { typst::model::Symbol::new(#c), },
Self::Single(c) => quote! { typst::eval::Symbol::new(#c), },
Self::Multiple(variants) => {
let variants = variants.iter().map(Variant::expand);
quote! {
typst::model::Symbol::list(&[#(#variants),*])
typst::eval::Symbol::list(&[#(#variants),*])
}
}
}

View File

@ -7,15 +7,14 @@ use std::sync::Arc;
use ecow::EcoString;
use crate::eval::{dict, Dict, Value};
use crate::font::Font;
use crate::geom::{
self, rounded_rect, Abs, Align, Axes, Color, Corners, Dir, Em, Geometry, Numeric,
Paint, Point, Rel, RgbaColor, Shape, Sides, Size, Stroke, Transform,
};
use crate::image::Image;
use crate::model::{
capable, dict, node, Content, Dict, Fold, StableId, StyleChain, Value,
};
use crate::model::{capable, node, Content, Fold, StableId, StyleChain};
/// A finished document with metadata and page frames.
#[derive(Debug, Default, Clone, Hash)]

View File

@ -12,11 +12,11 @@ use crate::diag::{bail, At, SourceResult, StrResult};
#[doc(hidden)]
macro_rules! __array {
($value:expr; $count:expr) => {
$crate::model::Array::from_vec($crate::model::eco_vec![$value.into(); $count])
$crate::eval::Array::from_vec($crate::eval::eco_vec![$value.into(); $count])
};
($($value:expr),* $(,)?) => {
$crate::model::Array::from_vec($crate::model::eco_vec![$($value.into()),*])
$crate::eval::Array::from_vec($crate::eval::eco_vec![$($value.into()),*])
};
}

View File

@ -4,9 +4,7 @@ use std::str::FromStr;
use ecow::EcoString;
use super::{
castable, Array, Content, Dict, Func, Label, Regex, Selector, Str, Transform, Value,
};
use super::{castable, Array, Dict, Func, Regex, Str, Value};
use crate::diag::StrResult;
use crate::doc::{Destination, Lang, Location, Region};
use crate::font::{FontStretch, FontStyle, FontWeight};
@ -14,6 +12,7 @@ use crate::geom::{
Axes, Color, Corners, Dir, GenAlign, Get, Length, Paint, PartialStroke, Point, Ratio,
Rel, Sides, Smart,
};
use crate::model::{Content, Label, Selector, Transform};
use crate::syntax::Spanned;
/// Cast from a value to a specific type.

View File

@ -18,7 +18,7 @@ macro_rules! __dict {
#[allow(unused_mut)]
let mut map = std::collections::BTreeMap::new();
$(map.insert($key.into(), $value.into());)*
$crate::model::Dict::from_map(map)
$crate::eval::Dict::from_map(map)
}};
}

View File

@ -5,11 +5,9 @@ use std::sync::Arc;
use comemo::{Prehashed, Track, Tracked, TrackedMut};
use ecow::EcoString;
use super::{
Args, CastInfo, Dict, Eval, Flow, Node, NodeId, Route, Scope, Scopes, Selector,
StyleMap, Tracer, Value, Vm,
};
use super::{Args, CastInfo, Dict, Eval, Flow, Route, Scope, Scopes, Tracer, Value, Vm};
use crate::diag::{bail, SourceResult, StrResult};
use crate::model::{Node, NodeId, Selector, StyleMap};
use crate::syntax::ast::{self, AstNode, Expr};
use crate::syntax::{SourceId, Span, SyntaxNode};
use crate::util::hash128;

View File

@ -5,10 +5,11 @@ use std::num::NonZeroUsize;
use ecow::EcoString;
use once_cell::sync::OnceCell;
use super::{Content, Module, NodeId, StyleChain, StyleMap, Vt};
use super::Module;
use crate::diag::SourceResult;
use crate::doc::Document;
use crate::geom::{Abs, Dir};
use crate::model::{Content, NodeId, StyleChain, StyleMap, Vt};
use crate::util::hash128;
/// Definition of Typst's standard library.
@ -139,6 +140,6 @@ pub fn set_lang_items(items: LangItems) {
/// Access a lang item.
macro_rules! item {
($name:ident) => {
$crate::model::LANG_ITEMS.get().unwrap().$name
$crate::eval::LANG_ITEMS.get().unwrap().$name
};
}

View File

@ -1,5 +1,40 @@
//! Evaluation of markup into modules.
#[macro_use]
mod library;
#[macro_use]
mod cast;
#[macro_use]
mod array;
#[macro_use]
mod dict;
#[macro_use]
mod str;
#[macro_use]
mod value;
mod args;
mod func;
mod methods;
mod module;
mod ops;
mod scope;
mod symbol;
pub use typst_macros::{castable, func};
pub use self::args::*;
pub use self::array::*;
pub use self::cast::*;
pub use self::dict::*;
pub use self::func::*;
pub use self::library::*;
pub use self::methods::*;
pub use self::module::*;
pub use self::scope::*;
pub use self::str::*;
pub use self::symbol::*;
pub use self::value::*;
use std::collections::BTreeMap;
use std::mem;
use std::path::{Path, PathBuf};
@ -8,14 +43,10 @@ use comemo::{Track, Tracked, TrackedMut};
use ecow::EcoVec;
use unicode_segmentation::UnicodeSegmentation;
use super::{
combining_accent, methods, ops, Arg, Args, Array, CapturesVisitor, Closure, Content,
Dict, Func, Label, LangItems, Module, Recipe, Scopes, Selector, StyleMap, Symbol,
Transform, Value,
};
use crate::diag::{
bail, error, At, SourceError, SourceResult, StrResult, Trace, Tracepoint,
};
use crate::model::{Content, Label, Recipe, Selector, StyleMap, Transform};
use crate::syntax::ast::AstNode;
use crate::syntax::{
ast, parse_code, Source, SourceId, Span, Spanned, SyntaxKind, SyntaxNode,
@ -43,7 +74,7 @@ pub fn eval(
// Hook up the lang items.
let library = world.library();
super::set_lang_items(library.items.clone());
set_lang_items(library.items.clone());
// Evaluate the module.
let route = unsafe { Route::insert(route, id) };

View File

@ -15,7 +15,7 @@ use crate::geom::GenAlign;
#[doc(hidden)]
macro_rules! __format_str {
($($tts:tt)*) => {{
$crate::model::Str::from($crate::model::eco_format!($($tts)*))
$crate::eval::Str::from($crate::eval::eco_format!($($tts)*))
}};
}

View File

@ -461,7 +461,7 @@ primitive! { Args: "arguments", Args }
#[cfg(test)]
mod tests {
use super::*;
use crate::model::{array, dict};
use crate::eval::{array, dict};
#[track_caller]
fn test(value: impl Into<Value>, exp: &str) {

View File

@ -2,7 +2,7 @@ use std::path::PathBuf;
use comemo::Track;
use crate::model::{eval, Module, Route, Tracer, Value};
use crate::eval::{eval, Module, Route, Tracer, Value};
use crate::syntax::{ast, LinkedNode, Source, SyntaxKind};
use crate::util::PathExt;
use crate::World;

View File

@ -4,7 +4,7 @@ use ecow::{eco_format, EcoString};
use if_chain::if_chain;
use super::{analyze_expr, analyze_import, plain_docs_sentence, summarize_font_family};
use crate::model::{methods_on, CastInfo, Scope, Value};
use crate::eval::{methods_on, CastInfo, Scope, Value};
use crate::syntax::{ast, LinkedNode, Source, SyntaxKind};
use crate::World;

View File

@ -2,8 +2,8 @@ use if_chain::if_chain;
use unicode_segmentation::UnicodeSegmentation;
use super::{analyze_expr, plain_docs_sentence, summarize_font_family};
use crate::eval::{CastInfo, Tracer, Value};
use crate::geom::{round_2, Length, Numeric};
use crate::model::{CastInfo, Tracer, Value};
use crate::syntax::ast;
use crate::syntax::{LinkedNode, Source, SyntaxKind};
use crate::World;

View File

@ -23,8 +23,8 @@
//! [parsed]: syntax::parse
//! [syntax tree]: syntax::SyntaxNode
//! [AST]: syntax::ast
//! [evaluate]: model::eval
//! [module]: model::Module
//! [evaluate]: eval::eval
//! [module]: eval::Module
//! [content]: model::Content
//! [typeset]: model::typeset
//! [document]: doc::Document
@ -43,23 +43,23 @@ pub mod geom;
#[macro_use]
pub mod diag;
#[macro_use]
pub mod model;
pub mod eval;
pub mod doc;
pub mod export;
pub mod font;
pub mod ide;
pub mod image;
pub mod model;
pub mod syntax;
use std::path::Path;
use comemo::{Prehashed, Track};
use model::Tracer;
use crate::diag::{FileResult, SourceResult};
use crate::doc::Document;
use crate::eval::{Library, Route, Tracer};
use crate::font::{Font, FontBook};
use crate::model::{Library, Route};
use crate::syntax::{Source, SourceId};
use crate::util::Buffer;
@ -68,7 +68,7 @@ pub fn compile(world: &(dyn World + 'static), source: &Source) -> SourceResult<D
// Evaluate the source file into a module.
let route = Route::default();
let mut tracer = Tracer::default();
let module = model::eval(world.track(), route.track(), tracer.track_mut(), source)?;
let module = eval::eval(world.track(), route.track(), tracer.track_mut(), source)?;
// Typeset the module's contents.
model::typeset(world.track(), &module.content())

View File

@ -10,11 +10,9 @@ use ecow::{EcoString, EcoVec};
use siphasher::sip128::{Hasher128, SipHasher};
use typst_macros::node;
use super::{
capability, capable, Args, Guard, Key, ParamInfo, Property, Recipe, Style, StyleMap,
Value, Vm,
};
use super::{capability, capable, Guard, Key, Property, Recipe, Style, StyleMap};
use crate::diag::{SourceResult, StrResult};
use crate::eval::{Args, ParamInfo, Value, Vm};
use crate::syntax::Span;
use crate::util::ReadableTypeId;
use crate::World;
@ -243,7 +241,7 @@ impl Content {
}
/// Whether a label can be attached to the content.
pub(super) fn labellable(&self) -> bool {
pub(crate) fn labellable(&self) -> bool {
!self.has::<dyn Unlabellable>()
}

View File

@ -1,49 +1,16 @@
//! Content and computation model.
//! The document model.
#[macro_use]
mod library;
#[macro_use]
mod cast;
#[macro_use]
mod array;
#[macro_use]
mod dict;
#[macro_use]
mod str;
#[macro_use]
mod value;
#[macro_use]
mod styles;
mod args;
mod content;
mod eval;
mod func;
mod methods;
mod module;
mod ops;
mod realize;
mod scope;
mod symbol;
mod typeset;
pub use self::content::*;
pub use self::realize::*;
pub use self::styles::*;
pub use self::typeset::*;
#[doc(hidden)]
pub use once_cell;
pub use typst_macros::{capability, capable, castable, func, node};
pub use self::args::*;
pub use self::array::*;
pub use self::cast::*;
pub use self::content::*;
pub use self::dict::*;
pub use self::eval::*;
pub use self::func::*;
pub use self::library::*;
pub use self::methods::*;
pub use self::module::*;
pub use self::realize::*;
pub use self::scope::*;
pub use self::str::*;
pub use self::styles::*;
pub use self::symbol::*;
pub use self::typeset::*;
pub use self::value::*;
pub use typst_macros::{capability, capable, node};

View File

@ -7,8 +7,9 @@ use std::sync::Arc;
use comemo::{Prehashed, Tracked};
use super::{Args, Content, Dict, Func, Label, NodeId, Regex, Value};
use super::{Content, Label, NodeId};
use crate::diag::{SourceResult, Trace, Tracepoint};
use crate::eval::{Args, Dict, Func, Regex, Value};
use crate::geom::{
Abs, Align, Axes, Corners, Em, GenAlign, Length, Numeric, PartialStroke, Rel, Sides,
Smart,

View File

@ -5,9 +5,10 @@ use std::num::NonZeroUsize;
use comemo::{Track, Tracked, TrackedMut};
use super::{Content, Selector, StyleChain, Value};
use super::{Content, Selector, StyleChain};
use crate::diag::SourceResult;
use crate::doc::{Document, Element, Frame, Location, Meta};
use crate::eval::Value;
use crate::geom::Transform;
use crate::util::hash128;
use crate::World;
@ -46,7 +47,7 @@ pub fn typeset(world: Tracked<dyn World>, content: &Content) -> SourceResult<Doc
/// A virtual typesetter.
///
/// Holds the state needed to [typeset] content. This is the equivalent to the
/// [Vm](super::Vm) for typesetting.
/// [Vm](crate::eval::Vm) for typesetting.
pub struct Vt<'a> {
/// The compilation environment.
#[doc(hidden)]

View File

@ -3,8 +3,8 @@ use std::path::Path;
use comemo::{Prehashed, Track, Tracked};
use iai::{black_box, main, Iai};
use typst::diag::{FileError, FileResult};
use typst::eval::Library;
use typst::font::{Font, FontBook};
use typst::model::Library;
use typst::syntax::{Source, SourceId};
use typst::util::Buffer;
use typst::World;
@ -59,24 +59,19 @@ fn bench_edit(iai: &mut Iai) {
fn bench_eval(iai: &mut Iai) {
let world = BenchWorld::new();
let route = typst::model::Route::default();
let mut tracer = typst::model::Tracer::default();
let route = typst::eval::Route::default();
let mut tracer = typst::eval::Tracer::default();
iai.run(|| {
typst::model::eval(
world.track(),
route.track(),
tracer.track_mut(),
&world.source,
)
.unwrap()
typst::eval::eval(world.track(), route.track(), tracer.track_mut(), &world.source)
.unwrap()
});
}
fn bench_typeset(iai: &mut Iai) {
let world = BenchWorld::new();
let route = typst::model::Route::default();
let mut tracer = typst::model::Tracer::default();
let module = typst::model::eval(
let route = typst::eval::Route::default();
let mut tracer = typst::eval::Tracer::default();
let module = typst::eval::eval(
world.track(),
route.track(),
tracer.track_mut(),

View File

@ -13,9 +13,9 @@ use once_cell::unsync::OnceCell;
use tiny_skia as sk;
use typst::diag::{bail, FileError, FileResult, SourceResult};
use typst::doc::{Document, Element, Frame, Meta};
use typst::eval::{func, Library, Value};
use typst::font::{Font, FontBook};
use typst::geom::{Abs, RgbaColor, Sides, Smart};
use typst::model::{func, Library, Value};
use typst::syntax::{Source, SourceId, Span, SyntaxNode};
use typst::util::{Buffer, PathExt};
use typst::World;
@ -150,7 +150,7 @@ fn library() -> Library {
/// ## Category
/// test
#[func]
fn test(args: &mut typst::model::Args) -> SourceResult<Value> {
fn test(args: &mut typst::eval::Args) -> SourceResult<Value> {
let lhs = args.expect::<Value>("left-hand side")?;
let rhs = args.expect::<Value>("right-hand side")?;
if lhs != rhs {
@ -163,7 +163,7 @@ fn library() -> Library {
/// ## Category
/// test
#[func]
fn print(args: &mut typst::model::Args) -> SourceResult<Value> {
fn print(args: &mut typst::eval::Args) -> SourceResult<Value> {
print!("> ");
for (i, value) in args.all::<Value>()?.into_iter().enumerate() {
if i > 0 {
@ -441,10 +441,10 @@ fn test_part(
if world.print.model {
let world = (world as &dyn World).track();
let route = typst::model::Route::default();
let mut tracer = typst::model::Tracer::default();
let route = typst::eval::Route::default();
let mut tracer = typst::eval::Tracer::default();
let module =
typst::model::eval(world, route.track(), tracer.track_mut(), source).unwrap();
typst::eval::eval(world, route.track(), tracer.track_mut(), source).unwrap();
println!("Model:\n{:#?}\n", module.content());
}