mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-24 18:39:50 -04:00
Store the result of the last statement in the builder.
This commit is contained in:
parent
c71d668529
commit
0453a6043d
13
src/build.rs
13
src/build.rs
@ -191,6 +191,8 @@ pub struct Builder {
|
|||||||
files: HashSet<String>,
|
files: HashSet<String>,
|
||||||
/// out is our built output.
|
/// out is our built output.
|
||||||
out: ValueMap,
|
out: ValueMap,
|
||||||
|
/// last is the result of the last statement.
|
||||||
|
last: Option<Rc<Val>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! eval_binary_expr {
|
macro_rules! eval_binary_expr {
|
||||||
@ -239,6 +241,7 @@ impl Builder {
|
|||||||
assets: HashMap::new(),
|
assets: HashMap::new(),
|
||||||
files: HashSet::new(),
|
files: HashSet::new(),
|
||||||
out: HashMap::new(),
|
out: HashMap::new(),
|
||||||
|
last: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +250,7 @@ impl Builder {
|
|||||||
assets: HashMap::new(),
|
assets: HashMap::new(),
|
||||||
files: HashSet::new(),
|
files: HashSet::new(),
|
||||||
out: scope,
|
out: scope,
|
||||||
|
last: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,6 +555,7 @@ impl Builder {
|
|||||||
match stmt {
|
match stmt {
|
||||||
Statement::Let { name: sym, value: expr } => {
|
Statement::Let { name: sym, value: expr } => {
|
||||||
let val = try!(self.eval_expr(expr));
|
let val = try!(self.eval_expr(expr));
|
||||||
|
self.last = Some(val.clone());
|
||||||
match self.out.entry(sym) {
|
match self.out.entry(sym) {
|
||||||
Entry::Occupied(e) => {
|
Entry::Occupied(e) => {
|
||||||
return Err(Box::new(
|
return Err(Box::new(
|
||||||
@ -568,13 +573,15 @@ impl Builder {
|
|||||||
let mut b = Self::new();
|
let mut b = Self::new();
|
||||||
b.build_file(&val);
|
b.build_file(&val);
|
||||||
let fields: Vec<(String, Rc<Val>)> = b.out.drain().collect();
|
let fields: Vec<(String, Rc<Val>)> = b.out.drain().collect();
|
||||||
self.assets.entry(sym).or_insert(Rc::new(Val::Tuple(fields)));
|
let result = Rc::new(Val::Tuple(fields));
|
||||||
|
self.assets.entry(sym).or_insert(result.clone());
|
||||||
self.files.insert(val);
|
self.files.insert(val);
|
||||||
|
self.last = Some(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::Expression(ref expr) => {
|
Statement::Expression(expr) => {
|
||||||
// TODO(jwall): Is this just a noop? Maybe it's completely unnecessary?
|
self.last = Some(try!(self.eval_expr(expr)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user