Merge branch 'int-float-size-gen' into temp_numbers

This commit is contained in:
rvcas 2020-12-30 19:41:44 -05:00
commit c33cab57f2
14 changed files with 493 additions and 85 deletions

View file

@ -212,7 +212,8 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap<Symbol, Def> {
/// 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);
let int_percision_var = var_store.fresh();
let body = Int(int_var, int_percision_var, i64::MAX);
Def {
annotation: None,
@ -226,7 +227,8 @@ fn num_max_int(symbol: Symbol, var_store: &mut VarStore) -> Def {
/// 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);
let int_percision_var = var_store.fresh();
let body = Int(int_var, int_percision_var, i64::MIN);
Def {
annotation: None,
@ -846,7 +848,7 @@ fn num_is_odd(symbol: Symbol, var_store: &mut VarStore) -> Def {
let body = RunLowLevel {
op: LowLevel::Eq,
args: vec![
(arg_var, Int(var_store.fresh(), 1)),
(arg_var, Int(var_store.fresh(), var_store.fresh(), 1)),
(
arg_var,
RunLowLevel {
@ -930,6 +932,7 @@ fn num_sqrt(symbol: Symbol, var_store: &mut VarStore) -> Def {
let bool_var = var_store.fresh();
let float_var = var_store.fresh();
let unbound_zero_var = var_store.fresh();
let percision_var = var_store.fresh();
let ret_var = var_store.fresh();
let body = If {
@ -943,7 +946,7 @@ fn num_sqrt(symbol: Symbol, var_store: &mut VarStore) -> Def {
op: LowLevel::NotEq,
args: vec![
(float_var, Var(Symbol::ARG_1)),
(float_var, Float(unbound_zero_var, 0.0)),
(float_var, Float(unbound_zero_var, percision_var, 0.0)),
],
ret_var: bool_var,
},
@ -1896,6 +1899,7 @@ fn num_div_float(symbol: Symbol, var_store: &mut VarStore) -> Def {
let bool_var = var_store.fresh();
let num_var = var_store.fresh();
let unbound_zero_var = var_store.fresh();
let percision_var = var_store.fresh();
let ret_var = var_store.fresh();
let body = If {
@ -1909,7 +1913,7 @@ fn num_div_float(symbol: Symbol, var_store: &mut VarStore) -> Def {
op: LowLevel::NotEq,
args: vec![
(num_var, Var(Symbol::ARG_2)),
(num_var, Float(unbound_zero_var, 0.0)),
(num_var, Float(unbound_zero_var, percision_var, 0.0)),
],
ret_var: bool_var,
},
@ -1958,6 +1962,7 @@ fn num_div_int(symbol: Symbol, var_store: &mut VarStore) -> Def {
let bool_var = var_store.fresh();
let num_var = var_store.fresh();
let unbound_zero_var = var_store.fresh();
let unbound_zero_percision_var = var_store.fresh();
let ret_var = var_store.fresh();
let body = If {
@ -1971,7 +1976,10 @@ fn num_div_int(symbol: Symbol, var_store: &mut VarStore) -> Def {
op: LowLevel::NotEq,
args: vec![
(num_var, Var(Symbol::ARG_2)),
(num_var, Int(unbound_zero_var, 0)),
(
num_var,
Int(unbound_zero_var, unbound_zero_percision_var, 0),
),
],
ret_var: bool_var,
},
@ -2025,6 +2033,7 @@ fn list_first(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_var = var_store.fresh();
let len_var = var_store.fresh();
let zero_var = var_store.fresh();
let zero_percision_var = var_store.fresh();
let list_elem_var = var_store.fresh();
let ret_var = var_store.fresh();
@ -2039,7 +2048,7 @@ fn list_first(symbol: Symbol, var_store: &mut VarStore) -> Def {
RunLowLevel {
op: LowLevel::NotEq,
args: vec![
(len_var, Int(zero_var, 0)),
(len_var, Int(zero_var, zero_percision_var, 0)),
(
len_var,
RunLowLevel {
@ -2061,7 +2070,10 @@ fn list_first(symbol: Symbol, var_store: &mut VarStore) -> Def {
// List.#getUnsafe list 0
RunLowLevel {
op: LowLevel::ListGetUnsafe,
args: vec![(list_var, Var(Symbol::ARG_1)), (len_var, Int(zero_var, 0))],
args: vec![
(list_var, Var(Symbol::ARG_1)),
(len_var, Int(zero_var, zero_percision_var, 0)),
],
ret_var: list_elem_var,
},
],
@ -2102,6 +2114,7 @@ fn list_last(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_var = var_store.fresh();
let len_var = var_store.fresh();
let num_var = var_store.fresh();
let num_percision_var = var_store.fresh();
let list_elem_var = var_store.fresh();
let ret_var = var_store.fresh();
@ -2116,7 +2129,7 @@ fn list_last(symbol: Symbol, var_store: &mut VarStore) -> Def {
RunLowLevel {
op: LowLevel::NotEq,
args: vec![
(len_var, Int(num_var, 0)),
(len_var, Int(num_var, num_percision_var, 0)),
(
len_var,
RunLowLevel {
@ -2155,7 +2168,7 @@ fn list_last(symbol: Symbol, var_store: &mut VarStore) -> Def {
ret_var: len_var,
},
),
(arg_var, Int(num_var, 1)),
(arg_var, Int(num_var, num_percision_var, 1)),
],
ret_var: len_var,
},

View file

@ -56,8 +56,8 @@ pub enum Expr {
Num(Variable, i64),
// Int and Float store a variable to generate better error messages
Int(Variable, i64),
Float(Variable, f64),
Int(Variable, Variable, i64),
Float(Variable, Variable, f64),
Str(InlinableString),
List {
list_var: Variable, // required for uniqueness of the list
@ -1170,8 +1170,8 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
// Num stores the `a` variable in `Num a`. Not the same as the variable
// stored in Int and Float below, which is strictly for better error messages
other @ Num(_, _)
| other @ Int(_, _)
| other @ Float(_, _)
| other @ Int(_, _, _)
| other @ Float(_, _, _)
| other @ Str { .. }
| other @ RuntimeError(_)
| other @ EmptyRecord

View file

@ -414,8 +414,8 @@ fn fix_values_captured_in_closure_expr(
}
Num(_, _)
| Int(_, _)
| Float(_, _)
| Int(_, _, _)
| Float(_, _, _)
| Str(_)
| Var(_)
| EmptyRecord

View file

@ -45,7 +45,7 @@ pub fn int_expr_from_result(
) -> Expr {
// Int stores a variable to generate better error messages
match result {
Ok(int) => Expr::Int(var_store.fresh(), int),
Ok(int) => Expr::Int(var_store.fresh(), var_store.fresh(), int),
Err((raw, error)) => {
let runtime_error = InvalidInt(error, base, region, raw.into());
@ -65,7 +65,7 @@ pub fn float_expr_from_result(
) -> Expr {
// Float stores a variable to generate better error messages
match result {
Ok(float) => Expr::Float(var_store.fresh(), float),
Ok(float) => Expr::Float(var_store.fresh(), var_store.fresh(), float),
Err((raw, error)) => {
let runtime_error = InvalidFloat(error, region, raw.into());