<commit_before>#include "master.hpp"

namespace factor
{

static bool fep_disabled;
static bool full_output;

void print_chars(string* str)
{
	cell i;
	for(i = 0; i < string_capacity(str); i++)
		putchar(string_nth(str,i));
}

void print_word(word* word, cell nesting)
{
	if(tagged<object>(word->vocabulary).type_p(STRING_TYPE))
	{
		print_chars(untag<string>(word->vocabulary));
		print_string(":");
	}

	if(tagged<object>(word->name).type_p(STRING_TYPE))
		print_chars(untag<string>(word->name));
	else
	{
		print_string("#<not a string: ");
		print_nested_obj(word->name,nesting);
		print_string(">");
	}
}

void print_factor_string(string* str)
{
	putchar('"');
	print_chars(str);
	putchar('"');
}

void print_array(array* array, cell nesting)
{
	cell length = array_capacity(array);
	cell i;
	bool trimmed;

	if(length > 10 && !full_output)
	{
		trimmed = true;
		length = 10;
	}
	else
		trimmed = false;

	for(i = 0; i < length; i++)
	{
		print_string(" ");
		print_nested_obj(array_nth(array,i),nesting);
	}

	if(trimmed)
		print_string("...");
}

void print_tuple(tuple *tuple, cell nesting)
{
	tuple_layout *layout = untag<tuple_layout>(tuple->layout);
	cell length = to_fixnum(layout->size);

	print_string(" ");
	print_nested_obj(layout->klass,nesting);

	cell i;
	bool trimmed;

	if(length > 10 && !full_output)
	{
		trimmed = true;
		length = 10;
	}
	else
		trimmed = false;

	for(i = 0; i < length; i++)
	{
		print_string(" ");
		print_nested_obj(tuple->data()[i],nesting);
	}

	if(trimmed)
		print_string("...");
}

void print_nested_obj(cell obj, fixnum nesting)
{
	if(nesting <= 0 && !full_output)
	{
		print_string(" ... ");
		return;
	}

	quotation *quot;

	switch(tagged<object>(obj).type())
	{
	case FIXNUM_TYPE:
		print_fixnum(untag_fixnum(obj));
		break;
	case WORD_TYPE:
		print_word(untag<word>(obj),nesting - 1);
		break;
	case STRING_TYPE:
		print_factor_string(untag<string>(obj));
		break;
	case F_TYPE:
		print_string("f");
		break;
	case TUPLE_TYPE:
		print_string("T{");
		print_tuple(untag<tuple>(obj),nesting - 1);
		print_string(" }");
		break;
	case ARRAY_TYPE:
		print_string("{");
		print_array(untag<array>(obj),nesting - 1);
		print_string(" }");
		break;
	case QUOTATION_TYPE:
		print_string("[");
		quot = untag<quotation>(obj);
		print_array(untag<array>(quot->array),nesting - 1);
		print_string(" ]");
		break;
	default:
		print_string("#<type ");
		print_cell(tagged<object>(obj).type());
		print_string(" @ ");
		print_cell_hex(obj);
		print_string(">");
		break;
	}
}

void print_obj(cell obj)
{
	print_nested_obj(obj,10);
}

void print_objects(cell *start, cell *end)
{
	for(; start <= end; start++)
	{
		print_obj(*start);
		nl();
	}
}

void print_datastack()
{
	print_string("==== DATA STACK:\n");
	print_objects((cell *)ds_bot,(cell *)ds);
}

void print_retainstack()
{
	print_string("==== RETAIN STACK:\n");
	print_objects((cell *)rs_bot,(cell *)rs);
}

void print_stack_frame(stack_frame *frame)
{
	print_obj(frame_executing(frame));
	print_string("\n");
	print_obj(frame_scan(frame));
	print_string("\n");
	print_cell_hex((cell)frame_executing(frame));
	print_string(" ");
	print_cell_hex((cell)frame->xt);
	print_string("\n");
}
<commit_msg>debug.cpp: fep now prints return addresses in call stack dump<commit_after>#include "master.hpp"

namespace factor
{

static bool fep_disabled;
static bool full_output;

void print_chars(string* str)
{
	cell i;
	for(i = 0; i < string_capacity(str); i++)
		putchar(string_nth(str,i));
}

void print_word(word* word, cell nesting)
{
	if(tagged<object>(word->vocabulary).type_p(STRING_TYPE))
	{
		print_chars(untag<string>(word->vocabulary));
		print_string(":");
	}

	if(tagged<object>(word->name).type_p(STRING_TYPE))
		print_chars(untag<string>(word->name));
	else
	{
		print_string("#<not a string: ");
		print_nested_obj(word->name,nesting);
		print_string(">");
	}
}

void print_factor_string(string* str)
{
	putchar('"');
	print_chars(str);
	putchar('"');
}

void print_array(array* array, cell nesting)
{
	cell length = array_capacity(array);
	cell i;
	bool trimmed;

	if(length > 10 && !full_output)
	{
		trimmed = true;
		length = 10;
	}
	else
		trimmed = false;

	for(i = 0; i < length; i++)
	{
		print_string(" ");
		print_nested_obj(array_nth(array,i),nesting);
	}

	if(trimmed)
		print_string("...");
}

void print_tuple(tuple *tuple, cell nesting)
{
	tuple_layout *layout = untag<tuple_layout>(tuple->layout);
	cell length = to_fixnum(layout->size);

	print_string(" ");
	print_nested_obj(layout->klass,nesting);

	cell i;
	bool trimmed;

	if(length > 10 && !full_output)
	{
		trimmed = true;
		length = 10;
	}
	else
		trimmed = false;

	for(i = 0; i < length; i++)
	{
		print_string(" ");
		print_nested_obj(tuple->data()[i],nesting);
	}

	if(trimmed)
		print_string("...");
}

void print_nested_obj(cell obj, fixnum nesting)
{
	if(nesting <= 0 && !full_output)
	{
		print_string(" ... ");
		return;
	}

	quotation *quot;

	switch(tagged<object>(obj).type())
	{
	case FIXNUM_TYPE:
		print_fixnum(untag_fixnum(obj));
		break;
	case WORD_TYPE:
		print_word(untag<word>(obj),nesting - 1);
		break;
	case STRING_TYPE:
		print_factor_string(untag<string>(obj));
		break;
	case F_TYPE:
		print_string("f");
		break;
	case TUPLE_TYPE:
		print_string("T{");
		print_tuple(untag<tuple>(obj),nesting - 1);
		print_string(" }");
		break;
	case ARRAY_TYPE:
		print_string("{");
		print_array(untag<array>(obj),nesting - 1);
		print_string(" }");
		break;
	case QUOTATION_TYPE:
		print_string("[");
		quot = untag<quotation>(obj);
		print_array(untag<array>(quot->array),nesting - 1);
		print_string(" ]");
		break;
	default:
		print_string("#<type ");
		print_cell(tagged<object>(obj).type());
		print_string(" @ ");
		print_cell_hex(obj);
		print_string(">");
		break;
	}
}

void print_obj(cell obj)
{
	print_nested_obj(obj,10);
}

void print_objects(cell *start, cell *end)
{
	for(; start <= end; start++)
	{
		print_obj(*start);
		nl();
	}
}

void print_datastack()
{
	print_string("==== DATA STACK:\n");
	print_objects((cell *)ds_bot,(cell *)ds);
}

void print_retainstack()
{
	print_string("==== RETAIN STACK:\n");
	print_objects((cell *)rs_bot,(cell *)rs);
}

void print_stack_frame(stack_frame *frame)
{
	print_obj(frame_executing(frame));
	print_string("\n");
	print_obj(frame_scan(frame));
	print_string("\n");
	print_string("word/quot addr: ");
	print_cell_hex((cell)frame_executing(frame));
	print_string("\n");
	print_string("word/quot xt: ");
	print_cell_hex((cell)frame->xt);
	print_string("\n");
	print_string("return address: ");
	print_cell_hex((cell)FRAME_RETURN_ADDRESS(frame));
	print_string("\n");
}

{'fraction_non_alphanumeric': 0.18190058921287203, 'fraction_numerical': 0.005438888049554313, 'mean_word_length': 5.198501872659176, 'pattern_counts': {'":': 2, '<': 43, '<?xml version=': 0, '>': 59, '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': '3893601', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2603, 'n_words': 441}