From d9ac9e628dca08265dab2d25a49f3113964d5056 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 23 Feb 2025 03:21:34 -0600 Subject: [PATCH] cl-interpret: Stage items within a file in resolution order. TODO: Does this even help??? --- compiler/cl-interpret/src/interpret.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/cl-interpret/src/interpret.rs b/compiler/cl-interpret/src/interpret.rs index a5c946c..7528f82 100644 --- a/compiler/cl-interpret/src/interpret.rs +++ b/compiler/cl-interpret/src/interpret.rs @@ -22,18 +22,19 @@ impl Interpret for File { fn interpret(&self, env: &mut Environment) -> IResult { /// Sorts items #[derive(Debug, Default)] - struct ItemSorter<'ast>(pub [Vec<&'ast Item>; 6]); + struct ItemSorter<'ast>(pub [Vec<&'ast Item>; 8]); impl<'ast> Visit<'ast> for ItemSorter<'ast> { fn visit_item(&mut self, i: &'ast Item) { - self.0[match &i.kind { - ItemKind::Module(_) => 0, - ItemKind::Use(_) => 1, - ItemKind::Enum(_) | ItemKind::Struct(_) | ItemKind::Alias(_) => 2, - ItemKind::Function(_) => 3, - ItemKind::Impl(_) => 4, - ItemKind::Const(_) | ItemKind::Static(_) => 5, - }] - .push(i) + for stage in match &i.kind { + ItemKind::Module(_) => [0].as_slice(), + ItemKind::Use(_) => &[1, 6], + ItemKind::Enum(_) | ItemKind::Struct(_) | ItemKind::Alias(_) => &[2], + ItemKind::Function(_) => &[3, 7], + ItemKind::Impl(_) => &[4], + ItemKind::Const(_) | ItemKind::Static(_) => &[5], + } { + self.0[*stage].push(i) + } } }