Skip to content

Commit

Permalink
fix: Expand macros inside macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Oct 5, 2019
1 parent 4aa9a73 commit 5a29433
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions vm/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use {
codespan_reporting::Diagnostic,
downcast_rs::{impl_downcast, Downcast},
futures::{stream, Future, Stream},
futures::Future,
};

use crate::base::{
Expand Down Expand Up @@ -325,39 +325,31 @@ impl<'a> MacroExpander<'a> {

pub fn run(&mut self, symbols: &mut Symbols, expr: &mut SpannedExpr<Symbol>) {
{
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);
Expand Down

0 comments on commit 5a29433

Please sign in to comment.