diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 910ff0b1f7..9bc853cdc0 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -100,6 +100,36 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap { Symbol::NUM_ATAN => num_atan, Symbol::NUM_ACOS => num_acos, Symbol::NUM_ASIN => num_asin, + Symbol::NUM_MAX_INT => num_max_int, + Symbol::NUM_MIN_INT => num_min_int, + } +} + +/// Num.maxInt : Int +fn num_max_int(symbol: Symbol, var_store: &mut VarStore) -> Def { + let int_var = var_store.fresh(); + let body = Int(int_var, i64::MAX); + + Def { + annotation: None, + expr_var: int_var, + loc_expr: Located::at_zero(body), + loc_pattern: Located::at_zero(Pattern::Identifier(symbol)), + pattern_vars: SendMap::default(), + } +} + +/// Num.minInt : Int +fn num_min_int(symbol: Symbol, var_store: &mut VarStore) -> Def { + let int_var = var_store.fresh(); + let body = Int(int_var, i64::MIN); + + Def { + annotation: None, + expr_var: int_var, + loc_expr: Located::at_zero(body), + loc_pattern: Located::at_zero(Pattern::Identifier(symbol)), + pattern_vars: SendMap::default(), } } diff --git a/compiler/gen/tests/gen_num.rs b/compiler/gen/tests/gen_num.rs index 4da085eac0..8c9a41374a 100644 --- a/compiler/gen/tests/gen_num.rs +++ b/compiler/gen/tests/gen_num.rs @@ -794,11 +794,23 @@ mod gen_num { assert_evals_to!( indoc!( r#" - # Num.maxInt - Num.add (-1) Num.maxInt + Num.maxInt "# ), - 1, + i64::MAX, + i64 + ); + } + + #[test] + fn num_min_int() { + assert_evals_to!( + indoc!( + r#" + Num.minInt + "# + ), + i64::MIN, i64 ); } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 9e75a00495..6f801fedbd 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2029,6 +2029,20 @@ pub fn with_hole<'a>( env.arena.alloc(Stmt::Ret(assigned)), ); + return result; + } else if symbol.module_id() != env.home { + // TODO here we assume this is a 0-arity thunk. That's not true in general! + let result = call_by_name( + env, + procs, + variable, + symbol, + std::vec::Vec::new(), + layout_cache, + assigned, + env.arena.alloc(Stmt::Ret(assigned)), + ); + dbg!(&procs.externals_we_need); return result; }