diff --git a/test/ishr.c0 b/test/ishr.c0 new file mode 100644 index 0000000..884a533 --- /dev/null +++ b/test/ishr.c0 @@ -0,0 +1,3 @@ +int main () { + return -1 >> 1; /* should return -1 */ +} diff --git a/test/ishr.c0.bc0 b/test/ishr.c0.bc0 new file mode 100644 index 0000000..34f85f9 --- /dev/null +++ b/test/ishr.c0.bc0 @@ -0,0 +1,24 @@ +C0 C0 FF EE # magic number +00 09 # version 4, arch = 1 (64 bits) + +00 00 # int pool count +# int pool + +00 00 # string pool total size +# string pool + +00 01 # function count +# function_pool + +#
+00 00 # number of arguments = 0 +00 00 # number of local variables = 0 +00 06 # code length = 6 bytes +10 FF # bipush -1 # -1 +10 01 # bipush 1 # 1 +7A # ishr # (-(1) >> 1) +B0 # return # + +00 00 # native count +# native pool + diff --git a/test/ishr.c0.bc0out b/test/ishr.c0.bc0out new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/test/ishr.c0.bc0out @@ -0,0 +1 @@ +-1 diff --git a/test/ishr.c0.c0out b/test/ishr.c0.c0out new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/test/ishr.c0.c0out @@ -0,0 +1 @@ +-1 diff --git a/test/ishr.c0.ex b/test/ishr.c0.ex new file mode 100755 index 0000000..a8e8013 Binary files /dev/null and b/test/ishr.c0.ex differ diff --git a/test/tests.js b/test/tests.js new file mode 100644 index 0000000..334bf81 --- /dev/null +++ b/test/tests.js @@ -0,0 +1,23 @@ +parser = require("../src/bytecode-parser.js") +c0vm = require("../src/c0vm.js") + +var callbacks = {} + +// Tests that IADD, BIPUSH, and RETURN (from main) work +exports.testIADD = function(test) { + var result = c0vm.execute(parser.parse("iadd.c0.bc0"), callbacks, false); + test.ok(result == -2, "iadd.c0.bc0 - Error in IADD, BIPUSH, or RETURN"); + test.done(); +}; + +exports.testPrint = function(test) { + var result = c0vm.execute(parser.parse("test.bc0"), callbacks, false); + test.ok(result == 0, "test.bc0 - Did not print to screen correctly"); + test.done(); +} + +exports.testISHR = function(test) { + var result = c0vm.execute(parser.parse("ishr.c0.bc0"), callbacks, false); + test.ok(result == -1, "ishr.c0.bc0 - -1 >> 1 gave " + result + ", not -1"); + test.done(); +}