<commit_before>#include "value.h"
#include "die.h"
#include "eval.h"
#include "run.h"

int arg(type T, value x)
	{
	if (x->T == 0) eval(x);
	return x->T == T && !x->L;
	}

/* Used for functions of the form (is_T x yes no), which checks the type of x
and returns yes if it's type T or no otherwise. */
value arg_is_type(type T, value f)
	{
	if (!f->L->L || !f->L->L->L) return f;
	value x = f->L->L->R;
	if (arg(T,x)) return f->L->R;
	if (x->T == 0) return f;
	return f->R;
	}

/*
Evaluate a value, reducing it to a final normal form if possible within any
limits on time and space.
*/
void eval(value f)
	{
	if (++cur_depth > max_depth)
		die("Your program is too deeply nested.");

	while (1)
		{
		if (f->T) break;

		if (max_steps >= 0 && ++cur_steps > max_steps)
			die("Your program ran too long");

		value x = f->L;
		eval(x);

		value g = x->T(f);
		if (g && g != f)
			replace(f,g);
		else
			f->T = x->T;
		}

	cur_depth--;
	}<commit_msg>Slight boost in eval.<commit_after>#include "value.h"
#include "die.h"
#include "eval.h"
#include "run.h"

int arg(type T, value x)
	{
	if (x->T == 0) eval(x);
	return x->T == T && !x->L;
	}

/* Used for functions of the form (is_T x yes no), which checks the type of x
and returns yes if it's type T or no otherwise. */
value arg_is_type(type T, value f)
	{
	if (!f->L->L || !f->L->L->L) return f;
	value x = f->L->L->R;
	if (arg(T,x)) return f->L->R;
	if (x->T == 0) return f;
	return f->R;
	}

/*
Evaluate a value, reducing it to a final normal form if possible within any
limits on time and space.
*/
void eval(value f)
	{
	if (++cur_depth > max_depth)
		die("Your program is too deeply nested.");

	while (1)
		{
		if (f->T) break;

		if (max_steps >= 0 && ++cur_steps > max_steps)
			die("Your program ran too long");

		value x = f->L;
		if (x->T == 0) eval(x);

		value g = x->T(f);
		if (g && g != f)
			replace(f,g);
		else
			f->T = x->T;
		}

	cur_depth--;
	}
{'fraction_non_alphanumeric': 0.18916102136529442, 'fraction_numerical': 0.004689942678478374, 'mean_word_length': 2.84, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, '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': '6454064', 'n_tokens_mistral': 850, 'n_tokens_neox': 795, 'n_words': 272}