summaryrefslogtreecommitdiff
path: root/dhall/src/builtins.rs
diff options
context:
space:
mode:
authorNadrieril2020-12-06 21:41:03 +0000
committerNadrieril2020-12-07 19:34:38 +0000
commit6287b7a7f9e421877ee13fefa586395fec844c99 (patch)
tree65129001dbd7e56561df656dc8eee8f441a05b25 /dhall/src/builtins.rs
parent9991bd4891774c4dd598decae02ee860554d2ab7 (diff)
Thread cx through typecheck
Diffstat (limited to 'dhall/src/builtins.rs')
-rw-r--r--dhall/src/builtins.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/dhall/src/builtins.rs b/dhall/src/builtins.rs
index cc426dd..f92f1c3 100644
--- a/dhall/src/builtins.rs
+++ b/dhall/src/builtins.rs
@@ -11,6 +11,7 @@ use crate::syntax::{
Const, Expr, ExprKind, InterpolatedText, InterpolatedTextContents, Label,
NaiveDouble, NumKind, Span, UnspannedExpr, V,
};
+use crate::Ctxt;
/// Built-ins
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -98,12 +99,14 @@ pub struct BuiltinClosure {
impl BuiltinClosure {
pub fn new(b: Builtin, env: NzEnv) -> NirKind {
- apply_builtin(b, Vec::new(), env)
+ // TODO: thread cx
+ Ctxt::with_new(|cx| apply_builtin(cx, b, Vec::new(), env))
}
pub fn apply(&self, a: Nir) -> NirKind {
use std::iter::once;
let args = self.args.iter().cloned().chain(once(a)).collect();
- apply_builtin(self.b, args, self.env.clone())
+ // TODO: thread cx
+ Ctxt::with_new(|cx| apply_builtin(cx, self.b, args, self.env.clone()))
}
pub fn to_hirkind(&self, venv: VarEnv) -> HirKind {
HirKind::Expr(self.args.iter().fold(
@@ -307,7 +310,12 @@ macro_rules! make_closure {
}
#[allow(clippy::cognitive_complexity)]
-fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
+fn apply_builtin(
+ cx: Ctxt<'_>,
+ b: Builtin,
+ args: Vec<Nir>,
+ env: NzEnv,
+) -> NirKind {
use NirKind::*;
use NumKind::{Bool, Double, Integer, Natural};
@@ -318,7 +326,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
DoneAsIs,
}
let make_closure = |e| {
- typecheck(&skip_resolve_expr(&e).unwrap())
+ typecheck(cx, &skip_resolve_expr(&e).unwrap())
.unwrap()
.eval(env.clone())
};