diff --git a/experiments/maki-interpreter/cli.js b/experiments/maki-interpreter/cli.js index 55e084f1..9bf68417 100755 --- a/experiments/maki-interpreter/cli.js +++ b/experiments/maki-interpreter/cli.js @@ -10,7 +10,7 @@ function main() { const relativePath = process.argv[2]; const buffer = fs.readFileSync(path.join(__dirname, relativePath)); const system = new System(); - run({ runtime, buffer, system }); + run({ runtime, buffer, system, log: true }); } main(); diff --git a/experiments/maki-interpreter/interpreter.js b/experiments/maki-interpreter/interpreter.js index 166da474..f5c0ad68 100644 --- a/experiments/maki-interpreter/interpreter.js +++ b/experiments/maki-interpreter/interpreter.js @@ -2,7 +2,7 @@ const parse = require("./parser"); const { getClass } = require("./objects"); const interpret = require("./virtualMachine"); -function main({ runtime, buffer, system }) { +function main({ runtime, buffer, system, log }) { const program = parse(buffer); // Set the System global @@ -11,7 +11,7 @@ function main({ runtime, buffer, system }) { // Replace class hashes with actual JavaScript classes from the runtime program.classes = program.classes.map(hash => { const resolved = runtime[hash]; - if (resolved == null) { + if (resolved == null && log) { const klass = getClass(hash); console.warn( `Class missing from runtime: ${hash} expected ${klass.name}` @@ -23,7 +23,7 @@ function main({ runtime, buffer, system }) { // Bind toplevel handlers. program.bindings.forEach(binding => { const handler = () => { - return interpret(binding.commandOffset, program); + return interpret(binding.commandOffset, program, { log }); }; // For now we only know how to handle System handlers. diff --git a/experiments/maki-interpreter/interpreter.test.js b/experiments/maki-interpreter/interpreter.test.js new file mode 100644 index 00000000..f6e48cde --- /dev/null +++ b/experiments/maki-interpreter/interpreter.test.js @@ -0,0 +1,32 @@ +const fs = require("fs"); +const path = require("path"); +const System = require("./runtime/System"); +const runtime = require("./runtime"); +const interpret = require("./interpreter"); + +function runFile(relativePath) { + const system = new System(); + const buffer = fs.readFileSync(path.join(__dirname, relativePath)); + interpret({ runtime, buffer, system, log: false }); +} + +describe("v1.1.1.b3 (Winamp 3.0 full)", () => { + test("can call messageBox with hello World", () => { + const mockMessageBox = jest.fn(); + // The VM depends upon the arity of this function, so we can't use + // `mockMessageBox` directly. + System.prototype.messageBox = function(a, b, c, d) { + mockMessageBox(a, b, c, d); + }; + runFile( + "./reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki" + ); + expect(mockMessageBox).toHaveBeenCalledTimes(1); + expect(mockMessageBox).toHaveBeenCalledWith( + "Hello World", + "Hello Title", + 1, + null + ); + }); +}); diff --git a/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m new file mode 100755 index 00000000..4075b023 --- /dev/null +++ b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m @@ -0,0 +1,7 @@ +#include "lib/std.mi" + +System.onScriptLoaded() +{ + String response; + System.messageBox("Hello World", "Hello Title", 1, response); +} \ No newline at end of file diff --git a/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki new file mode 100755 index 00000000..237bcb6c Binary files /dev/null and b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki differ diff --git a/experiments/maki-interpreter/runtime/System.js b/experiments/maki-interpreter/runtime/System.js index c5134df6..fb3425f9 100644 --- a/experiments/maki-interpreter/runtime/System.js +++ b/experiments/maki-interpreter/runtime/System.js @@ -35,8 +35,8 @@ class System extends MakiObject { getParam() { return "Some String"; } - messagebox(message, var2, var3, var4) { - alert(message); + messageBox(message, msgtitle, flag, notanymoreId) { + console.log({ message, msgtitle, flag, notanymoreId }); } } diff --git a/experiments/maki-interpreter/virtualMachine.js b/experiments/maki-interpreter/virtualMachine.js index 97f01962..d2f7fe2d 100644 --- a/experiments/maki-interpreter/virtualMachine.js +++ b/experiments/maki-interpreter/virtualMachine.js @@ -1,7 +1,7 @@ const { printCommand } = require("./prettyPrinter"); -const log = true; -function interpret(start, { commands, methods, variables, classes }) { +function interpret(start, program, { log = false }) { + const { commands, methods, variables, classes } = program; // Run all the commands that are safe to run. Increment this number to find // the next bug. const stack = [];