mirror of
https://github.com/Noratrieb/crapderive.git
synced 2026-01-14 16:45:08 +01:00
good error
This commit is contained in:
parent
72fbc4e55a
commit
72687d4167
2 changed files with 12 additions and 4 deletions
|
|
@ -120,7 +120,7 @@ impl InterpretCtx {
|
||||||
let is_ok = std::io::stdin().read_exact(slice).is_ok();
|
let is_ok = std::io::stdin().read_exact(slice).is_ok();
|
||||||
*self.reg_mut(Register(0)) = if is_ok { 0 } else { 1 };
|
*self.reg_mut(Register(0)) = if is_ok { 0 } else { 1 };
|
||||||
}
|
}
|
||||||
_ => panic!("invalid interrupt!"),
|
_ => unreachable!("checked in compiler"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
src/ir.rs
14
src/ir.rs
|
|
@ -102,7 +102,7 @@ impl CompileCtx {
|
||||||
Stmt::Div { to, value }
|
Stmt::Div { to, value }
|
||||||
}
|
}
|
||||||
StmtKind::Int { number } => {
|
StmtKind::Int { number } => {
|
||||||
if number > 1 {
|
if number > 2 {
|
||||||
return Err(CompilerError::simple(
|
return Err(CompilerError::simple(
|
||||||
"invalid interrupt".to_string(),
|
"invalid interrupt".to_string(),
|
||||||
p_stmt.span,
|
p_stmt.span,
|
||||||
|
|
@ -155,7 +155,10 @@ impl CompileCtx {
|
||||||
nested.span,
|
nested.span,
|
||||||
"save the first result in a temporary register".to_string(),
|
"save the first result in a temporary register".to_string(),
|
||||||
)),
|
)),
|
||||||
ExprKind::Symbol(_) => todo!("compile to AddrLiteral"),
|
ExprKind::Symbol(_) => return Err(CompilerError::simple(
|
||||||
|
"symbol not allowed here".to_owned(),
|
||||||
|
expr.span,
|
||||||
|
))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +166,12 @@ impl CompileCtx {
|
||||||
fn compile_value(&mut self, expr: parser::Expr) -> Result<Value> {
|
fn compile_value(&mut self, expr: parser::Expr) -> Result<Value> {
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Number(n) => Ok(Value::Literal(n)),
|
ExprKind::Number(n) => Ok(Value::Literal(n)),
|
||||||
ExprKind::Symbol(_) => todo!("compile to Literal"),
|
ExprKind::Symbol(_) => {
|
||||||
|
return Err(CompilerError::simple(
|
||||||
|
"symbol not allowed here".to_owned(),
|
||||||
|
expr.span,
|
||||||
|
))
|
||||||
|
}
|
||||||
_ => Ok(Value::Place(self.compile_place(expr)?)),
|
_ => Ok(Value::Place(self.compile_place(expr)?)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue