<commit_before>class Cpu
	constructor: (@bios) ->
		@debugger = null
		@reset()

	reset: ->
		@inscount = 0 # Number of instructions executed
		@mem = new Memory @, @bios
		@regs = [
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0
		]
		@hi = @lo = 0
		@pc = 0xbfc00000
		@delay = null # Delay slot for execution

		@cop0reg = [
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0
		]

	execute_one: ->
		@decompiling = false
		@inscount++
		@delayed = @delay
		cpc = if @delayed != null then @delay else @pc
		@delay = null
		if faux_interpret(cpc, @mem.uint32(cpc), @) == false
			inst = @mem.uint32 cpc
			phex32 cpc, inst, disassemble(cpc, inst)
			throw 'Unknown instruction'
		
		@pc += 4 if @delayed == null

	decompile_block: (pc) ->
		@decompiling = true
		total = ''
		emit = (snippet) -> code += snippet + '\n'
		branched = false
		branch = -> branched = true
		while true
			code = ''
			inst = @mem.uint32 pc
			if not decompile pc, inst, emit, branch
				return [false, pc + 4]
			pc += 4
			if branched
				tcode = code
				code = ''
				inst = @mem.uint32 pc
				if not decompile pc, inst, emit, branch
					return [false, pc + 4]
				pc += 4
				total += code
				total += tcode
				break
			else
				total += code

		func = eval('(function(state) { state.delayed = false;\n' + total + ' })')
		[true, pc, func]

	branch: (pc, recompiled=false) ->
		if recompiled
			@pc = pc
		else
			@debugger.branch @pc, pc if @debugger != null
			@delay = @pc + 4
			@pc = pc - 4 # Compensate for PC push<commit_msg>Added quick block cache.<commit_after>class Cpu
	constructor: (@bios) ->
		@debugger = null
		@reset()

	reset: ->
		@inscount = 0 # Number of instructions executed
		@mem = new Memory @, @bios
		@regs = [
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0
		]
		@hi = @lo = 0
		@pc = 0xbfc00000
		@delay = null # Delay slot for execution

		@cop0reg = [
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0, 
			0, 0, 0, 0, 0, 0, 0, 0
		]

		@last_block_pc = -1
		@last_block_func = null

	execute_one: ->
		@inscount++
		@delayed = @delay
		cpc = if @delayed != null then @delay else @pc
		@delay = null
		if faux_interpret(cpc, @mem.uint32(cpc), @) == false
			inst = @mem.uint32 cpc
			phex32 cpc, inst, disassemble(cpc, inst)
			throw 'Unknown instruction'
		
		@pc += 4 if @delayed == null

	decompile_block: (pc) ->
		if @last_block_pc == pc
			return [true, pc, @last_block_func]

		@last_block_pc = pc
		total = ''
		emit = (snippet) -> code += snippet + '\n'
		branched = false
		branch = -> branched = true
		while true
			code = ''
			inst = @mem.uint32 pc
			if not decompile pc, inst, emit, branch
				return [false, pc + 4]
			pc += 4
			if branched
				tcode = code
				code = ''
				inst = @mem.uint32 pc
				if not decompile pc, inst, emit, branch
					return [false, pc + 4]
				pc += 4
				total += code
				total += tcode
				break
			else
				total += code

		func = eval('(function(state) { state.delayed = false;\n' + total + ' })')
		@last_block_func = func
		[true, pc, func]

	branch: (pc, recompiled=false) ->
		if recompiled
			@pc = pc
		else
			@debugger.branch @pc, pc if @debugger != null
			@delay = @pc + 4
			@pc = pc - 4 # Compensate for PC push
{'fraction_non_alphanumeric': 0.1568281938325991, 'fraction_numerical': 0.05315712187958884, 'mean_word_length': 2.3556650246305417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587200', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1380, 'n_words': 465}