summaryrefslogtreecommitdiff
path: root/src/eval/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-08 15:08:26 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-08 15:45:14 +0200
commit712c00ecb72b67da2c0788e5d3eb4dcc6366b2a7 (patch)
treef5d7ef4341a4728c980d020cc173fa6bb70feaff /src/eval/mod.rs
parent977ac77e6a3298be2644a8231e93acbef9f7f396 (diff)
Em units
Diffstat (limited to 'src/eval/mod.rs')
-rw-r--r--src/eval/mod.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index 8b777a64..3f580178 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -43,7 +43,7 @@ use parking_lot::{MappedRwLockWriteGuard, RwLockWriteGuard};
use unicode_segmentation::UnicodeSegmentation;
use crate::diag::{At, StrResult, Trace, Tracepoint, TypResult};
-use crate::geom::{Angle, Fraction, Length, Ratio};
+use crate::geom::{Angle, Em, Fraction, Length, Ratio};
use crate::library;
use crate::syntax::ast::*;
use crate::syntax::{Span, Spanned};
@@ -245,10 +245,13 @@ impl Eval for Lit {
LitKind::Bool(v) => Value::Bool(v),
LitKind::Int(v) => Value::Int(v),
LitKind::Float(v) => Value::Float(v),
- LitKind::Length(v, unit) => Value::Length(Length::with_unit(v, unit)),
- LitKind::Angle(v, unit) => Value::Angle(Angle::with_unit(v, unit)),
- LitKind::Percent(v) => Value::Ratio(Ratio::new(v / 100.0)),
- LitKind::Fractional(v) => Value::Fraction(Fraction::new(v)),
+ LitKind::Numeric(v, unit) => match unit {
+ Unit::Length(unit) => Length::with_unit(v, unit).into(),
+ Unit::Angle(unit) => Angle::with_unit(v, unit).into(),
+ Unit::Em => Em::new(v).into(),
+ Unit::Fr => Fraction::new(v).into(),
+ Unit::Percent => Ratio::new(v / 100.0).into(),
+ },
LitKind::Str(ref v) => Value::Str(v.clone()),
})
}
@@ -735,7 +738,7 @@ impl Eval for IncludeExpr {
/// Process an import of a module relative to the current location.
fn import(ctx: &mut Context, path: &str, span: Span) -> TypResult<Module> {
// Load the source file.
- let full = ctx.resolve(path);
+ let full = ctx.complete_path(path);
let id = ctx.sources.load(&full).map_err(|err| match err.kind() {
std::io::ErrorKind::NotFound => error!(span, "file not found"),
_ => error!(span, "failed to load source file ({})", err),