From 72687d41678590fd71f8a55f7245d7d3802c73f8 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 27 Jun 2022 12:17:40 +0200 Subject: [PATCH] good error --- src/interpret.rs | 2 +- src/ir.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/interpret.rs b/src/interpret.rs index ee79686..9b57803 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -120,7 +120,7 @@ impl InterpretCtx { let is_ok = std::io::stdin().read_exact(slice).is_ok(); *self.reg_mut(Register(0)) = if is_ok { 0 } else { 1 }; } - _ => panic!("invalid interrupt!"), + _ => unreachable!("checked in compiler"), } } diff --git a/src/ir.rs b/src/ir.rs index 412635c..41420fb 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -102,7 +102,7 @@ impl CompileCtx { Stmt::Div { to, value } } StmtKind::Int { number } => { - if number > 1 { + if number > 2 { return Err(CompilerError::simple( "invalid interrupt".to_string(), p_stmt.span, @@ -155,7 +155,10 @@ impl CompileCtx { nested.span, "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 { match expr.kind { 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)?)), } }