Updated tests to work with new parser changes
This commit is contained in:
@@ -4,21 +4,8 @@ byte_stream = require("./byte-stream");
|
||||
// This is a simple, kinda hacky bytecode parser for .bc0 files
|
||||
// Now takes in raw bytecode
|
||||
function getBytes(data) {
|
||||
/*
|
||||
var data = fs.readFileSync(filename);
|
||||
|
||||
if (data == null) {
|
||||
if (err["code"] === "ENOENT")
|
||||
console.log("Error: file " + filename + " does not exist.");
|
||||
else
|
||||
console.log("Error: " + err);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// Data contains our file, but we want it as a string
|
||||
var string_data = data.toString();
|
||||
console.log(string_data);
|
||||
|
||||
// Strip all the comments for easier parsing
|
||||
var without_comments = string_data.replace(new RegExp("#.*", "gi"), "");
|
||||
@@ -33,7 +20,6 @@ function getBytes(data) {
|
||||
});
|
||||
|
||||
// We now have an array of bytes. That's probably everything we need, right?
|
||||
console.log(bytes);
|
||||
return bytes;
|
||||
|
||||
}
|
||||
@@ -109,9 +95,24 @@ Bc0File.prototype.string_from_index = function (i) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function parse(filename) {
|
||||
return new Bc0File(filename);
|
||||
function parse(bytecode) {
|
||||
return new Bc0File(bytecode);
|
||||
}
|
||||
|
||||
function parseFile(filename) {
|
||||
var data = fs.readFileSync(filename);
|
||||
|
||||
if (data == null) {
|
||||
if (err["code"] === "ENOENT")
|
||||
console.log("Error: file " + filename + " does not exist.");
|
||||
else
|
||||
console.log("Error: " + err);
|
||||
return;
|
||||
}
|
||||
|
||||
return parse(data);
|
||||
}
|
||||
|
||||
exports.getBytes = getBytes;
|
||||
exports.parse = parse;
|
||||
exports.parseFile = parseFile;
|
||||
|
||||
@@ -545,10 +545,6 @@ function run_vm(vm) {
|
||||
}
|
||||
}
|
||||
|
||||
// if (at_breakpoint) {
|
||||
// save state (maybe in a global in this file?)
|
||||
// return;
|
||||
// }
|
||||
// Takes in a parsed .bc0 file and runs it
|
||||
function execute(file, callbacks, v) {
|
||||
var state = initialize_vm(file, callbacks, v);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
parser = require("../src/bytecode-parser.js");
|
||||
c0vm = require("../src/c0vm.js");
|
||||
c0ffi = require("../src/c0ffi.js");
|
||||
parser = require("../public/vm/bytecode-parser.js");
|
||||
c0vm = require("../public/vm/c0vm.js");
|
||||
c0ffi = require("../public/vm/c0ffi.js");
|
||||
|
||||
var callbacks = c0ffi.default_callbacks;
|
||||
console.log("Initial callbacks: " + callbacks[c0ffi.NATIVE_STRING_LENGTH](["hi"]));
|
||||
@@ -23,7 +23,7 @@ callbacks[c0ffi.NATIVE_PRINTLN] = function(args) {
|
||||
|
||||
function doTest(filename, expected_result) {
|
||||
return function(test) {
|
||||
var result = c0vm.execute(parser.parse(filename), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile(filename), callbacks, false);
|
||||
test.ok(result == expected_result,
|
||||
filename + " - did not get expected result " + expected_result +
|
||||
", instead got " + result);
|
||||
@@ -35,7 +35,7 @@ exports.testIADD = doTest("iadd.c0.bc0", -2);
|
||||
|
||||
exports.testPrint = function(test) {
|
||||
printout = "";
|
||||
var result = c0vm.execute(parser.parse("test.bc0"), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile("test.bc0"), callbacks, false);
|
||||
test.ok(printout == "Hello, world.\nYou don't look so good.\n",
|
||||
"test.bc0 - Did not print to screen correctly: output was " + printout);
|
||||
test.done();
|
||||
@@ -50,7 +50,7 @@ exports.testMID = doTest("mid.c0.bc0", 155);
|
||||
// This one should throw an exception because an assertion fails
|
||||
exports.testSample25 = function(test) {
|
||||
test.throws(function () {
|
||||
c0vm.execute(parser.parse("sample2.5.c0.bc0"), callbacks, false)
|
||||
c0vm.execute(parser.parseFile("sample2.5.c0.bc0"), callbacks, false)
|
||||
});
|
||||
test.done();
|
||||
}
|
||||
@@ -61,14 +61,14 @@ exports.testDSQUARED = doTest("dsquared.c0.bc0", 17068);
|
||||
|
||||
exports.testArrays = function(test) {
|
||||
test.throws(function () {
|
||||
c0vm.execute(parser.parse("arrays.c0.bc0"), callbacks, false)
|
||||
c0vm.execute(parser.parseFile("arrays.c0.bc0"), callbacks, false)
|
||||
});
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports.testMoreArray = function(test) {
|
||||
printout = "";
|
||||
var result = c0vm.execute(parser.parse("moreArrays.c0.bc0"), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile("moreArrays.c0.bc0"), callbacks, false);
|
||||
test.ok(printout == "2312",
|
||||
"moreArrays.c0.bc0 - Did not print to screen correctly, result was " +
|
||||
printout);
|
||||
@@ -77,7 +77,7 @@ exports.testMoreArray = function(test) {
|
||||
|
||||
exports.testStructs = function(test) {
|
||||
printout = "";
|
||||
var result = c0vm.execute(parser.parse("structs.c0.bc0"), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile("structs.c0.bc0"), callbacks, false);
|
||||
test.ok(printout == "potato chip123",
|
||||
"structs.c0.bc0 - Did not print to screen correctly, result was " +
|
||||
printout);
|
||||
@@ -86,14 +86,14 @@ exports.testStructs = function(test) {
|
||||
|
||||
exports.testAbort = function(test) {
|
||||
test.throws(function () {
|
||||
c0vm.execute(parser.parse("abort.c0.bc0"), callbacks, false);
|
||||
c0vm.execute(parser.parseFile("abort.c0.bc0"), callbacks, false);
|
||||
});
|
||||
test.done();
|
||||
}
|
||||
|
||||
exports.testArith = function(test) {
|
||||
printout = "";
|
||||
var result = c0vm.execute(parser.parse("arith.c0.bc0"), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile("arith.c0.bc0"), callbacks, false);
|
||||
test.ok(printout == "-2147483648 2147483647 -375 -2147483648 -9 -1 12 \n-12 12 Modulus testing 11-1 5 1 Testing constants -251 Testing inequalities \ny1 y2 y3 n4 n5 n6 y7 Testing bitwise operators \n992000 1045310 53250 -12083 Testing bit shifting\n-2147483648 7360588088-31-19\n",
|
||||
"arith.c0.bc0 - Did not print to screen correctly, result was " +
|
||||
printout);
|
||||
@@ -104,7 +104,7 @@ exports.testPIAZZA1 = doTest("piazza1.c0.bc0", 18);
|
||||
|
||||
exports.testSTRINGS = function(test) {
|
||||
printout = "";
|
||||
var result = c0vm.execute(parser.parse("strings.c0.bc0"), callbacks, false);
|
||||
var result = c0vm.execute(parser.parseFile("strings.c0.bc0"), callbacks, false);
|
||||
test.ok(printout == "hello there!?",
|
||||
"strings.c0.bc0 - Did not print to screen correctly, result was " +
|
||||
printout);
|
||||
|
||||
Reference in New Issue
Block a user