mirror of
https://github.com/captbaritone/webamp.git
synced 2026-08-01 22:45:18 +00:00
Fix inconsistency with BOOL/BOOLEAN
This commit is contained in:
parent
fee323d302
commit
7b69ff2b02
5 changed files with 49 additions and 47 deletions
|
|
@ -146,14 +146,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -170,14 +170,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -195,14 +195,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -220,14 +220,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -304,15 +304,8 @@ class Interpreter {
|
|||
}
|
||||
const obj = this.stack.pop();
|
||||
assert(
|
||||
obj.type === "OBJECT",
|
||||
"Tried to call a method on a primitive."
|
||||
);
|
||||
assert(
|
||||
typeof obj.value === "object",
|
||||
"Trying to call a method on a not object"
|
||||
);
|
||||
assert(
|
||||
obj.value != null,
|
||||
(obj.type === "OBJECT" && typeof obj.value) === "object" &&
|
||||
obj.value != null,
|
||||
"Guru Meditation: Tried to call method on null object"
|
||||
);
|
||||
let value = obj.value[methodName](...methodArgs);
|
||||
|
|
@ -326,12 +319,15 @@ class Interpreter {
|
|||
// variables[1] holds global NULL value
|
||||
value = this.variables[1];
|
||||
}
|
||||
if (returnType === "BOOL") {
|
||||
if (returnType === "BOOLEAN") {
|
||||
assert(typeof value === "boolean", "BOOL should return a boolean");
|
||||
value = value ? 1 : 0;
|
||||
}
|
||||
if (returnType === "OBJECT") {
|
||||
assert(typeof value === "object", "not an object");
|
||||
assert(
|
||||
typeof value === "object",
|
||||
`Expected the returned value of ${klass.name}.${methodName} to be an object, but it was "${value}"`
|
||||
);
|
||||
}
|
||||
if (this.debug) {
|
||||
console.log(`Calling method ${methodName}`);
|
||||
|
|
@ -379,7 +375,7 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to increment a non-number.");
|
||||
}
|
||||
|
|
@ -394,7 +390,7 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to decrement a non-number.");
|
||||
}
|
||||
|
|
@ -409,7 +405,7 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to increment a non-number.");
|
||||
}
|
||||
|
|
@ -423,7 +419,7 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to increment a non-number.");
|
||||
}
|
||||
|
|
@ -437,7 +433,7 @@ class Interpreter {
|
|||
const b = this.stack.pop();
|
||||
switch (a.type) {
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error(
|
||||
`Tried to add non-numbers: ${b.type} + ${a.type}.`
|
||||
|
|
@ -451,7 +447,7 @@ class Interpreter {
|
|||
}
|
||||
switch (b.type) {
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
// TODO: Do we need to round the value if INT?
|
||||
|
|
@ -465,14 +461,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -487,14 +483,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -509,14 +505,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
// TODO: Do we need to round the value if INT?
|
||||
|
|
@ -530,14 +526,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
// Need to coerce LHS if not int, RHS is always int (enforced by compiler)
|
||||
case "FLOAT":
|
||||
|
|
@ -573,7 +569,7 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -588,14 +584,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
@ -614,14 +610,14 @@ class Interpreter {
|
|||
switch (a.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
switch (b.type) {
|
||||
case "STRING":
|
||||
case "OBJECT":
|
||||
case "BOOL":
|
||||
case "BOOLEAN":
|
||||
case "NULL":
|
||||
throw new Error("Tried to add non-numbers.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const objects: { [key: string]: ObjectDefinition } = {
|
|||
...config,
|
||||
};
|
||||
|
||||
export function getClass(id: String): ObjectDefinition {
|
||||
export function getClass(id: string): ObjectDefinition {
|
||||
return normalizedObjects[getFormattedId(id)];
|
||||
}
|
||||
|
||||
|
|
@ -35,9 +35,8 @@ export function getReturnType(classId: string, methodName: string): DataType {
|
|||
case "DOUBLE":
|
||||
case "STRING":
|
||||
case "FLOAT":
|
||||
return upper as any;
|
||||
case "BOOLEAN":
|
||||
return "BOOL";
|
||||
return upper as any;
|
||||
case "":
|
||||
return "NULL" as any;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { COMMANDS } from "./constants";
|
|||
import { DataType, Variable } from "./v";
|
||||
import MakiFile from "./MakiFile";
|
||||
import { getReturnType } from "./objects";
|
||||
import { assert } from "../utils";
|
||||
|
||||
export type Command = {
|
||||
opcode: number;
|
||||
|
|
@ -209,9 +210,13 @@ function readVariables({ makiFile, classes }) {
|
|||
let value = null;
|
||||
|
||||
switch (typeName) {
|
||||
// BOOLEAN
|
||||
// BOOL
|
||||
case PRIMITIVE_TYPES[5]:
|
||||
value = uinit1;
|
||||
assert(
|
||||
value === 1 || value === 0,
|
||||
"Expected boolean value to be initialized as zero or one"
|
||||
);
|
||||
break;
|
||||
// INT
|
||||
case PRIMITIVE_TYPES[2]:
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import BaseObject from "../skin/BaseObject";
|
|||
|
||||
export type Variable =
|
||||
| {
|
||||
type: "BOOL";
|
||||
value: boolean;
|
||||
type: "BOOLEAN";
|
||||
value: number; // 1 || 0
|
||||
}
|
||||
| {
|
||||
type: "INT" | "FLOAT" | "DOUBLE";
|
||||
|
|
@ -36,4 +36,7 @@ export const V = {
|
|||
newInt(value: number | boolean): Variable {
|
||||
return { type: "INT", value: Number(value) };
|
||||
},
|
||||
newBool(value: boolean): Variable {
|
||||
return { type: "BOOLEAN", value: value ? 1 : 0 };
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import GuiObj from "./GuiObj";
|
||||
import UI_ROOT from "../UIRoot";
|
||||
import { V } from "../maki/v";
|
||||
|
||||
// http://wiki.winamp.com/wiki/XML_GUI_Objects#.3Cbutton.2F.3E_.26_.3Ctogglebutton.2F.3E
|
||||
export default class Button extends GuiObj {
|
||||
|
|
@ -84,9 +85,7 @@ export default class Button extends GuiObj {
|
|||
|
||||
if (onoff !== this._active) {
|
||||
this._active = onoff;
|
||||
UI_ROOT.vm.dispatch(this, "onactivate", [
|
||||
{ type: "BOOL", value: onoff ? 1 : 0 },
|
||||
]);
|
||||
UI_ROOT.vm.dispatch(this, "onactivate", [V.newBool(onoff)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue