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

View File

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