mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DEV: Assert, Out, and Convert statements work.
This commit is contained in:
parent
f6a6a3ac32
commit
156b55271e
@ -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,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!();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user