<commit_before>#include <ol/vm.h>

#include <stdio.h>
#include <unistd.h>
typedef uintptr_t word;

#define BEGIN(x) \
{ \
	printf("Testing " x " instruction... ");
#define END() \
	OLVM_delete(olvm); \
}

#define EVAL(...) \
	unsigned char bootstrap[] = __VA_ARGS__; \
	olvm_t* olvm = OLVM_new(bootstrap); \
	word output = (word) OLVM_run(olvm, 0, 0);

#define ASSERT(...) \
	if (__VA_ARGS__) { \
		succeeded++; \
		printf("Ok.\n"); \
	} \
	else { \
		failed++; \
		printf("Failed.\n"); \
	} \
	total++;

#define TESTCASE(name, assertion, ...) \
	BEGIN(name) \
		EVAL(__VA_ARGS__) \
		ASSERT(output assertion) \
	END()

int main(int argc, char** argv)
{
	int failed = 0;
	int succeeded = 0;
	int total = 0;

	/// LDI
	TESTCASE("LDE",  == 0x336, // #empty
		//lambda(x)  LDE[6]  RET[6]
		{ 2, 16, 4,  13, 6,  24, 6,  0 }
	);
	TESTCASE("LDN",  == 0x236, // #null
		//lambda(x)  LDN[6]  RET[6]
		{ 2, 16, 4,  77, 6,  24, 6,  0 }
	);
	TESTCASE("LDT",  == 0x136, // #true
		//lambda(x)  LDN[6]  RET[6]
		{ 2, 16, 4, 141, 6,  24, 6,  0 }
	);
	TESTCASE("LDF",  == 0x036, // #false
		//lambda(x)  LDN[6]  RET[6]
		{ 2, 16, 4, 205, 6,  24, 6,  0 }
	);

	/// LD
	TESTCASE("LD",   == 0x202,
		//lambda(x)  LD  2>[6]  RET[6]
		{ 2, 16, 5,  14, 2, 6,  24, 6,  0 }
	);
	/// MOVE
	TESTCASE("MOVE", == 0x202,
		//lambda(x)  LD  2>[6]  MOVE [6]>[7]  RET[7]
		{ 2, 16, 8,  14, 2, 6,  9,    6,  7,  24, 7,  0 }
	);
<commit_msg>vm test cleanup<commit_after>#include <stdio.h>
#include <unistd.h>

#include <ol/vm.h>

#define BEGIN(x) \
{ \
	printf("Testing " x " instruction... ");
#define END() \
	OLVM_delete(olvm); \
}

#define EVAL(...) \
	unsigned char bootstrap[] = __VA_ARGS__; \
	olvm_t* olvm = OLVM_new(bootstrap); \
	word output = (word) OLVM_run(olvm, 0, 0);

#define ASSERT(...) \
	if (__VA_ARGS__) { \
		succeeded++; \
		printf("Ok.\n"); \
	} \
	else { \
		failed++; \
		printf("Failed.\n"); \
	} \
	total++;

#define TESTCASE(name, assertion, ...) \
	BEGIN(name) \
		EVAL(__VA_ARGS__) \
		ASSERT(output assertion) \
	END()

int main(int argc, char** argv)
{
	int failed = 0;
	int succeeded = 0;
	int total = 0;

	/// LDI
	TESTCASE("LDE",  == 0x336, // #empty
		//lambda(x)  LDE[6]  RET[6]
		{ 2, 16, 4,  13, 6,  24, 6,  0 }
	);
	TESTCASE("LDN",  == 0x236, // #null
		//lambda(x)  LDN[6]  RET[6]
		{ 2, 16, 4,  77, 6,  24, 6,  0 }
	);
	TESTCASE("LDT",  == 0x136, // #true
		//lambda(x)  LDT[6]  RET[6]
		{ 2, 16, 4, 141, 6,  24, 6,  0 }
	);
	TESTCASE("LDF",  == 0x036, // #false
		//lambda(x)  LDF[6]  RET[6]
		{ 2, 16, 4, 205, 6,  24, 6,  0 }
	);

	/// LD
	TESTCASE("LD",   == 0x202,
		//lambda(x)  LD  2>[6]  RET[6]
		{ 2, 16, 5,  14, 2, 6,  24, 6,  0 }
	);
	/// MOVE
	TESTCASE("MOVE", == 0x202,
		//lambda(x)  LD  2>[6]  MOVE [6]>[7]  RET[7]
		{ 2, 16, 8,  14, 2, 6,  9,    6,  7,  24, 7,  0 }
	);

{'fraction_non_alphanumeric': 0.2380100214745884, 'fraction_numerical': 0.08446671438797423, 'mean_word_length': 2.400243309002433, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '7405257', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1349, 'n_words': 315}