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 siphasher::sip128::{Hasher128, SipHasher};
use termcolor::{ColorChoice, StandardStream, WriteColor}; use termcolor::{ColorChoice, StandardStream, WriteColor};
use typst::diag::{FileError, FileResult, SourceError, StrResult}; use typst::diag::{FileError, FileResult, SourceError, StrResult};
use typst::eval::Library;
use typst::font::{Font, FontBook, FontInfo, FontVariant}; use typst::font::{Font, FontBook, FontInfo, FontVariant};
use typst::model::Library;
use typst::syntax::{Source, SourceId}; use typst::syntax::{Source, SourceId};
use typst::util::{Buffer, PathExt}; use typst::util::{Buffer, PathExt};
use typst::World; use typst::World;

View File

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

View File

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

View File

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

View File

@ -137,5 +137,5 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> {
#[func] #[func]
pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> { pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?; 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 text;
pub mod visualize; pub mod visualize;
use typst::eval::{LangItems, Library, Module, Scope};
use typst::geom::{Align, Color, Dir, GenAlign}; 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; use self::layout::LayoutRoot;

View File

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

View File

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

View File

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

View File

@ -14,13 +14,17 @@ pub use typst::diag::{bail, error, At, SourceResult, StrResult};
#[doc(no_inline)] #[doc(no_inline)]
pub use typst::doc::*; pub use typst::doc::*;
#[doc(no_inline)] #[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::*; pub use typst::geom::*;
#[doc(no_inline)] #[doc(no_inline)]
pub use typst::model::{ pub use typst::model::{
array, capability, capable, castable, dict, format_str, func, node, Args, Array, capability, capable, node, Content, Finalize, Fold, Introspector, Label, Node,
AutoValue, Cast, CastInfo, Content, Dict, Finalize, Fold, Func, Introspector, Label, NodeId, Prepare, Resolve, Selector, Show, StabilityProvider, StyleChain, StyleMap,
Node, NodeId, NoneValue, Prepare, Resolve, Selector, Show, StabilityProvider, Str, StyleVec, Unlabellable, Vt,
StyleChain, StyleMap, StyleVec, Symbol, Unlabellable, Value, Vm, Vt,
}; };
#[doc(no_inline)] #[doc(no_inline)]
pub use typst::syntax::{Span, Spanned}; 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. /// A module with all emoji.
pub fn emoji() -> Module { 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. /// A module with all general symbols.
pub fn sym() -> Module { 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 describe_func = create_describe_func(&castable);
let dynamic_impls = castable.name.as_ref().map(|name| { let dynamic_impls = castable.name.as_ref().map(|name| {
quote! { quote! {
impl ::typst::model::Type for #ty { impl ::typst::eval::Type for #ty {
const TYPE_NAME: &'static str = #name; 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 { 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! { Ok(quote! {
impl ::typst::model::Cast for #ty { impl ::typst::eval::Cast for #ty {
#is_func #is_func
#cast_func #cast_func
#describe_func #describe_func
@ -53,7 +53,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
} }
Pattern::Ty(_, ty) => { Pattern::Ty(_, ty) => {
cast_checks.push(quote! { cast_checks.push(quote! {
if <#ty as ::typst::model::Cast>::is(value) { if <#ty as ::typst::eval::Cast>::is(value) {
return true; return true;
} }
}); });
@ -63,7 +63,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
let dynamic_check = castable.name.is_some().then(|| { let dynamic_check = castable.name.is_some().then(|| {
quote! { quote! {
if let ::typst::model::Value::Dyn(dynamic) = &value { if let ::typst::eval::Value::Dyn(dynamic) = &value {
if dynamic.is::<Self>() { if dynamic.is::<Self>() {
return true; return true;
} }
@ -73,7 +73,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
let str_check = (!string_arms.is_empty()).then(|| { let str_check = (!string_arms.is_empty()).then(|| {
quote! { quote! {
if let ::typst::model::Value::Str(string) = &value { if let ::typst::eval::Value::Str(string) = &value {
match string.as_str() { match string.as_str() {
#(#string_arms,)* #(#string_arms,)*
_ => {} _ => {}
@ -83,7 +83,7 @@ fn create_is_func(castable: &Castable) -> TokenStream {
}); });
quote! { quote! {
fn is(value: &typst::model::Value) -> bool { fn is(value: &::typst::eval::Value) -> bool {
#dynamic_check #dynamic_check
#str_check #str_check
#(#cast_checks)* #(#cast_checks)*
@ -105,8 +105,8 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
} }
Pattern::Ty(binding, ty) => { Pattern::Ty(binding, ty) => {
cast_checks.push(quote! { cast_checks.push(quote! {
if <#ty as ::typst::model::Cast>::is(&value) { if <#ty as ::typst::eval::Cast>::is(&value) {
let #binding = <#ty as ::typst::model::Cast>::cast(value)?; let #binding = <#ty as ::typst::eval::Cast>::cast(value)?;
return Ok(#expr); return Ok(#expr);
} }
}); });
@ -116,7 +116,7 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
let dynamic_check = castable.name.is_some().then(|| { let dynamic_check = castable.name.is_some().then(|| {
quote! { quote! {
if let ::typst::model::Value::Dyn(dynamic) = &value { if let ::typst::eval::Value::Dyn(dynamic) = &value {
if let Some(concrete) = dynamic.downcast::<Self>() { if let Some(concrete) = dynamic.downcast::<Self>() {
return Ok(concrete.clone()); return Ok(concrete.clone());
} }
@ -126,7 +126,7 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
let str_check = (!string_arms.is_empty()).then(|| { let str_check = (!string_arms.is_empty()).then(|| {
quote! { quote! {
if let ::typst::model::Value::Str(string) = &value { if let ::typst::eval::Value::Str(string) = &value {
match string.as_str() { match string.as_str() {
#(#string_arms,)* #(#string_arms,)*
_ => {} _ => {}
@ -136,11 +136,11 @@ fn create_cast_func(castable: &Castable) -> TokenStream {
}); });
quote! { quote! {
fn cast(value: ::typst::model::Value) -> ::typst::diag::StrResult<Self> { fn cast(value: ::typst::eval::Value) -> ::typst::diag::StrResult<Self> {
#dynamic_check #dynamic_check
#str_check #str_check
#(#cast_checks)* #(#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); let docs = documentation(&cast.attrs);
infos.push(match &cast.pattern { infos.push(match &cast.pattern {
Pattern::Str(lit) => { Pattern::Str(lit) => {
quote! { ::typst::model::CastInfo::Value(#lit.into(), #docs) } quote! { ::typst::eval::CastInfo::Value(#lit.into(), #docs) }
} }
Pattern::Ty(_, ty) => { 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! { quote! {
fn describe() -> ::typst::model::CastInfo { fn describe() -> ::typst::eval::CastInfo {
#(#infos)+* #(#infos)+*
} }
} }

View File

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

View File

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

View File

@ -62,11 +62,11 @@ impl Parse for Kind {
impl Kind { impl Kind {
fn expand(&self) -> TokenStream { fn expand(&self) -> TokenStream {
match self { match self {
Self::Single(c) => quote! { typst::model::Symbol::new(#c), }, Self::Single(c) => quote! { typst::eval::Symbol::new(#c), },
Self::Multiple(variants) => { Self::Multiple(variants) => {
let variants = variants.iter().map(Variant::expand); let variants = variants.iter().map(Variant::expand);
quote! { 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 ecow::EcoString;
use crate::eval::{dict, Dict, Value};
use crate::font::Font; use crate::font::Font;
use crate::geom::{ use crate::geom::{
self, rounded_rect, Abs, Align, Axes, Color, Corners, Dir, Em, Geometry, Numeric, self, rounded_rect, Abs, Align, Axes, Color, Corners, Dir, Em, Geometry, Numeric,
Paint, Point, Rel, RgbaColor, Shape, Sides, Size, Stroke, Transform, Paint, Point, Rel, RgbaColor, Shape, Sides, Size, Stroke, Transform,
}; };
use crate::image::Image; use crate::image::Image;
use crate::model::{ use crate::model::{capable, node, Content, Fold, StableId, StyleChain};
capable, dict, node, Content, Dict, Fold, StableId, StyleChain, Value,
};
/// A finished document with metadata and page frames. /// A finished document with metadata and page frames.
#[derive(Debug, Default, Clone, Hash)] #[derive(Debug, Default, Clone, Hash)]

View File

@ -12,11 +12,11 @@ use crate::diag::{bail, At, SourceResult, StrResult};
#[doc(hidden)] #[doc(hidden)]
macro_rules! __array { macro_rules! __array {
($value:expr; $count:expr) => { ($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),* $(,)?) => { ($($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 ecow::EcoString;
use super::{ use super::{castable, Array, Dict, Func, Regex, Str, Value};
castable, Array, Content, Dict, Func, Label, Regex, Selector, Str, Transform, Value,
};
use crate::diag::StrResult; use crate::diag::StrResult;
use crate::doc::{Destination, Lang, Location, Region}; use crate::doc::{Destination, Lang, Location, Region};
use crate::font::{FontStretch, FontStyle, FontWeight}; use crate::font::{FontStretch, FontStyle, FontWeight};
@ -14,6 +12,7 @@ use crate::geom::{
Axes, Color, Corners, Dir, GenAlign, Get, Length, Paint, PartialStroke, Point, Ratio, Axes, Color, Corners, Dir, GenAlign, Get, Length, Paint, PartialStroke, Point, Ratio,
Rel, Sides, Smart, Rel, Sides, Smart,
}; };
use crate::model::{Content, Label, Selector, Transform};
use crate::syntax::Spanned; use crate::syntax::Spanned;
/// Cast from a value to a specific type. /// Cast from a value to a specific type.

View File

@ -18,7 +18,7 @@ macro_rules! __dict {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut map = std::collections::BTreeMap::new(); let mut map = std::collections::BTreeMap::new();
$(map.insert($key.into(), $value.into());)* $(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 comemo::{Prehashed, Track, Tracked, TrackedMut};
use ecow::EcoString; use ecow::EcoString;
use super::{ use super::{Args, CastInfo, Dict, Eval, Flow, Route, Scope, Scopes, Tracer, Value, Vm};
Args, CastInfo, Dict, Eval, Flow, Node, NodeId, Route, Scope, Scopes, Selector,
StyleMap, Tracer, Value, Vm,
};
use crate::diag::{bail, SourceResult, StrResult}; use crate::diag::{bail, SourceResult, StrResult};
use crate::model::{Node, NodeId, Selector, StyleMap};
use crate::syntax::ast::{self, AstNode, Expr}; use crate::syntax::ast::{self, AstNode, Expr};
use crate::syntax::{SourceId, Span, SyntaxNode}; use crate::syntax::{SourceId, Span, SyntaxNode};
use crate::util::hash128; use crate::util::hash128;

View File

@ -5,10 +5,11 @@ use std::num::NonZeroUsize;
use ecow::EcoString; use ecow::EcoString;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use super::{Content, Module, NodeId, StyleChain, StyleMap, Vt}; use super::Module;
use crate::diag::SourceResult; use crate::diag::SourceResult;
use crate::doc::Document; use crate::doc::Document;
use crate::geom::{Abs, Dir}; use crate::geom::{Abs, Dir};
use crate::model::{Content, NodeId, StyleChain, StyleMap, Vt};
use crate::util::hash128; use crate::util::hash128;
/// Definition of Typst's standard library. /// Definition of Typst's standard library.
@ -139,6 +140,6 @@ pub fn set_lang_items(items: LangItems) {
/// Access a lang item. /// Access a lang item.
macro_rules! item { macro_rules! item {
($name:ident) => { ($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. //! 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::collections::BTreeMap;
use std::mem; use std::mem;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -8,14 +43,10 @@ use comemo::{Track, Tracked, TrackedMut};
use ecow::EcoVec; use ecow::EcoVec;
use unicode_segmentation::UnicodeSegmentation; 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::{ use crate::diag::{
bail, error, At, SourceError, SourceResult, StrResult, Trace, Tracepoint, 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::AstNode;
use crate::syntax::{ use crate::syntax::{
ast, parse_code, Source, SourceId, Span, Spanned, SyntaxKind, SyntaxNode, ast, parse_code, Source, SourceId, Span, Spanned, SyntaxKind, SyntaxNode,
@ -43,7 +74,7 @@ pub fn eval(
// Hook up the lang items. // Hook up the lang items.
let library = world.library(); let library = world.library();
super::set_lang_items(library.items.clone()); set_lang_items(library.items.clone());
// Evaluate the module. // Evaluate the module.
let route = unsafe { Route::insert(route, id) }; let route = unsafe { Route::insert(route, id) };

View File

@ -15,7 +15,7 @@ use crate::geom::GenAlign;
#[doc(hidden)] #[doc(hidden)]
macro_rules! __format_str { macro_rules! __format_str {
($($tts:tt)*) => {{ ($($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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::model::{array, dict}; use crate::eval::{array, dict};
#[track_caller] #[track_caller]
fn test(value: impl Into<Value>, exp: &str) { fn test(value: impl Into<Value>, exp: &str) {

View File

@ -2,7 +2,7 @@ use std::path::PathBuf;
use comemo::Track; 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::syntax::{ast, LinkedNode, Source, SyntaxKind};
use crate::util::PathExt; use crate::util::PathExt;
use crate::World; use crate::World;

View File

@ -4,7 +4,7 @@ use ecow::{eco_format, EcoString};
use if_chain::if_chain; use if_chain::if_chain;
use super::{analyze_expr, analyze_import, plain_docs_sentence, summarize_font_family}; 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::syntax::{ast, LinkedNode, Source, SyntaxKind};
use crate::World; use crate::World;

View File

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

View File

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

View File

@ -10,11 +10,9 @@ use ecow::{EcoString, EcoVec};
use siphasher::sip128::{Hasher128, SipHasher}; use siphasher::sip128::{Hasher128, SipHasher};
use typst_macros::node; use typst_macros::node;
use super::{ use super::{capability, capable, Guard, Key, Property, Recipe, Style, StyleMap};
capability, capable, Args, Guard, Key, ParamInfo, Property, Recipe, Style, StyleMap,
Value, Vm,
};
use crate::diag::{SourceResult, StrResult}; use crate::diag::{SourceResult, StrResult};
use crate::eval::{Args, ParamInfo, Value, Vm};
use crate::syntax::Span; use crate::syntax::Span;
use crate::util::ReadableTypeId; use crate::util::ReadableTypeId;
use crate::World; use crate::World;
@ -243,7 +241,7 @@ impl Content {
} }
/// Whether a label can be attached to the 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>() !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] #[macro_use]
mod styles; mod styles;
mod args;
mod content; mod content;
mod eval;
mod func;
mod methods;
mod module;
mod ops;
mod realize; mod realize;
mod scope;
mod symbol;
mod typeset; mod typeset;
pub use self::content::*;
pub use self::realize::*;
pub use self::styles::*;
pub use self::typeset::*;
#[doc(hidden)] #[doc(hidden)]
pub use once_cell; pub use once_cell;
pub use typst_macros::{capability, capable, castable, func, node}; pub use typst_macros::{capability, capable, 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::*;

View File

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

View File

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

View File

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

View File

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