<commit_before>#include "strm.h"
#include "node.h"

#define NODE_ERROR_RUNTIME 0
#define NODE_ERROR_RETURN 1

static int exec_expr(node_ctx*, node*, strm_value*);

static int
exec_expr_stmt(node_ctx* ctx, node* np, strm_value* val)
{
  int i, n;
  node_values* v = np->value.v.p;
  for (i = 0; i < v->len; i++) {
    n = exec_expr(ctx, v->data[i], val);
    if (n) return n;
  }
  return 0;
}

static int
exec_plus(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  if (strm_str_p(*args)) {
    strm_string *str1 = strm_value_str(args[0]);
    strm_string *str2 = strm_value_str(args[1]);
    strm_string *str3 = strm_str_new(NULL, str1->len + str2->len);
    char *p;

    p = (char*)str3->ptr;
    memcpy(p, str1->ptr, str1->len);
    memcpy(p+str1->len, str2->ptr, str2->len);
    p[str3->len] = '\0';
    *ret = strm_ptr_value(str3);
    return 0;
  }
  else if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])+strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])+strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_minus(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])-strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])-strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_mult(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])*strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])*strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_div(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_flt_value(strm_value_flt(args[0])/strm_value_flt(args[1]));
  return 0;
}

static int
exec_gt(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(strm_value_flt(args[0])>strm_value_flt(args[1]));
  return 0;
}

static int
exec_ge(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(strm_value_flt(args[0])>=strm_value_flt(args[1]));
  return 0;
}

static int
exec_lt(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(strm_value_flt(args[0])<strm_value_flt(args[1]));
  return 0;
}

static int
exec_le(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(strm_value_flt(args[0])<=strm_value_flt(args[1]));
  return 0;
}

static int
exec_eq(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(strm_value_eq(args[0], args[1]));
  return 0;
}

static int
exec_neq(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  *ret = strm_bool_value(!strm_value_eq(args[0], args[1]));
  return 0;
}

typedef int (*exec_cfunc)(node_ctx*, int, strm_value*, strm_value*);

static int
op_call(node_ctx* ctx, node_id id, int argc, strm_value* args, strm_value* ret)
{
  strm_value m = strm_var_get(id);

  if (m.vtype == STRM_VALUE_CFUNC) {
    return ((exec_cfunc)m.val.p)(ctx, argc, args, ret);
  }
  node_raise(ctx, "function not found");
  return 1;
}

static int
exec_expr(node_ctx* ctx, node* np, strm_value* val)
{
  int n;

  if (np == NULL) {
    return 1;
  }

  switch (np->type) {
/*
  case NODE_ARGS:
    break;<commit_msg>add argc assertion for op exec functions<commit_after>#include "strm.h"
#include "node.h"

#define NODE_ERROR_RUNTIME 0
#define NODE_ERROR_RETURN 1

static int exec_expr(node_ctx*, node*, strm_value*);

static int
exec_expr_stmt(node_ctx* ctx, node* np, strm_value* val)
{
  int i, n;
  node_values* v = np->value.v.p;
  for (i = 0; i < v->len; i++) {
    n = exec_expr(ctx, v->data[i], val);
    if (n) return n;
  }
  return 0;
}

static int
exec_plus(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  if (strm_str_p(*args)) {
    strm_string *str1 = strm_value_str(args[0]);
    strm_string *str2 = strm_value_str(args[1]);
    strm_string *str3 = strm_str_new(NULL, str1->len + str2->len);
    char *p;

    p = (char*)str3->ptr;
    memcpy(p, str1->ptr, str1->len);
    memcpy(p+str1->len, str2->ptr, str2->len);
    p[str3->len] = '\0';
    *ret = strm_ptr_value(str3);
    return 0;
  }
  else if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])+strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])+strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_minus(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])-strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])-strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_mult(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  if (strm_int_p(args[0]) && strm_int_p(args[1])) {
    *ret = strm_int_value(strm_value_int(args[0])*strm_value_int(args[1]));
    return 0;
  }
  else if (strm_num_p(args[0])) {
    *ret = strm_flt_value(strm_value_flt(args[0])*strm_value_flt(args[1]));
    return 0;
  }
  return 1;
}

static int
exec_div(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_flt_value(strm_value_flt(args[0])/strm_value_flt(args[1]));
  return 0;
}

static int
exec_gt(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(strm_value_flt(args[0])>strm_value_flt(args[1]));
  return 0;
}

static int
exec_ge(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(strm_value_flt(args[0])>=strm_value_flt(args[1]));
  return 0;
}

static int
exec_lt(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(strm_value_flt(args[0])<strm_value_flt(args[1]));
  return 0;
}

static int
exec_le(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(strm_value_flt(args[0])<=strm_value_flt(args[1]));
  return 0;
}

static int
exec_eq(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(strm_value_eq(args[0], args[1]));
  return 0;
}

static int
exec_neq(node_ctx* ctx, int argc, strm_value* args, strm_value* ret)
{
  assert(argc == 2);
  *ret = strm_bool_value(!strm_value_eq(args[0], args[1]));
  return 0;
}

typedef int (*exec_cfunc)(node_ctx*, int, strm_value*, strm_value*);

static int
op_call(node_ctx* ctx, node_id id, int argc, strm_value* args, strm_value* ret)
{
  strm_value m = strm_var_get(id);

  if (m.vtype == STRM_VALUE_CFUNC) {
    return ((exec_cfunc)m.val.p)(ctx, argc, args, ret);
  }
  node_raise(ctx, "function not found");
  return 1;
}

static int
exec_expr(node_ctx* ctx, node* np, strm_value* val)
{
  int n;

  if (np == NULL) {
    return 1;
  }

  switch (np->type) {
/*
  case NODE_ARGS:
    break;
{'fraction_non_alphanumeric': 0.16336633663366337, 'fraction_numerical': 0.021273748996521274, 'mean_word_length': 4.662878787878788, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '2579560', 'n_tokens_mistral': 3411, 'n_tokens_neox': 3348, 'n_words': 643}