diff --git a/public/vm/Makefile b/public/vm/Makefile index 5a0a3fc..d83d2f2 100644 --- a/public/vm/Makefile +++ b/public/vm/Makefile @@ -1,4 +1,4 @@ -FILES = c0vm.js bytecode-parser.js byte-stream.js opcodes.js c0ffi.js index.js +FILES = c0vm.js bytecode-parser.js byte-stream.js opcodes.js c0ffi.js index.js all: $(FILES) browserify $(FILES) -o vm.js diff --git a/public/vm/c0vm.js b/public/vm/c0vm.js index 9f47047..fe73a80 100755 --- a/public/vm/c0vm.js +++ b/public/vm/c0vm.js @@ -3,7 +3,6 @@ op = require("./opcodes"); var INT_MIN = 0x80000000; var INT_MAX = 0x7FFFFFFF; -var verbose = false; function log(message) { if (verbose) console.log(message); } @@ -499,7 +498,7 @@ function run_vm(vm) { return vm; } } - + var val = vm.step(); if (val !== undefined) return val; @@ -528,7 +527,7 @@ function execute(file, callbacks, v) { function push(v) { console.log("Pretend I pushed " + v); } - + exports.execute = execute; exports.initialize_vm = initialize_vm; diff --git a/public/vm/index.js b/public/vm/index.js index 4b9d8ce..05d0232 100644 --- a/public/vm/index.js +++ b/public/vm/index.js @@ -2,56 +2,46 @@ parser = require("./bytecode-parser"); c0vm = require("./c0vm.js"); c0ffi = require("./c0ffi.js"); -// console.log("Reading in sample bytecode file:"); -// console.log(parser.getBytes("../test/test.bc0")); -// console.log("That was the sample bytecode file" + -// " -- it probably took up your whole terminal screen."); -// var file = parser.parse("../test/test.bc0"); -// console.log(file); -// console.log(file.function_pool[0].code); - // UI interaction functions function print(arg) { - // $("#output").append(arg); - $("#output").val($("#output").val() + arg); } callbacks = c0ffi.default_callbacks; // conio -callbacks[c0ffi.NATIVE_PRINT] = function(args) { - print(args[0]); - return 0; -} -callbacks[c0ffi.NATIVE_PRINTLN] = function(args) { - print(args[0]); - print("\n"); -} -callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) { - if (args[0]) - print("false"); - else - print("true"); -} -callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) { - print(String.fromCharCode(args[0])); -} -callbacks[c0ffi.NATIVE_READLINE] = function(args) { - return prompt("",""); -} -callbacks[c0ffi.NATIVE_PRINTINT] = function(args) { - print(args[0]); -} + callbacks[c0ffi.NATIVE_PRINT] = function(args) { + print(args[0]); + return 0; + } + callbacks[c0ffi.NATIVE_PRINTLN] = function(args) { + print(args[0]); + print("\n"); + } + callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) { + if (args[0]) + print("false"); + else + print("true"); + } + callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) { + print(String.fromCharCode(args[0])); + } + callbacks[c0ffi.NATIVE_READLINE] = function(args) { + return prompt("",""); + } + callbacks[c0ffi.NATIVE_PRINTINT] = function(args) { + print(args[0]); + } -console.log(callbacks); + console.log(callbacks); $("#run").click(function() { var input = $("#bytecode").val().replace(/(\r\n|\n|\r)/gm,""); $("#output").val(""); - + var file = parser.parse($("#bytecode").val()); - print(c0vm.execute(file, callbacks)); + c0vm.execute(file, callbacks, true); }); diff --git a/public/vm/vm.js b/public/vm/vm.js index 2c76175..67c86b4 100644 --- a/public/vm/vm.js +++ b/public/vm/vm.js @@ -319,6 +319,10 @@ callbacks[exports.NATIVE_STRING_COMPARE] = function(args) { return 0; } +callbacks[exports.NATIVE_STRING_EQUAL] = function(args) { + return args[0] === args[1]; +} + exports.default_callbacks = callbacks; },{}],4:[function(require,module,exports){ @@ -327,7 +331,6 @@ op = require("./opcodes"); var INT_MIN = 0x80000000; var INT_MAX = 0x7FFFFFFF; -var verbose = false; function log(message) { if (verbose) console.log(message); } @@ -823,7 +826,7 @@ function run_vm(vm) { return vm; } } - + var val = vm.step(); if (val !== undefined) return val; @@ -852,7 +855,7 @@ function execute(file, callbacks, v) { function push(v) { console.log("Pretend I pushed " + v); } - + exports.execute = execute; exports.initialize_vm = initialize_vm; @@ -864,58 +867,48 @@ parser = require("./bytecode-parser"); c0vm = require("./c0vm.js"); c0ffi = require("./c0ffi.js"); -// console.log("Reading in sample bytecode file:"); -// console.log(parser.getBytes("../test/test.bc0")); -// console.log("That was the sample bytecode file" + -// " -- it probably took up your whole terminal screen."); -// var file = parser.parse("../test/test.bc0"); -// console.log(file); -// console.log(file.function_pool[0].code); - // UI interaction functions function print(arg) { - // $("#output").append(arg); - $("#output").val($("#output").val() + arg); } callbacks = c0ffi.default_callbacks; // conio -callbacks[c0ffi.NATIVE_PRINT] = function(args) { - print(args[0]); - return 0; -} -callbacks[c0ffi.NATIVE_PRINTLN] = function(args) { - print(args[0]); - print("\n"); -} -callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) { - if (args[0]) - print("false"); - else - print("true"); -} -callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) { - print(String.fromCharCode(args[0])); -} -callbacks[c0ffi.NATIVE_READLINE] = function(args) { - return prompt("",""); -} -callbacks[c0ffi.NATIVE_PRINTINT] = function(args) { - print(args[0]); -} + callbacks[c0ffi.NATIVE_PRINT] = function(args) { + print(args[0]); + return 0; + } + callbacks[c0ffi.NATIVE_PRINTLN] = function(args) { + print(args[0]); + print("\n"); + } + callbacks[c0ffi.NATIVE_PRINTBOOL] = function(args) { + if (args[0]) + print("false"); + else + print("true"); + } + callbacks[c0ffi.NATIVE_PRINTCHAR] = function(args) { + print(String.fromCharCode(args[0])); + } + callbacks[c0ffi.NATIVE_READLINE] = function(args) { + return prompt("",""); + } + callbacks[c0ffi.NATIVE_PRINTINT] = function(args) { + print(args[0]); + } -console.log(callbacks); + console.log(callbacks); $("#run").click(function() { var input = $("#bytecode").val().replace(/(\r\n|\n|\r)/gm,""); $("#output").val(""); - + var file = parser.parse($("#bytecode").val()); - print(c0vm.execute(file, callbacks)); + c0vm.execute(file, callbacks, true); }); },{"./bytecode-parser":2,"./c0ffi.js":3,"./c0vm.js":4}],6:[function(require,module,exports){