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/operations.rs | 865 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 865 insertions(+) create mode 100644 dhall/src/operations.rs (limited to 'dhall/src/operations.rs') 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