<commit_before>#include <strings.h>

#include "../system.h"

object_t* exception(char* e, int line_number, char* token) {
  printf("An Exception was raised on line: %d, near: '%s'\n\t%s\n", line_number, token, e);
  if (CRASH_ON_EXCEPTION) {
    exit(2);
  }
  object_t* o = newObject();
  o->value->value.s = token;
  o->value->type = Exception;
  return o;
}

object_t* z_exception(char* e) {
  printf("An Exception was raised on line: %d, near: '%s'\n\t%s\n", LINE_NUMBER, CURRENT_TOKEN, e);
  if (CRASH_ON_EXCEPTION) {
    exit(2);
  }
  object_t* o = newObject();
  o->value->value.s = CURRENT_TOKEN;
  o->value->type = Exception;
  return o;
}


object_t* z_add(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i + b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f + b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f + b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i + b->value->value.f);
    result->value->type = Float;
  } else if (z_typeof(a) == z_typeof(b) && z_typeof(a) == String) {
    char* str1 = a->value->value.s;
    char* str2 = b->value->value.s;
    char* newstr = (char*) malloc(1 + strlen(str1) + strlen(str2));
    strcpy(newstr, str1);
    strcat(newstr, str2);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(a) == z_typeof(b) && z_typeof(a) == Char) {
    char c1 = a->value->value.c;
    char c2 = b->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char)*2);
    strncpy(newstr, &c1, 1);
    strncat(newstr, &c2, 1);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(a) == String && z_typeof(b) == Char) {
    char* str = a->value->value.s;
    char c = b->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char) + strlen(str));
    strncpy(newstr, str, strlen(str));
    strncat(newstr, &c, 1);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(b) == String && z_typeof(a) == Char) {
    char* str = b->value->value.s;
    char c = a->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char) + strlen(str));
    strncpy(newstr, &c, 1);
    strncat(newstr, str, strlen(str));
    result->value->value.s = newstr;
    result->value->type = String;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_sub(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i - b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f - b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f - b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i - b->value->value.f);
    result->value->type = Float;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_mul(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i * b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f * b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f * b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i * b->value->value.f);
    result->value->type = Float;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_div(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i / b->value->value.i);
    result->value->type = Int;<commit_msg>added exception for division by 0<commit_after>#include <strings.h>

#include "../system.h"

object_t* exception(char* e, int line_number, char* token) {
  printf("An Exception was raised on line: %d, near: '%s'\n\t%s\n", line_number, token, e);
  if (CRASH_ON_EXCEPTION) {
    exit(2);
  }
  object_t* o = newObject();
  o->value->value.s = token;
  o->value->type = Exception;
  return o;
}

object_t* z_exception(char* e) {
  printf("An Exception was raised on line: %d, near: '%s'\n\t%s\n", LINE_NUMBER, CURRENT_TOKEN, e);
  if (CRASH_ON_EXCEPTION) {
    exit(2);
  }
  object_t* o = newObject();
  o->value->value.s = CURRENT_TOKEN;
  o->value->type = Exception;
  return o;
}


object_t* z_add(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i + b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f + b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f + b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i + b->value->value.f);
    result->value->type = Float;
  } else if (z_typeof(a) == z_typeof(b) && z_typeof(a) == String) {
    char* str1 = a->value->value.s;
    char* str2 = b->value->value.s;
    char* newstr = (char*) malloc(1 + strlen(str1) + strlen(str2));
    strcpy(newstr, str1);
    strcat(newstr, str2);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(a) == z_typeof(b) && z_typeof(a) == Char) {
    char c1 = a->value->value.c;
    char c2 = b->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char)*2);
    strncpy(newstr, &c1, 1);
    strncat(newstr, &c2, 1);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(a) == String && z_typeof(b) == Char) {
    char* str = a->value->value.s;
    char c = b->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char) + strlen(str));
    strncpy(newstr, str, strlen(str));
    strncat(newstr, &c, 1);
    result->value->value.s = newstr;
    result->value->type = String;
  } else if (z_typeof(b) == String && z_typeof(a) == Char) {
    char* str = b->value->value.s;
    char c = a->value->value.c;
    char* newstr = (char*) malloc(1 + sizeof(char) + strlen(str));
    strncpy(newstr, &c, 1);
    strncat(newstr, str, strlen(str));
    result->value->value.s = newstr;
    result->value->type = String;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_sub(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i - b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f - b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f - b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i - b->value->value.f);
    result->value->type = Float;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_mul(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i * b->value->value.i);
    result->value->type = Int;
  } else if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Float) {
    result->value->value = (generic_value_t) (a->value->value.f * b->value->value.f);
    result->value->type = Float;
  } else if(z_typeof(a) == Float && z_typeof(b) == Int) {
    result->value->value = (generic_value_t) (a->value->value.f * b->value->value.i);
    result->value->type = Float;
  } else if(z_typeof(a) == Int && z_typeof(b) == Float) {
    result->value->value = (generic_value_t) (a->value->value.i * b->value->value.f);
    result->value->type = Float;
  } else {
    exception("Type mismatch", -1, NULL);
  }
  return result;
}

object_t* z_div(list_t* args) {
  object_t* a = z_nth(args,0);
  object_t* b = z_nth(args,1);
  object_t* result = newObject();
  if ((z_typeof(a) == Int && b->value->value.i == 0) || (z_typeof(a) == Float && b->value->value.f == 0)) {
    return z_exception("Division by zero.");
  }
  if(z_typeof(a) == z_typeof(b) && z_typeof(a) == Int) {
    result->value->value = (generic_value_t) (a->value->value.i / b->value->value.i);
    result->value->type = Int;
{'fraction_non_alphanumeric': 0.21130748950297823, 'fraction_numerical': 0.006542329850600527, 'mean_word_length': 3.494076349275998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 297, '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': '5845788', 'n_tokens_mistral': 4109, 'n_tokens_neox': 4074, 'n_words': 775}