Skip to content

Commit

Permalink
Macro -> function
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed Nov 8, 2023
1 parent 96cc564 commit 5783ada
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
14 changes: 5 additions & 9 deletions compiler/src/passes/validate/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::passes::validate::type_check::uncover_globals::uncover_globals;
use crate::passes::validate::type_check::validate_expr::validate_expr;
use crate::passes::validate::type_check::validate_typedef::validate_typedef;
use crate::passes::validate::{PrgTypeChecked, TExpr};
use crate::s;
use crate::utils::expect::expect;
use crate::utils::push_map::PushMap;
use std::collections::HashMap;
Expand Down Expand Up @@ -135,8 +134,8 @@ pub fn expect_type_eq<'p>(
MismatchedTypes {
t1: t1.clone().fmap(str::to_string),
t2: t2.clone().fmap(str::to_string),
span_t1: s!(e1.span),
span_t2: s!(e2.span),
span_t1: s(e1.span),
span_t2: s(e2.span),
},
)?;

Expand All @@ -153,14 +152,11 @@ pub fn expect_type<'p>(
MismatchedType {
got: typ.clone().fmap(str::to_string),
expect: expected.clone().fmap(str::to_string),
span: s!(expr.span),
span: s(expr.span),
},
)
}

#[macro_export]
macro_rules! s {
($span:expr) => {
($span.0, $span.1 - $span.0)
};
pub fn s(span: (usize, usize)) -> (usize, usize) {
(span.0, span.1 - span.0)
}
5 changes: 2 additions & 3 deletions compiler/src/passes/validate/type_check/validate_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::passes::parse::{Expr, Spanned};
use crate::passes::validate::type_check::error::TypeError;
use crate::passes::validate::type_check::error::TypeError::*;
use crate::passes::validate::type_check::validate_expr::validate_expr;
use crate::passes::validate::type_check::{Env, EnvEntry};
use crate::passes::validate::type_check::{Env, EnvEntry, s};
use crate::passes::validate::TExpr;
use crate::s;
use crate::utils::expect::expect;

pub fn validate_assign<'p>(
Expand All @@ -16,7 +15,7 @@ pub fn validate_assign<'p>(
) -> Result<Spanned<TExpr<'p, &'p str>>, TypeError> {
let entry = env.scope.get(&sym.inner).ok_or(UndeclaredVar {
sym: (*sym.inner).to_string(),
span: s!(sym.span),
span: s(sym.span),
})?;

let EnvEntry::Type { mutable, .. } = entry else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/passes/validate/type_check/validate_lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::passes::parse::{Lit, Spanned};
use crate::passes::validate::type_check::error::TypeError;
use crate::passes::validate::type_check::error::TypeError::*;
use crate::passes::validate::{TExpr, TLit};
use crate::s;
use crate::passes::validate::type_check::s;

pub fn validate_lit<'p>(
val: Lit,
Expand All @@ -13,7 +13,7 @@ pub fn validate_lit<'p>(
Lit::Int { val } => {
let val = val
.parse()
.map_err(|_| IntegerOutOfBounds { span: s!(span) })?;
.map_err(|_| IntegerOutOfBounds { span: s(span) })?;

TExpr::Lit {
val: TLit::Int { val },
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/passes/validate/type_check/validate_var.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::passes::parse::Spanned;
use crate::passes::validate::type_check::error::TypeError;
use crate::passes::validate::type_check::error::TypeError::*;
use crate::passes::validate::type_check::{Env, EnvEntry};
use crate::passes::validate::type_check::{Env, EnvEntry, s};
use crate::passes::validate::TExpr;
use crate::s;

pub fn validate_var<'p>(
sym: &'p str,
Expand All @@ -12,7 +11,7 @@ pub fn validate_var<'p>(
) -> Result<Spanned<TExpr<'p, &'p str>>, TypeError> {
let entry = env.scope.get(&sym).ok_or(UndeclaredVar {
sym: (*sym).to_string(),
span: s!(span),
span: s(span),
})?;

let EnvEntry::Type { typ, .. } = entry else {
Expand Down

0 comments on commit 5783ada

Please sign in to comment.