From 5a2943300b9010acf3913c535c983f10af4c9ec7 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Sat, 5 Oct 2019 21:26:03 +0200 Subject: [PATCH] fix: Expand macros inside macros --- vm/src/macros.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/vm/src/macros.rs b/vm/src/macros.rs index b0e64f1b8e..b39faf1999 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -9,7 +9,7 @@ use std::{ use { codespan_reporting::Diagnostic, downcast_rs::{impl_downcast, Downcast}, - futures::{stream, Future, Stream}, + futures::Future, }; use crate::base::{ @@ -325,39 +325,31 @@ impl<'a> MacroExpander<'a> { pub fn run(&mut self, symbols: &mut Symbols, expr: &mut SpannedExpr) { { - let exprs = { - let mut visitor = MacroVisitor { - expander: self, - symbols, - exprs: Vec::new(), - }; - visitor.visit_expr(expr); - visitor.exprs + let mut visitor = MacroVisitor { + expander: self, + symbols, + exprs: Vec::new(), }; - let _ = stream::futures_ordered(exprs.into_iter().map(move |(expr, future)| { - future.then(move |result| -> Result<_, ()> { - match result { + let visitor = &mut visitor; + visitor.visit_expr(expr); + + while !visitor.exprs.is_empty() { + for (expr, future) in mem::replace(&mut visitor.exprs, Vec::new()) { + match future.wait() { Ok(mut replacement) => { replacement.span = expr.span; replace_expr(expr, replacement); - Ok(None) + visitor.visit_expr(expr); } Err(err) => { let expr_span = expr.span; replace_expr(expr, pos::spanned(expr_span, Expr::Error(None))); - Ok(Some(pos::spanned(expr.span, err))) + visitor.expander.errors.push(pos::spanned(expr.span, err)); } } - }) - })) - .for_each(|err| -> Result<(), ()> { - if let Some(err) = err { - self.errors.push(err); } - Ok(()) - }) - .wait(); + } } if self.errors.has_errors() { info!("Macro errors: {}", self.errors);