Also store f64 for things like pattern comparisons, etc

This commit is contained in:
Jared Ramirez 2021-08-18 17:18:13 -07:00
parent adabf70132
commit d69b9173fc
18 changed files with 195 additions and 252 deletions

View file

@ -3,8 +3,8 @@ use crate::builtins::builtin_defs_map;
use crate::def::{can_defs_with_return, Def};
use crate::env::Env;
use crate::num::{
finish_parsing_base, finish_parsing_int, float_expr_from_result, int_expr_from_result,
num_expr_from_result, validate_float_str,
finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result,
int_expr_from_result, num_expr_from_result,
};
use crate::pattern::{canonicalize_pattern, Pattern};
use crate::procedure::References;
@ -52,11 +52,11 @@ pub enum 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
Num(Variable, Box<str>),
Num(Variable, Box<str>, i64),
// Int and Float store a variable to generate better error messages
Int(Variable, Variable, Box<str>),
Float(Variable, Variable, Box<str>),
Int(Variable, Variable, Box<str>, i128),
Float(Variable, Variable, Box<str>, f64),
Str(Box<str>),
List {
elem_var: Variable,
@ -206,10 +206,10 @@ pub fn canonicalize_expr<'a>(
use Expr::*;
let (expr, output) = match expr {
ast::Expr::Num(string) => {
ast::Expr::Num(str) => {
let answer = num_expr_from_result(
var_store,
finish_parsing_int(*string).map(|_| *string),
finish_parsing_int(*str).map(|int| (*str, int)),
region,
env,
);
@ -219,7 +219,7 @@ pub fn canonicalize_expr<'a>(
ast::Expr::Float(str) => {
let answer = float_expr_from_result(
var_store,
validate_float_str(str).map(|()| *str),
finish_parsing_float(str).map(|f| (*str, f)),
region,
env,
);
@ -810,7 +810,7 @@ pub fn canonicalize_expr<'a>(
// to keep borrowed values around and make this compile
let int_string = int.to_string();
let int_str = int_string.as_str();
int_expr_from_result(var_store, Ok(int_str), region, *base, env)
int_expr_from_result(var_store, Ok((int_str, int as i128)), region, *base, env)
}
Err(e) => int_expr_from_result(var_store, Err(e), region, *base, env),
};
@ -1234,9 +1234,9 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
match 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 @ Num(_, _, _)
| other @ Int(_, _, _, _)
| other @ Float(_, _, _, _)
| other @ Str { .. }
| other @ RuntimeError(_)
| other @ EmptyRecord