Halfway done with evaluating tuples

This commit is contained in:
greg 2017-10-23 00:22:25 -07:00
parent 677e3ae0a9
commit 911f26e9c6
1 changed files with 14 additions and 2 deletions

View File

@ -26,7 +26,8 @@ enum FullyEvaluatedExpr {
Bool(bool), Bool(bool),
Custom { Custom {
string_rep: Rc<String>, string_rep: Rc<String>,
} },
Tuple(Vec<FullyEvaluatedExpr>),
} }
impl ReplState { impl ReplState {
@ -66,6 +67,7 @@ impl ReplState {
Str(s) => Some(format!("\"{}\"", s)), Str(s) => Some(format!("\"{}\"", s)),
Bool(b) => Some(format!("{}", b)), Bool(b) => Some(format!("{}", b)),
Custom { string_rep } => Some(format!("{}", string_rep)), Custom { string_rep } => Some(format!("{}", string_rep)),
Tuple(_items) => Some(format!("(tuple to be defined later)")),
} }
}) })
}, },
@ -112,7 +114,17 @@ impl ReplState {
PrefixExp(op, expr) => self.eval_prefix_exp(op, expr), PrefixExp(op, expr) => self.eval_prefix_exp(op, expr),
BinExp(op, lhs, rhs) => self.eval_binexp(op, lhs, rhs), BinExp(op, lhs, rhs) => self.eval_binexp(op, lhs, rhs),
Value(name, _) => self.eval_value(name), Value(name, _) => self.eval_value(name),
_ => Err(format!("Unimplemented")), TupleLiteral(expressions) => {
let mut evals = Vec::new();
for expr in expressions {
match self.eval_expr(expr) {
Ok(fully_evaluated) => evals.push(fully_evaluated),
error => return error,
}
}
Ok(Tuple(evals))
}
x => Err(format!("Unimplemented thing {:?}", x)),
} }
} }