Skip to content

Commit

Permalink
Made error messages less terrible
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Jul 28, 2023
1 parent 1219f5e commit ad85abc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cargo build
FILENAME="$1"
# Compile standard library
./target/release/sloth std/stdio.sloth std/stdlib.sloth std/stdmath.sloth $FILENAME
./target/debug/sloth std/extern.sloth std/stdmath.sloth std/stdio.sloth $FILENAME

# Generate binary
clang -lm output.o std/stdio.c std/stdlib.c std/stdmath.c -o "${FILENAME%.sloth}"
Expand Down
41 changes: 24 additions & 17 deletions sloth/src/analysis/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ impl Populator {
.iter()
.map(|it| table.get_type(&it.typ))
.collect::<Option<Vec<_>>>()
.ok_or(AnalysisError::UnknownIdentifier(line, "0xOwO".to_owned()))?;
.ok_or(AnalysisError::UnknownIdentifier(
line,
"Error creating function inputs".to_owned(),
))?;

let output = output
.map(|it| table.get_type(it))
.unwrap_or(Some(Type::Void))
.ok_or(AnalysisError::UnknownIdentifier(line, "0xUwU".to_owned()))?;
.ok_or(AnalysisError::UnknownIdentifier(
line,
"Error creating function output".to_owned(),
))?;

Ok(Symbol::Value(ValueSymbol {
typ: Type::Function {
Expand Down Expand Up @@ -185,7 +191,7 @@ pub(super) fn propagate_types(node: &mut Expr) -> Result<(), AnalysisError> {
child
.typ
.clone()
.ok_or(AnalysisError::Unknown(node.line, "owo choco"))?
.ok_or(AnalysisError::Unknown(node.line, "Error at grouping"))?
}
ExprKind::Literal(lit) => match lit {
Literal::Integer(_) => Type::Integer,
Expand All @@ -203,7 +209,7 @@ pub(super) fn propagate_types(node: &mut Expr) -> Result<(), AnalysisError> {
last = Some(member.typ.clone().unwrap());
}

last.expect("need 1 element in literal im sozzy")
last.expect("Literal requires 1 element")
}
Literal::String(_) => Type::String,
_ => todo!(),
Expand Down Expand Up @@ -232,7 +238,7 @@ pub(super) fn propagate_types(node: &mut Expr) -> Result<(), AnalysisError> {
| BinaryOp::Mod => lhs
.typ
.clone()
.ok_or(AnalysisError::Unknown(node.line, "owo?? choco???"))?,
.ok_or(AnalysisError::Unknown(node.line, "Error propagating type"))?,
BinaryOp::Lt
| BinaryOp::Gt
| BinaryOp::LtEq
Expand All @@ -242,23 +248,24 @@ pub(super) fn propagate_types(node: &mut Expr) -> Result<(), AnalysisError> {
BinaryOp::LogicalAnd | BinaryOp::LogicalOr => lhs
.typ
.clone()
.ok_or(AnalysisError::Unknown(node.line, "owo?? choco???"))?,
BinaryOp::Range => Type::Iterator {
typ: Box::new(
lhs.typ
.clone()
.ok_or(AnalysisError::Unknown(node.line, "skill issue"))?,
),
},
.ok_or(AnalysisError::Unknown(node.line, "Error popagating type"))?,
BinaryOp::Range => {
Type::Iterator {
typ: Box::new(lhs.typ.clone().ok_or(AnalysisError::Unknown(
node.line,
"Error popagating type",
))?),
}
}
}
}
ExprKind::UnaryOp { value, .. } => {
propagate_types(value)?;

value.typ.clone().ok_or(AnalysisError::Unknown(
node.line,
"YOU'RE WRONG... SULFURIC ACID!",
))?
value
.typ
.clone()
.ok_or(AnalysisError::Unknown(node.line, "Error propagating type"))?
}
ExprKind::Call { callee, args } => {
propagate_types(callee)?;
Expand Down
9 changes: 6 additions & 3 deletions sloth/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'ctx> Codegen<'ctx> {
let current_ptr = self
.builder
.build_struct_gep(range_type, range_ptr, 0, "current")
.expect("Butter corn salt!");
.expect("Error creating current_ptr at for loop.");

let table = body.symtable.clone();
let symbol = table.get_value(identifier).unwrap();
Expand All @@ -186,7 +186,7 @@ impl<'ctx> Codegen<'ctx> {
let end_ptr = self
.builder
.build_struct_gep(range_type, range_ptr, 1, "end")
.expect("❌🧢");
.expect("Error creating end_ptr at for loop.");

self.builder.build_unconditional_branch(loop_bb);

Expand Down Expand Up @@ -464,7 +464,10 @@ impl<'ctx> Codegen<'ctx> {
// extracting an identifier to it. Change this
// so you can do for example `fn(){}()`.
let ExprKind::Identifier(ident) = &callee.kind else { panic!() };
let function = self.module.get_function(ident).expect("oh nooos");
let function = self
.module
.get_function(ident)
.unwrap_or_else(|| panic!("Function not found: {}", ident));

let args = args
.iter()
Expand Down
2 changes: 1 addition & 1 deletion sloth/src/parser/graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Error, Write};
us estd::fmt::{Error, Write};

use super::ast::{Expr, ExprKind, Function, FunctionKind, Stmt, StmtKind};

Expand Down

0 comments on commit ad85abc

Please sign in to comment.