feat: error handling (WIP)

This commit is contained in:
2025-05-15 19:44:38 +08:00
parent 1e50322af0
commit ed28efb623
4 changed files with 44 additions and 40 deletions

View File

@@ -12,15 +12,15 @@ pub fn env<'vm>(vm: &'vm VM) -> Rc<Env<'vm>> {
let primops = [
PrimOp::new("add", 2, |_, args| {
let [first, second]: [Value; 2] = args.try_into().unwrap();
first.add(second)
first.add(second).ok()
}),
PrimOp::new("sub", 2, |_, args| {
let [first, second]: [Value; 2] = args.try_into().unwrap();
first.add(second.neg())
first.add(second.neg()).ok()
}),
PrimOp::new("mul", 2, |_, args| {
let [first, second]: [Value; 2] = args.try_into().unwrap();
first.mul(second)
first.mul(second).ok()
}),
PrimOp::new("div", 2, |_, args| {
let [first, second]: [Value; 2] = args.try_into().unwrap();
@@ -28,17 +28,17 @@ pub fn env<'vm>(vm: &'vm VM) -> Rc<Env<'vm>> {
}),
PrimOp::new("lessThan", 2, |_, args| {
let [first, second]: [Value; 2] = args.try_into().unwrap();
first.lt(second)
first.lt(second).ok()
}),
PrimOp::new("seq", 2, |vm, args| {
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
first.force(vm).unwrap();
second
second.ok()
}),
PrimOp::new("deepSeq", 2, |vm, args| {
let [mut first, second]: [Value; 2] = args.try_into().unwrap();
first.force_deep(vm).unwrap();
second
second.ok()
}),
];