Minor adjustments and update tests snapshots

This commit is contained in:
imaqtkatt 2024-02-07 08:50:31 -03:00
parent 784836f32b
commit c8ab1b31f6
12 changed files with 20 additions and 30 deletions

View File

@ -63,9 +63,6 @@ pub fn desugar_book(book: &mut Book, opts: CompileOpts) -> Result<(DefName, Vec<
if opts.supercombinators {
book.detach_supercombinators(&main);
}
if opts.inline {
book.inline();
}
if opts.ref_to_ref {
book.simplify_ref_to_ref()?;
}
@ -73,6 +70,9 @@ pub fn desugar_book(book: &mut Book, opts: CompileOpts) -> Result<(DefName, Vec<
book.simplify_main_ref(&main);
}
book.prune(Some(&main), opts.prune, &mut warnings);
if opts.inline {
book.inline();
}
if opts.merge {
book.merge_definitions(&main);
}

View File

@ -40,9 +40,9 @@ impl Pattern {
match self {
Pattern::Ctr(name, args) => {
let arity = arities.get(name).unwrap();
let n_args = args.len();
if *arity != n_args {
Err(format!("Arity error. Constructor '{name}' expects {arity} fields, found {n_args}."))
let args = args.len();
if *arity != args {
Err(format!("Arity error. Constructor '{}' expects {} fields, found {}.", name, arity, args))
} else {
Ok(())
}

View File

@ -4,17 +4,17 @@ use std::collections::HashSet;
impl Book {
pub fn inline(&mut self) {
let mut inlineable = HashSet::new();
let mut inlineables = HashSet::new();
for (def_name, def) in self.defs.iter() {
def.assert_no_pattern_matching_rules();
if def.rules[0].body.is_inlineable() {
inlineable.insert(def_name.clone());
inlineables.insert(def_name.clone());
}
}
let defs = self.defs.clone();
for (_, def) in &mut self.defs {
def.rules[0].body.inline(&inlineable, &defs);
for def in self.defs.values_mut() {
def.rules[0].body.inline(&inlineables, &defs);
}
}
}

View File

@ -8,10 +8,10 @@ pub mod encode_adts;
pub mod encode_pattern_matching;
pub mod eta_reduction;
pub mod flatten;
pub mod inline;
pub mod linearize;
pub mod resolve_ctrs_in_pats;
pub mod resolve_refs;
pub mod simplify_main_ref;
pub mod simplify_ref_to_ref;
pub mod unique_names;
pub mod inline;

View File

@ -6,6 +6,5 @@ input_file: tests/golden_tests/compile_file_o_all/and.hvm
@and = (a ({2 (b b) {2 @a (a c)}} c))
@false = {2 * {2 a a}}
@main = a
& @and ~ (@true (@false a))
@true = {2 a {2 * a}}
& @and ~ ({2 b {2 * b}} ({2 * {2 c c}} a))

View File

@ -2,9 +2,7 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file_o_all/bool.hvm
---
@Not = ((@fals (@true a)) a)
@fals = (* (a a))
@Not = (((* (a a)) ((b (* b)) c)) c)
@main = a
& @Not ~ (@true a)
@true = (a (* a))
& @Not ~ ((b (* b)) a)

View File

@ -4,7 +4,6 @@ input_file: tests/golden_tests/compile_file_o_all/ex0.hvm
---
@C_2 = ({3 (a b) (c a)} (c b))
@S = (a ((a b) (* b)))
@Z = (* (a a))
@main = a
& @C_2 ~ (@S (@Z a))
& @C_2 ~ (@S ((* (b b)) a))

View File

@ -4,6 +4,5 @@ input_file: tests/golden_tests/compile_file_o_all/extracted_match_pred.hvm
---
@main = a
& @val ~ (#1 a)
@val = (?<(@valZ @val) a> a)
@valZ = #0
@val = (?<(#0 @val) a> a)

View File

@ -2,7 +2,5 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file_o_all/long_name.hvm
---
@WowThis_is = (a a)
@main = (* a)
& @WowThis_is ~ (* a)
@main = (* *)

View File

@ -6,6 +6,5 @@ input_file: tests/golden_tests/compile_file_o_all/num_pattern_with_var.hvm
@a = (?<(#0 (a a)) b> b)
@b = (* #0)
@main = a
& @Foo ~ (@true (#3 a))
@true = {2 * {2 a a}}
& @Foo ~ ({2 * {2 b b}} (#3 a))

View File

@ -9,6 +9,6 @@ input_file: tests/golden_tests/compile_file_o_all/scrutinee_reconstruction.hvm
@b = {2 * @c}
@c = (a (* a))
@main = a
& @Option.or ~ (b (@None a))
& @Option.or ~ (b ({2 * {2 c c}} a))
& @Some ~ (#5 b)

View File

@ -2,7 +2,5 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file_o_all/var_shadows_ref.hvm
---
@a = (a a)
@main = a
& @a ~ ((b b) a)
@main = (a a)