Started working on better breakpoints

This commit is contained in:
Mitchell Plamann
2015-05-03 16:37:15 -04:00
parent 44f10cb5c6
commit 5e0529a1e0
29 changed files with 28 additions and 0 deletions

0
public/vm/byte-stream.js Executable file → Normal file
View File

View File

@@ -125,6 +125,26 @@ Bc0File.prototype.line_for_indices = function(function_index, byte_offset) {
return this.line_numbers[offset_in_file];
}
Bc0File.prototype.indicies_for_line = function(line) {
// Performs a linear search through the (bytecode to line number) map
// to find the bytecode offsets corresponding to a line number
var function_index = 0;
while (function_index < this.function_pool.length - 1) {
var function_start = this.function_pool[function_index + 1].code_byte_offset;
if (this.line_numbers[function_start] > line) break;
function_start++;
}
// function_index should now be set to the index of the function containing our line
var f = this.function_pool[function_index];
var offset = 0;
while (offset < f.code.length - 1) {
if (this.line_numbers[f.code_byte_offset + offset] > line) break;
offset++;
}
return [function_index, offset];
}
function parse(bytecode) {
return new Bc0File(bytecode);
}

8
public/vm/c0vm.js Executable file → Normal file
View File

@@ -514,6 +514,14 @@ ProgramState.prototype.set_breakpoint = function(function_index, opcode_index) {
this.breakpoints.push([function_index, opcode_index]);
}
ProgramState.prototype.set_breakpoint_bytecode_line = function(line) {
var indicies = this.file.indicies_for_line(line);
if (indicies === null || indicies.length < 2) {
console.log("Error - indicies_for_line returned an invalid result.");
}
this.set_breakpoint(indicies[0], indicies[1]);
}
ProgramState.prototype.run = function() {
while (true) {
for (var i = 0; i < this.breakpoints.length; i++) {

0
public/vm/cc0.cgi Executable file → Normal file
View File