gravlax
Advanced tools
Comparing version 0.12.5 to 0.12.6
@@ -31,2 +31,5 @@ import { LoxCallable } from "./callable.js"; | ||
} | ||
function getNumber(val) { | ||
return isCurrency(val) ? val.value : val; | ||
} | ||
function assertUnreachable(x) { | ||
@@ -75,4 +78,18 @@ throw new Error(`Unreachable code reached! ${x}`); | ||
checkNumberOrCurrencyOperand(operator, left); | ||
checkNumberOperand(operator, right); | ||
return applyToNumOrCurrency(left, (v) => v * right); | ||
checkNumberOrCurrencyOperand(operator, right); | ||
const curR = isCurrency(right); | ||
const value = getNumber(left) * getNumber(right); | ||
if (isCurrency(left)) { | ||
if (curR) { | ||
throw new RuntimeError(operator, "Cannot multiply two currencies."); | ||
} else { | ||
return { currency: left.currency, value }; | ||
} | ||
} else { | ||
if (curR) { | ||
return { currency: right.currency, value }; | ||
} else { | ||
return value; | ||
} | ||
} | ||
case "+": | ||
@@ -79,0 +96,0 @@ if (typeof left === "string" && typeof right === "string") { |
{ | ||
"name": "gravlax", | ||
"version": "0.12.5", | ||
"version": "0.12.6", | ||
"description": "A Lox interpreter with tasty TypeScript seasoning", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
146049
1583