Skip to content

Commit

Permalink
allow breakpoint on first character
Browse files Browse the repository at this point in the history
  • Loading branch information
btzy committed Aug 23, 2017
1 parent 3a7e893 commit ae31180
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion jelly-bf-interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ JellyBFInterpreter=function(codeString,get_input,put_output,breakpointuint8array
}
if(loop_stack.length!==0)throw JellyBFInterpreter.CompileError.LOOPS_IMBALANCED;
this.next_instruction_index[last_instruction_index]=Number.MAX_SAFE_INTEGER;
this.instruction_ptr=this.entry_point;
// allow breakpointing first character:
var pseudo_entry_index=this.code.length;
this.code+="`";
this.next_instruction_index[pseudo_entry_index]=this.entry_point;
this.instruction_ptr=pseudo_entry_index;
};
JellyBFInterpreter.CompileError={
LOOPS_IMBALANCED:1
Expand Down Expand Up @@ -80,6 +84,9 @@ JellyBFInterpreter.prototype.run=function(){
else if(this.code[this.instruction_ptr]==="."){
this.put_output(Atomics.load(this.memory,this.memory_ptr));
}
else if(this.code[this.instruction_ptr]==="`"){
// don't do anything
}
else{
throw "Internal error!";
}
Expand Down
7 changes: 5 additions & 2 deletions jelly-bf-worker.max.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,10 @@ JellyBFInterpreter = function(codeString, get_input, put_output, breakpointuint8
}
if (loop_stack.length !== 0) throw JellyBFInterpreter.CompileError.LOOPS_IMBALANCED;
this.next_instruction_index[last_instruction_index] = Number.MAX_SAFE_INTEGER;
this.instruction_ptr = this.entry_point;
var pseudo_entry_index = this.code.length;
this.code += "`";
this.next_instruction_index[pseudo_entry_index] = this.entry_point;
this.instruction_ptr = pseudo_entry_index;
};

JellyBFInterpreter.CompileError = {
Expand Down Expand Up @@ -1612,7 +1615,7 @@ JellyBFInterpreter.prototype.run = function() {
Atomics.store(this.memory, this.memory_ptr, this.get_input());
} else if (this.code[this.instruction_ptr] === ".") {
this.put_output(Atomics.load(this.memory, this.memory_ptr));
} else {
} else if (this.code[this.instruction_ptr] === "`") {} else {
throw "Internal error!";
}
this.instruction_ptr = this.next_instruction_index[this.instruction_ptr];
Expand Down

0 comments on commit ae31180

Please sign in to comment.