changed because Mitchell broke things

This commit is contained in:
2015-04-20 22:08:07 -04:00
parent 62d0e37984
commit 739005289e
5 changed files with 22 additions and 125 deletions

View File

@@ -1,4 +1,7 @@
FILES = c0vm.js bytecode-parser.js byte-stream.js opcodes.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
clean:
rm -f vm.js

View File

@@ -16,7 +16,7 @@ function print(arg) {
$("#output").append(arg);
}
callbacks = {};
callbacks = c0ffi.default_callbacks;
callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]);
print("<br />");
@@ -33,6 +33,9 @@ console.log(callbacks);
$("#run").click(function() {
var input = $("#bytecode").html().replace(/(\r\n|\n|\r)/gm,"");
$("#output").text("");
var file = parser.parse($("#bytecode").text());
print("<br />");
print(c0vm.execute(file, callbacks));

View File

@@ -299,7 +299,6 @@ function i32_to_array(i32) {
((i32 >> 8) & 0xFF),
((i32 >> 16) & 0xFF),
((i32 >> 24) & 0xFF)];
}
function array_to_i32(array) {
@@ -334,13 +333,13 @@ var ProgramState = function(parsed_file, callback_dict) {
try {
this.natives[i] = callback_dict[i];
} catch (key_not_found) {
this.natives[i] = function (arg) {
this.natives[i] = function (arg) {
console.log("Native function " + name + " called, ran method stub.");
return 0;
};
}
}
// Memory is just a big array of bytes, right?
// "Allocation" is appending onto this array
// A pointer to memory is an index into this array.
@@ -409,7 +408,7 @@ ProgramState.prototype.step = function() {
case op.BIPUSH:
this.frame.pc += 2;
var val = this.frame.program[this.frame.pc-1];
// Do sign extension if necessary
if ((val & 0x80) != 0)
val = -0x80 + (val & 0x7F);
@@ -611,7 +610,7 @@ ProgramState.prototype.step = function() {
};
console.log("Unknown native function index " + f.function_table_index);
}
log("Calling native function with index " + index + " with arguments " +
log("Calling native function with index " + index + " with arguments " +
arg_array);
this.push(native_function(arg_array));
break;
@@ -623,7 +622,7 @@ ProgramState.prototype.step = function() {
var address = this.heap.length;
for (var i = 0; i < size; i++) this.heap.push(0);
this.push(address);
this.frame.pc += 2;
break;
@@ -636,7 +635,7 @@ ProgramState.prototype.step = function() {
this.heap.push(num_elements);
this.heap.push(size);
for (var i = 0; i < num_elements; i++) {
for (var j = 0; j < size; j++)
this.heap.push(0);
@@ -752,7 +751,7 @@ function execute(file, callbacks, v) {
if (verbose) log(file);
log("Beginning execution");
while (true) {
var val = state.step();
if (val !== undefined) return val;
@@ -771,7 +770,7 @@ function execute(file, callbacks, v) {
// save state (maybe in a global in this file?)
// return;
// }
}
}
}
exports.execute = execute;
@@ -795,7 +794,7 @@ function print(arg) {
$("#output").append(arg);
}
callbacks = {};
callbacks = c0ffi.default_callbacks;
callbacks[c0ffi.NATIVE_PRINT] = function(args) {
print(args[0]);
print("<br />");
@@ -812,6 +811,9 @@ console.log(callbacks);
$("#run").click(function() {
var input = $("#bytecode").html().replace(/(\r\n|\n|\r)/gm,"");
$("#output").text("");
var file = parser.parse($("#bytecode").text());
print("<br />");
print(c0vm.execute(file, callbacks));
@@ -926,4 +928,4 @@ exports.lookup_table = {
},{}],7:[function(require,module,exports){
},{}]},{},[4,2,1,6,5]);
},{}]},{},[4,2,1,6,3,5]);