From ae311809ee98d7797b7d3f57d273a46399560869 Mon Sep 17 00:00:00 2001 From: Bernard Teo Date: Wed, 23 Aug 2017 15:41:25 +0800 Subject: [PATCH] allow breakpoint on first character --- jelly-bf-interpreter.js | 9 ++++++++- jelly-bf-worker.max.js | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jelly-bf-interpreter.js b/jelly-bf-interpreter.js index d2c25c1..e2c0bc9 100644 --- a/jelly-bf-interpreter.js +++ b/jelly-bf-interpreter.js @@ -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 @@ -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!"; } diff --git a/jelly-bf-worker.max.js b/jelly-bf-worker.max.js index edd9793..67b1166 100644 --- a/jelly-bf-worker.max.js +++ b/jelly-bf-worker.max.js @@ -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 = { @@ -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];