From fff4c46e09d4edf25eba737f4d71bfdb1dbf4a82 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 6 Apr 2020 22:11:54 +0100 Subject: Extract operation-related code to a new module --- dhall/src/lib.rs | 1 + dhall/src/operations.rs | 865 +++++++++++++++++++++++++++++++++ dhall/src/semantics/builtins.rs | 5 +- dhall/src/semantics/nze/nir.rs | 3 +- dhall/src/semantics/nze/normalize.rs | 301 +----------- dhall/src/semantics/resolve/resolve.rs | 3 +- dhall/src/semantics/tck/typecheck.rs | 515 +------------------- dhall/src/syntax/ast/expr.rs | 65 +-- dhall/src/syntax/binary/decode.rs | 3 +- dhall/src/syntax/binary/encode.rs | 5 +- dhall/src/syntax/text/parser.rs | 2 +- dhall/src/syntax/text/printer.rs | 11 +- 12 files changed, 898 insertions(+), 881 deletions(-) create mode 100644 dhall/src/operations.rs (limited to 'dhall') diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 98ad4f0..e00177c 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -11,6 +11,7 @@ mod tests; pub mod error; +pub mod operations; pub mod semantics; pub mod syntax; diff --git a/dhall/src/operations.rs b/dhall/src/operations.rs new file mode 100644 index 0000000..363cd10 --- /dev/null +++ b/dhall/src/operations.rs @@ -0,0 +1,865 @@ +use itertools::Itertools; +use std::borrow::Cow; +use std::cmp::max; +use std::collections::HashMap; + +use crate::error::{ErrorBuilder, TypeError}; +use crate::semantics::{ + merge_maps, mk_span_err, mkerr, ret_kind, ret_op, ret_ref, Binder, Closure, + Hir, HirKind, Nir, NirKind, Ret, TextLit, Tir, TyEnv, Type, +}; +use crate::syntax::map::DupTreeSet; +use crate::syntax::{ + trivial_result, BinOp, Builtin, Const, ExprKind, Label, NumKind, Span, +}; + +/// Operations +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum OpKind { + /// `f a` + App(SubExpr, SubExpr), + /// Binary operations + BinOp(BinOp, SubExpr, SubExpr), + /// `if x then y else z` + BoolIf(SubExpr, SubExpr, SubExpr), + /// `merge x y : t` + Merge(SubExpr, SubExpr, Option), + /// `toMap x : t` + ToMap(SubExpr, Option), + /// `e.x` + Field(SubExpr, Label), + /// `e.{ x, y, z }` + Projection(SubExpr, DupTreeSet