From 55b5be3407a8528bc47482a591b168a7cb0ce91e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 6 May 2019 23:52:15 +0200 Subject: Move main datatypes into their own modules --- dhall/src/phase/mod.rs | 10 +- dhall/src/phase/normalize.rs | 999 +------------------------------------------ dhall/src/phase/typecheck.rs | 345 ++++++--------- 3 files changed, 160 insertions(+), 1194 deletions(-) (limited to 'dhall/src/phase') diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 4262dc1..0faf6dd 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -4,11 +4,13 @@ use std::path::Path; use dhall_syntax::{Const, Import, Span, SubExpr, X}; +use crate::core::context::TypecheckContext; +use crate::core::thunk::Thunk; +use crate::core::value::{AlphaVar, Value}; use crate::error::{Error, ImportError, TypeError, TypeMessage}; -use normalize::{AlphaVar, Thunk, Value}; use resolve::ImportRoot; -use typecheck::{const_to_typed, type_of_const, TypecheckContext}; +use typecheck::{const_to_typed, type_of_const}; pub(crate) mod binary; pub(crate) mod normalize; @@ -305,6 +307,10 @@ impl Normalized { pub(crate) fn to_type(self) -> Type { self.0.to_type() } + pub(crate) fn get_type(&self) -> Result, TypeError> { + self.0.get_type() + } + pub(crate) fn shift(&self, delta: isize, var: &AlphaVar) -> Self { Normalized(self.0.shift(delta, var)) } diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 2340bbd..a48c299 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -1,988 +1,16 @@ -#![allow(non_snake_case)] use std::collections::BTreeMap; -use std::rc::Rc; -use dhall_proc_macros as dhall; -use dhall_syntax::context::Context; -use dhall_syntax::{ - rc, BinOp, Builtin, Const, ExprF, Integer, InterpolatedTextContents, Label, - Natural, V, X, -}; +use dhall_syntax::{BinOp, Builtin, ExprF, InterpolatedTextContents, Label, X}; -use crate::phase::{NormalizedSubExpr, ResolvedSubExpr, Type, Typed}; +use crate::core::context::NormalizationContext; +use crate::core::thunk::{Thunk, TypeThunk}; +use crate::core::value::Value; +use crate::phase::{NormalizedSubExpr, ResolvedSubExpr, Typed}; -type InputSubExpr = ResolvedSubExpr; -type OutputSubExpr = NormalizedSubExpr; +pub(crate) type InputSubExpr = ResolvedSubExpr; +pub(crate) type OutputSubExpr = NormalizedSubExpr; -/// Stores a pair of variables: a normal one and if relevant one -/// that corresponds to the alpha-normalized version of the first one. -#[derive(Debug, Clone, Eq)] -pub(crate) struct AlphaVar { - normal: V