DEV: Assert, Out, and Convert statements work.

This commit is contained in:
Jeremy Wall 2019-08-21 19:50:31 -05:00
parent f6a6a3ac32
commit 156b55271e
2 changed files with 18 additions and 11 deletions

View File

@ -307,7 +307,8 @@ impl Builtins {
let val = stack.pop();
if let Some((val, val_pos)) = val {
let val = val.try_into()?;
if let Some((c_type_val, c_type_pos)) = stack.pop() {
let c_type = stack.pop();
if let Some((c_type_val, c_type_pos)) = c_type {
if let &Value::S(ref c_type) = c_type_val.as_ref() {
if let Some(c) = env.borrow().converter_registry.get_converter(c_type) {
if let Err(e) = c.convert(Rc::new(val), &mut writer) {
@ -321,12 +322,12 @@ impl Builtins {
)));
}
}
}
return Err(dbg!(Error::new(
format!("Not a conversion type {:?}", val),
format!("Not a conversion type {:?}", c_type_val),
val_pos,
)));
}
}
unreachable!();
}

View File

@ -60,8 +60,9 @@ impl AST {
Self::translate_expr(expr, &mut ops, root);
ops.push(Op::Pop, expr_pos);
}
Statement::Assert(_, _) => {
unimplemented!("Assert statements are not implmented yet")
Statement::Assert(pos, expr) => {
Self::translate_expr(expr, &mut ops, root);
ops.push(Op::Runtime(Hook::Assert), pos);
}
Statement::Let(def) => {
let binding = def.name.fragment;
@ -69,11 +70,16 @@ impl AST {
Self::translate_expr(def.value, &mut ops, root);
ops.push(Op::Bind, def.pos);
}
Statement::Output(_, _, _) => {
unimplemented!("Out statements are not implmented yet")
Statement::Output(pos, tok, expr) => {
ops.push(Op::Val(Primitive::Str(tok.fragment)), tok.pos);
Self::translate_expr(expr, &mut ops, root);
ops.push(Op::Runtime(Hook::Out), pos);
}
Statement::Print(_, _, _) => {
unimplemented!("Print statements are not implmented yet")
Statement::Print(pos, tok, expr) => {
ops.push(Op::Val(Primitive::Str(tok.fragment)), tok.pos);
Self::translate_expr(expr, &mut ops, root);
ops.push(Op::Runtime(Hook::Convert), pos.clone());
ops.push(Op::Pop, pos);
}
}
}