<commit_before>#include "Array.h"
#include "Field.h"
#include "Type.h"
#include "Nothing.h"
#include <stddef.h>

namespace octarine {

	Field _ArrayFields[] = {
		{ Type::sType, POINTER, offsetof(Array, mType), { 4, "type" } },
		{ UwordType, VALUE, offsetof(Array, mKind), { 4, "kind" } },
		{ UwordType, VALUE, offsetof(Array, mSize), { 4, "size" } },
		{ AddressType, VALUE, offsetof(Array, mData), { 4, "data" } }
	};

	Array _ArrayFieldsArray = {
		Field::sType,
		VALUE,
		4,
		&_ArrayFields
	};

	Type _ArrayType = {
		sizeof(Array),
		sizeof(Uword),
		_ArrayFieldsArray
	};

	Type* Array::sType = &_ArrayType;

	static void _init(Self* self) {
		Array* a = (Array*) self;
		a->mData = nullptr;
		a->mSize = 0;
		a->mKind = VALUE;
		a->mType = Nothing::sType;
	}

	static void _destroy(Self* self) {
	}

	static Type* _type(Self* self) {
		return Array::sType;
	}

	static Uword _hash(Self* self) {
		Array* a = (Array*) self;
		Uword hash = 17;
		hash += a->mSize * 37;
		hash += a->mKind * 37;
		hash += a->mType->sObjectFns->hash((Self*)a->mType) * 37;
		for (Uword i = 0; i < a->mSize; ++i) {
			Self* arrayField;
			if (a->mKind == VALUE) {
				arrayField = (Self*) ((U8*) a->mData + i * a->mType->mSize);
			}
			else {
				arrayField = *((Self**) ((U8*) a->mData + i * sizeof(Address)));
			}
			hash += a->mType->mObjectFns->hash((Self*) arrayField) * 37;
		}
		return hash;
	}

	static Bool _equals(Self* self, Object other) {
		if (self == other.mSelf) {
			return True;
		}
		if (other.mFunctions->type(other.mSelf) != Array::sType) {
			return False;
		}
		Array* a = (Array*) self;
		Array* otherA = (Array*) other.mSelf;
		if (!(a->mKind == otherA->mKind &&
			a->mSize == otherA->mSize &&
			a->mType->sObjectFns->equals((Self*) a->mType, otherA->mType->asObject()))) {
			return False;
		}
		for (Uword i = 0; i < a->mSize; ++i) {
			Self* arrayField1;
			Self* arrayField2;
			if (a->mKind == VALUE) {
				arrayField1 = (Self*) ((U8*) a->mData + i * a->mType->mSize);
				arrayField2 = (Self*) ((U8*) otherA->mData + i * a->mType->mSize);
			}
			else {
				arrayField1 = *((Self**) ((U8*) a->mData + i * sizeof(Address)));
				arrayField2 = (Self*) ((U8*) otherA->mData + i * a->mType->mSize);
			}
			// TODO: This conversion to Object should probably be in a function somewhere?
			Object arrayField2AsObject;
			arrayField2AsObject.mSelf = arrayField2;
			arrayField2AsObject.mFunctions = a->mType->mObjectFns;
			if (!a->mType->mObjectFns->equals(arrayField1, arrayField2AsObject)) {
				return False;
			}
		}
		return True;
	}

	static void _trace(Self* self, MemoryManager mm) {
		Array* a = (Array*) self;
		Uword markResult;
		mm.functions->mark(mm.self, a, &markResult);
		if (markResult == MemoryManagerMarkResult::ALREADY_MARKED) {
			return;
		}
		a->mType->sObjectFns->trace((Self*) a->mType, mm);<commit_msg>Array.cpp compiles<commit_after>#include "Array.h"
#include "Field.h"
#include "Type.h"
#include "Nothing.h"
#include "MemoryManager.h"
#include <stddef.h>

namespace octarine {

	Field _ArrayFields[] = {
		{ Type::sType, POINTER, offsetof(Array, mType), { 4, "type" } },
		{ UwordType, VALUE, offsetof(Array, mKind), { 4, "kind" } },
		{ UwordType, VALUE, offsetof(Array, mSize), { 4, "size" } },
		{ AddressType, VALUE, offsetof(Array, mData), { 4, "data" } }
	};

	Array _ArrayFieldsArray = {
		Field::sType,
		VALUE,
		4,
		&_ArrayFields
	};

	Type _ArrayType = {
		sizeof(Array),
		sizeof(Uword),
		_ArrayFieldsArray
	};

	Type* Array::sType = &_ArrayType;

	static void _init(Self* self) {
		Array* a = (Array*) self;
		a->mData = nullptr;
		a->mSize = 0;
		a->mKind = VALUE;
		a->mType = Nothing::sType;
	}

	static void _destroy(Self* self) {
	}

	static Type* _type(Self* self) {
		return Array::sType;
	}

	static Uword _hash(Self* self) {
		Array* a = (Array*) self;
		Uword hash = 17;
		hash += a->mSize * 37;
		hash += a->mKind * 37;
		hash += a->mType->sObjectFns->hash((Self*)a->mType) * 37;
		for (Uword i = 0; i < a->mSize; ++i) {
			Self* arrayField;
			if (a->mKind == VALUE) {
				arrayField = (Self*) ((U8*) a->mData + i * a->mType->mSize);
			}
			else {
				arrayField = *((Self**) ((U8*) a->mData + i * sizeof(Address)));
			}
			hash += a->mType->mObjectFns->hash((Self*) arrayField) * 37;
		}
		return hash;
	}

	static Bool _equals(Self* self, Object other) {
		if (self == other.mSelf) {
			return True;
		}
		if (other.mFunctions->type(other.mSelf) != Array::sType) {
			return False;
		}
		Array* a = (Array*) self;
		Array* otherA = (Array*) other.mSelf;
		if (!(a->mKind == otherA->mKind &&
			a->mSize == otherA->mSize &&
			a->mType->sObjectFns->equals((Self*) a->mType, otherA->mType->asObject()))) {
			return False;
		}
		for (Uword i = 0; i < a->mSize; ++i) {
			Self* arrayField1;
			Self* arrayField2;
			if (a->mKind == VALUE) {
				arrayField1 = (Self*) ((U8*) a->mData + i * a->mType->mSize);
				arrayField2 = (Self*) ((U8*) otherA->mData + i * a->mType->mSize);
			}
			else {
				arrayField1 = *((Self**) ((U8*) a->mData + i * sizeof(Address)));
				arrayField2 = (Self*) ((U8*) otherA->mData + i * a->mType->mSize);
			}
			// TODO: This conversion to Object should probably be in a function somewhere?
			Object arrayField2AsObject;
			arrayField2AsObject.mSelf = arrayField2;
			arrayField2AsObject.mFunctions = a->mType->mObjectFns;
			if (!a->mType->mObjectFns->equals(arrayField1, arrayField2AsObject)) {
				return False;
			}
		}
		return True;
	}

	static void _trace(Self* self, MemoryManager* mm) {
		Array* a = (Array*) self;
		Uword markResult;
		mm->mFunctions->mark(mm->mSelf, a, &markResult);
		if (markResult == MemoryManagerMarkResult::ALREADY_MARKED) {
			return;
		}
		a->mType->sObjectFns->trace((Self*) a->mType, mm);
{'fraction_non_alphanumeric': 0.18942961800104657, 'fraction_numerical': 0.012558869701726845, 'mean_word_length': 3.458786936236392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 111, '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': '5542763', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2236, 'n_words': 500}