mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
simplify type coercion / fix destructuring related error (#807)
This commit is contained in:
parent
9007b1c4ee
commit
e8e49103a9
1 changed files with 8 additions and 8 deletions
|
|
@ -3,11 +3,11 @@ const Variable = require("./variable");
|
|||
function coerceTypes (var1, var2, val1, val2) {
|
||||
if (var2.type === 'INT') {
|
||||
if (var1.type === 'FLOAT' || var1.type === 'DOUBLE') {
|
||||
return [Math.floor(val1), val2];
|
||||
return Math.floor(val1);
|
||||
}
|
||||
}
|
||||
|
||||
return [val1, val2];
|
||||
return val1;
|
||||
}
|
||||
|
||||
async function interpret(start, program, { logger = null }) {
|
||||
|
|
@ -40,7 +40,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
// and variables on the stack.
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(aValue === bValue);
|
||||
break;
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
const b = stack.pop();
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(aValue !== bValue);
|
||||
break;
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
const b = stack.pop();
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(bValue > aValue);
|
||||
break;
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
const b = stack.pop();
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(bValue >= aValue);
|
||||
break;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
const b = stack.pop();
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(bValue < aValue);
|
||||
break;
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ async function interpret(start, program, { logger = null }) {
|
|||
const b = stack.pop();
|
||||
let aValue = a instanceof Variable ? a.getValue() : a;
|
||||
let bValue = b instanceof Variable ? b.getValue() : b;
|
||||
[aValue, bValue] = coerceTypes(a, b, aValue, bValue);
|
||||
aValue = coerceTypes(a, b, aValue, bValue);
|
||||
stack.push(bValue <= aValue);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue