# debug_tools

if $ARGS[0] = 'trace':
	if $ARGS[1] = 'loc_change':
		if debug['trace_loc_change'] = 0: exit
		$debug['trace_line'] = "'<<$curloc>>'"
	elseif $ARGS[1] = 'direct':
		if arrsize('$trace_locations') = 0: exit
		if arrpos("$trace_locations", $ARGS[2]) = -1: exit
		$debug['trace_line'] = "'<<$ARGS[2]>>'"
	else
		exit
	end

	debug['trace_index'] = 0
	:trace_loc_change_loop
	if debug['trace_index'] < arrsize("$trace_args"):
		if $trace_args[debug['trace_index']] ! '':
			$debug['trace_line'] += ", '<<$trace_args[debug['trace_index']]>>'"
		elseif trace_args[debug['trace_index']] ! 0:
			$debug['trace_line'] += ", <<trace_args[debug['trace_index']]>>"
		else
			$debug['trace_line'] += ", /DEF"
		end
		debug['trace_index'] += 1
		jump 'trace_loc_change_loop'
	end
	! killvar 'call_trace_index'
	killvar '$trace_args' & killvar 'trace_args'

	$debug['<<$ARGS[1]>>_trace'] += $debug['trace_line'] + '<br>'
	! killvar '$call_trace_line'
	if debug['trace_shown'] ! 0: gs 'stat_display'
!?end

elseif $ARGS[0] = 'trace_list_locs':
	tmp_i = 0
	:list_locs_loop
	if tmp_i < arrsize('$trace_locations'):
		$tmp_msg += $trace_locations[tmp_i] + '<br>'
		tmp_i += 1
		jump 'list_locs_loop'
	end
	msg $tmp_msg
	killvar 'tmp_i' & killvar '$tmp_msg'
!?end

elseif $ARGS[0] = 'reset':
	$debug['loc_change_trace'] = ''
	$debug['direct_trace'] = ''
end

--- debug_tools ---------------------------------

