<commit_before>#include "slate.h"


//Template for defining Slate primitive signatures. Not a macro because IDEs don't process it:
//#define SLATE_PRIM(prim_name) void prim_name(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer)

#ifdef SLATE_DAEMONIZE
#include <pwd.h>
#include <sys/stat.h>
#include <signal.h>
#endif

void prim_fixme(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
  struct Object* x = args[0];
  printf("UNIMPLEMENTED PRIMITIVE\n");
  interpreter_signal_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_TYPE_ERROR_ON), x, NULL, resultStackPointer);
}

#pragma mark Root

void prim_isIdenticalTo(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	oh->cached.interpreter->stack->elements[resultStackPointer] = (args[0]==args[1])? oh->cached.true_object : oh->cached.false_object;
}

void prim_identity_hash(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	/*fix*/
	/*  print_detail(oh, args[0]);
	 print_backtrace(oh);*/
	oh->cached.interpreter->stack->elements[resultStackPointer] = smallint_to_object(object_hash(args[0]));
}

void prim_identity_hash_univ(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	/*fix*/
	/*  print_detail(oh, args[0]);
	 print_backtrace(oh);*/
	if (object_is_smallint(args[0])) {
		oh->cached.interpreter->stack->elements[resultStackPointer] = args[0];
	} else {
		oh->cached.interpreter->stack->elements[resultStackPointer] = smallint_to_object(object_hash(args[0]));
	}
}

/* Root forwardTo: anotherObject */
void prim_forward_to(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	struct Object* x = args[0];
	struct Object* y = args[1];
	oh->cached.interpreter->stack->elements[resultStackPointer] = y;
	/* since some objects like roleTables store pointers to things like Nil in byte arrays rather than oop arrays,
	 * we must make sure that these special objects do not move.
	 */
	if (x == get_special(oh, SPECIAL_OOP_NIL) 
		|| x == get_special(oh, SPECIAL_OOP_TRUE)
		|| x == get_special(oh, SPECIAL_OOP_FALSE)) {
		printf("Error... you cannot call forwardTo on this special object (did you add a slot to Nil/True/False?)\n");
		interpreter_signal_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_TYPE_ERROR_ON), x, NULL, resultStackPointer); \
		return;
	}
	
	if (!object_is_smallint(x) && !object_is_smallint(y) && x != y) {
		heap_forward(oh, x, y);
		heap_gc(oh);
		cache_specials(oh);
	}
	
}

/* Root atSlotNamed: symbol */
void prim_at_slot_named(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	struct Object* obj;
	struct Object* name;
	struct SlotEntry * se;
	
	obj = args[0];
	name = args[1];
	
	if (object_is_smallint(obj)) {
		interpreter_signal_with_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_SLOT_NOT_FOUND_NAMED), obj, name, NULL, resultStackPointer);
	} else {
		se = slot_table_entry_for_name(oh, obj->map->slotTable, (struct Symbol*)name);
		if (se == NULL) {
			interpreter_signal_with_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_SLOT_NOT_FOUND_NAMED), obj, name, NULL, resultStackPointer);
		} else {
			word_t offset = object_to_smallint(se->offset);
			oh->cached.interpreter->stack->elements[resultStackPointer] = object_slot_value_at_offset(obj, offset);<commit_msg>simple prim_forward_to optimization<commit_after>#include "slate.h"


//Template for defining Slate primitive signatures. Not a macro because IDEs don't process it:
//#define SLATE_PRIM(prim_name) void prim_name(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer)

#ifdef SLATE_DAEMONIZE
#include <pwd.h>
#include <sys/stat.h>
#include <signal.h>
#endif

void prim_fixme(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
  struct Object* x = args[0];
  printf("UNIMPLEMENTED PRIMITIVE\n");
  interpreter_signal_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_TYPE_ERROR_ON), x, NULL, resultStackPointer);
}

#pragma mark Root

void prim_isIdenticalTo(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	oh->cached.interpreter->stack->elements[resultStackPointer] = (args[0]==args[1])? oh->cached.true_object : oh->cached.false_object;
}

void prim_identity_hash(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	/*fix*/
	/*  print_detail(oh, args[0]);
	 print_backtrace(oh);*/
	oh->cached.interpreter->stack->elements[resultStackPointer] = smallint_to_object(object_hash(args[0]));
}

void prim_identity_hash_univ(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	/*fix*/
	/*  print_detail(oh, args[0]);
	 print_backtrace(oh);*/
	if (object_is_smallint(args[0])) {
		oh->cached.interpreter->stack->elements[resultStackPointer] = args[0];
	} else {
		oh->cached.interpreter->stack->elements[resultStackPointer] = smallint_to_object(object_hash(args[0]));
	}
}

/* Root forwardTo: anotherObject */
void prim_forward_to(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	struct Object* x = args[0];
	struct Object* y = args[1];
	oh->cached.interpreter->stack->elements[resultStackPointer] = y;
	/* since some objects like roleTables store pointers to things like Nil in byte arrays rather than oop arrays,
	 * we must make sure that these special objects do not move.
	 */
	if (x == get_special(oh, SPECIAL_OOP_NIL) 
		|| x == get_special(oh, SPECIAL_OOP_TRUE)
		|| x == get_special(oh, SPECIAL_OOP_FALSE)) {
		printf("Error... you cannot call forwardTo on this special object (did you add a slot to Nil/True/False?)\n");
		interpreter_signal_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_TYPE_ERROR_ON), x, NULL, resultStackPointer); \
		return;
	}
	
	if (!object_is_smallint(x) && !object_is_smallint(y) && x != y) {
		heap_forward(oh, x, y);
		/*heap_gc(oh);*/ /* unnecessary waste of time for one object? */
		cache_specials(oh);
	}
	
}

/* Root atSlotNamed: symbol */
void prim_at_slot_named(struct object_heap* oh, struct Object* args[], word_t arity, struct OopArray* opts, word_t resultStackPointer) {
	struct Object* obj;
	struct Object* name;
	struct SlotEntry * se;
	
	obj = args[0];
	name = args[1];
	
	if (object_is_smallint(obj)) {
		interpreter_signal_with_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_SLOT_NOT_FOUND_NAMED), obj, name, NULL, resultStackPointer);
	} else {
		se = slot_table_entry_for_name(oh, obj->map->slotTable, (struct Symbol*)name);
		if (se == NULL) {
			interpreter_signal_with_with(oh, oh->cached.interpreter, get_special(oh, SPECIAL_OOP_SLOT_NOT_FOUND_NAMED), obj, name, NULL, resultStackPointer);
		} else {
			word_t offset = object_to_smallint(se->offset);
			oh->cached.interpreter->stack->elements[resultStackPointer] = object_slot_value_at_offset(obj, offset);
{'fraction_non_alphanumeric': 0.12957937584803256, 'fraction_numerical': 0.0035278154681139757, 'mean_word_length': 5.927631578947368, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 63, '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': '4359873', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2546, 'n_words': 606}