1
0
Fork 0

add div/0 check

This commit is contained in:
Sean Sube 2022-09-30 22:28:23 -05:00
parent e553b51dc0
commit 45a6f2d034
1 changed files with 5 additions and 1 deletions

View File

@ -13,7 +13,11 @@ export function evalBin(b: Result<BinExpr>): Result<number> {
case '*':
return emitCont(br.lhs.val * br.rhs.val, b.rem);
case '/':
return emitCont(br.lhs.val / br.rhs.val, b.rem);
if (br.rhs.val === 0) {
return emitBack(b.rem);
} else {
return emitCont(br.lhs.val / br.rhs.val, b.rem);
}
default:
return emitBack(b.rem);
}