示例#1
0
文件: iter.c 项目: matz/streem
static int
iter_consec(strm_stream* strm, strm_value data)
{
  struct slice_data* d = strm->data;
  strm_int n = d->n;

  if (d->i < n) {
    d->buf[d->i++] = data;
    if (d->i == n) {
      strm_array ary = strm_ary_new(d->buf, n);
      strm_emit(strm, strm_ary_value(ary), NULL);
    }
    return STRM_OK;
  }
  else {
    strm_array ary;
    strm_int i;
    strm_int len = n-1;

    for (i=0; i<len; i++) {
      d->buf[i] = d->buf[i+1];
    }
    d->buf[len] = data;
    ary = strm_ary_new(d->buf, n);
    strm_emit(strm, strm_ary_value(ary), NULL);
  }
  return STRM_OK;
}
示例#2
0
文件: iter.c 项目: matz/streem
static int
gen_repeat(strm_stream* strm, strm_value data)
{
  struct repeat_data *d = strm->data;

  d->count--;
  if (d->count == 0) {
    strm_emit(strm, d->v, NULL);
    strm_stream_close(strm);
  }
  else {
    strm_emit(strm, d->v, gen_repeat);
  }
  return STRM_OK;
}
示例#3
0
文件: exec.c 项目: likeog/streem
static int
blk_exec(strm_task* task, strm_value data)
{
  strm_lambda lambda = task->data;
  strm_value ret = strm_nil_value();
  node_args* args = (node_args*)lambda->body->args;
  int n;
  strm_state c = {0};

  c.task = task;
  c.prev = lambda->state;
  if (args) {
    assert(args->len == 1);
    strm_var_set(&c, node_to_sym(args->data[0]), data);
  }

  n = exec_expr(&c, lambda->body->compstmt, &ret);
  if (n) return STRM_NG;
  if (lambda->state->exc) {
    if (lambda->state->exc->type == NODE_ERROR_RETURN) {
      ret = lambda->state->exc->arg;
      free(lambda->state->exc);
      lambda->state->exc = NULL;
    } else {
      return STRM_NG;
    }
  }
  strm_emit(task, ret, NULL);
  return STRM_OK;
}
示例#4
0
文件: exec.c 项目: cbforks/streem
static int
blk_exec(strm_stream* strm, strm_value data)
{
  strm_lambda lambda = strm->data;
  strm_value ret = strm_nil_value();
  node_args* args = (node_args*)lambda->body->args;
  node_error* exc;
  int n;
  strm_state c = {0};

  c.prev = lambda->state;
  if (args) {
    assert(args->len == 1);
    strm_var_set(&c, node_to_sym(args->data[0]), data);
  }

  n = exec_expr(strm, &c, lambda->body->compstmt, &ret);
  exc = strm->exc;
  if (exc) {
    if (exc->type == NODE_ERROR_RETURN) {
      ret = exc->arg;
      strm_clear_exc(strm);
    }
    else {
      if (strm_option_verbose) {
        strm_eprint(strm);
      }
      return STRM_NG;
    }
  }
  if (n) return STRM_NG;
  strm_emit(strm, ret, NULL);
  return STRM_OK;
}
示例#5
0
文件: exec.c 项目: fenglyu/streem
static void
blk_exec(strm_task* task, strm_value data)
{
  strm_lambda *lambda = task->data;
  strm_value ret = strm_nil_value();
  node_values* args = (node_values*)lambda->body->args;
  int n;
  strm_state c = {0};

  c.task = task;
  c.prev = lambda->state;
  assert(args->len == 1);
  strm_var_set(&c, (strm_string*)args->data[0], data);

  n = exec_expr(&c, lambda->body->compstmt, &ret);
  if (n) return;
  if (lambda->state->exc) {
    if (lambda->state->exc->type == NODE_ERROR_RETURN) {
      ret = lambda->state->exc->arg;
      free(lambda->state->exc);
      lambda->state->exc = NULL;
    } else {
      return;
    }
  }
  strm_emit(task, ret, NULL);
}
示例#6
0
文件: stat.c 项目: byelipk/streem
static int
avg_finish(strm_stream* strm, strm_value data)
{
  struct sum_data* d = strm->data;

  strm_emit(strm, strm_flt_value(d->sum/d->num), NULL);
  return STRM_OK;
}
示例#7
0
文件: iter.c 项目: matz/streem
static int
minmax_finish(strm_stream* strm, strm_value data)
{
  struct minmax_data* d = strm->data;

  strm_emit(strm, d->data, NULL);
  return STRM_OK;
}
示例#8
0
文件: exec.c 项目: fenglyu/streem
static void
arr_exec(strm_task* task, strm_value data)
{
  struct array_data *arrd = task->data;
  strm_emit(task, arrd->arr->ptr[arrd->n++], NULL);
  if (arrd->n == arrd->arr->len)
    strm_task_close(task);
}
示例#9
0
文件: iter.c 项目: matz/streem
static int
iter_uniq(strm_stream* strm, strm_value data)
{
  struct uniq_data* d = strm->data;

  if (!d->init) {
    d->init = TRUE;
    d->last = data;
    strm_emit(strm, data, NULL);
    return STRM_OK;
  }
  if (!strm_value_eq(data, d->last)) {
    d->last = data;
    strm_emit(strm, data, NULL);
  }
  return STRM_OK;
}
示例#10
0
文件: stat.c 项目: byelipk/streem
static int
var_finish(strm_stream* strm, strm_value data)
{
  struct stdev_data* d = strm->data;
  double s = d->s2 / (d->num-1);
  strm_emit(strm, strm_flt_value(s), NULL);
  return STRM_OK;
}
示例#11
0
文件: iter.c 项目: matz/streem
static int
count_finish(strm_stream* strm, strm_value data)
{
  struct count_data* d = strm->data;

  strm_emit(strm, strm_int_value(d->count), NULL);
  free(d);
  return STRM_OK;
}
示例#12
0
文件: iter.c 项目: matz/streem
static int
reduce_finish(strm_stream* strm, strm_value data)
{
  struct reduce_data* d = strm->data;

  if (!d->init) return STRM_NG;
  strm_emit(strm, d->acc, NULL);
  return STRM_OK;
}
示例#13
0
文件: exec.c 项目: fenglyu/streem
static void
cfunc_exec(strm_task* task, strm_value data)
{
  strm_value ret;
  exec_cfunc func = task->data;
  strm_state c = {0};

  if ((*func)(&c, 1, &data, &ret) == STRM_OK) {
    strm_emit(task, ret, NULL);
  }
}
示例#14
0
文件: iter.c 项目: matz/streem
static int
iter_drop(strm_stream* strm, strm_value data)
{
  struct take_data* d = strm->data;

  if (d->n > 0) {
    d->n--;
    return STRM_OK;
  }
  strm_emit(strm, data, NULL);
  return STRM_OK;
}
示例#15
0
文件: exec.c 项目: likeog/streem
static int
arr_exec(strm_task* task, strm_value data)
{
  struct array_data *arrd = task->data;

  if (arrd->n == strm_ary_len(arrd->arr)) {
    strm_task_close(task);
    return STRM_OK;
  }
  strm_emit(task, strm_ary_ptr(arrd->arr)[arrd->n++], arr_exec);
  return STRM_OK;
}
示例#16
0
文件: iter.c 项目: matz/streem
static int
iter_take(strm_stream* strm, strm_value data)
{
  struct take_data* d = strm->data;

  strm_emit(strm, data, NULL);
  d->n--;
  if (d->n == 0) {
    strm_stream_close(strm);
  }
  return STRM_OK;
}
示例#17
0
文件: iter.c 项目: matz/streem
static int
iter_map(strm_stream* strm, strm_value data)
{
  struct map_data* d = strm->data;
  strm_value val;

  if (strm_funcall(strm, d->func, 1, &data, &val) == STRM_NG) {
    return STRM_NG;
  }
  strm_emit(strm, val, NULL);
  return STRM_OK;
}
示例#18
0
static int
arr_exec(strm_task* task, strm_value data)
{
  struct array_data *arrd = task->data;

  if (arrd->n == arrd->arr->len) {
    strm_task_close(task);
    return STRM_OK;
  }
  strm_emit(task, arrd->arr->ptr[arrd->n++], arr_exec);
  return STRM_OK;
}
示例#19
0
文件: exec.c 项目: cbforks/streem
static int
cfunc_exec(strm_stream* strm, strm_value data)
{
  strm_value ret;
  strm_cfunc func = strm->data;

  if ((*func)(strm, 1, &data, &ret) == STRM_OK) {
    strm_emit(strm, ret, NULL);
    return STRM_OK;
  }
  return STRM_NG;
}
示例#20
0
文件: exec.c 项目: cbforks/streem
static int
arr_exec(strm_stream* strm, strm_value data)
{
  struct array_data *arrd = strm->data;

  if (arrd->n == strm_ary_len(arrd->arr)) {
    strm_stream_close(strm);
    return STRM_OK;
  }
  strm_emit(strm, strm_ary_ptr(arrd->arr)[arrd->n++], arr_exec);
  return STRM_OK;
}
示例#21
0
文件: stat.c 项目: byelipk/streem
static int
finish_sample(strm_stream* strm, strm_value data)
{
  struct sample_data* d = strm->data;
  strm_int i, len=d->len;

  for (i=0; i<len; i++) {
    strm_emit(strm, d->samples[i], NULL);
  }
  free(d);
  return STRM_OK;
}
示例#22
0
文件: stat.c 项目: byelipk/streem
static int
correl_finish(strm_stream* strm, strm_value data)
{
  struct correl_data* d = strm->data;

  d->n--;
  double sxx = sqrt(d->sxx / d->n);
  double syy = sqrt(d->syy / d->n);
  double sxy = d->sxy / (d->n * sxx * syy);
  strm_emit(strm, strm_flt_value(sxy), NULL);
  return STRM_OK;
}
示例#23
0
文件: seq.c 项目: mySingleLive/streem
static int
seq_seed(strm_task* task, strm_value data)
{
  struct seq_seeder *s = task->data;

  if (s->n > s->end) {
    strm_task_close(task);
    return STRM_OK;
  }
  strm_emit(task, strm_int_value(s->n), seq_seed);
  s->n += s->inc;
  return STRM_OK;
}
示例#24
0
文件: exec.c 项目: likeog/streem
static int
cfunc_exec(strm_task* task, strm_value data)
{
  strm_value ret;
  strm_cfunc func = task->data;
  strm_state c = {0};

  if ((*func)(&c, 1, &data, &ret) == STRM_OK) {
    strm_emit(task, ret, NULL);
    return STRM_OK;
  }
  return STRM_NG;
}
示例#25
0
文件: iter.c 项目: cbforks/streem
static int
gen_seq(strm_stream* strm, strm_value data)
{
  struct seq_data* d = strm->data;

  if (d->end > 0 && d->n > d->end) {
    strm_stream_close(strm);
    return STRM_OK;
  }
  strm_emit(strm, strm_int_value(d->n), gen_seq);
  d->n += d->inc;
  return STRM_OK;
}
示例#26
0
文件: iter.c 项目: matz/streem
static int
finish_slice(strm_stream* strm, strm_value data)
{
  struct slice_data* d = strm->data;

  if (d->i > 0) {
    strm_array ary = strm_ary_new(d->buf, d->i);
    strm_emit(strm, strm_ary_value(ary), NULL);
  }
  free(d->buf);
  free(d);
  return STRM_OK;
}
示例#27
0
文件: iter.c 项目: matz/streem
static int
iter_filter(strm_stream* strm, strm_value data)
{
  struct map_data* d = strm->data;
  strm_value val;

  if (strm_funcall(strm, d->func, 1, &data, &val) == STRM_NG) {
    return STRM_NG;
  }
  if (strm_value_bool(val)) {
    strm_emit(strm, data, NULL);
  }
  return STRM_OK;
}
示例#28
0
文件: iter.c 项目: matz/streem
static int
iter_uniqf(strm_stream* strm, strm_value data)
{
  struct uniq_data* d = strm->data;
  strm_value val;

  if (strm_funcall(strm, d->func, 1, &data, &val) == STRM_NG) {
    return STRM_NG;
  }
  if (!d->init) {
    d->init = TRUE;
    d->last = data;
    d->v = val;
    strm_emit(strm, data, NULL);
    return STRM_OK;
  }
  if (!strm_value_eq(val, d->v)) {
    d->last = data;
    d->v = val;
    strm_emit(strm, data, NULL);
  }
  return STRM_OK;
}
示例#29
0
文件: iter.c 项目: matz/streem
static int
gen_cycle(strm_stream* strm, strm_value data)
{
  struct cycle_data *d = strm->data;
  strm_value* p;
  strm_int i, len;

  d->count--;
  p = strm_ary_ptr(d->ary);
  len = strm_ary_len(d->ary);
  if (d->count != 0) {
    len--;
  }
  for (i=0; i<len; i++) {
    strm_emit(strm, p[i], NULL);
  }
  if (d->count == 0) {
    strm_stream_close(strm);
  }
  else {
    strm_emit(strm, p[i], gen_cycle);
  }
  return STRM_OK;
}
示例#30
0
文件: iter.c 项目: matz/streem
static int
iter_slice(strm_stream* strm, strm_value data)
{
  struct slice_data* d = strm->data;
  strm_int n = d->n;

  d->buf[d->i++] = data;
  if (d->i == n) {
    strm_array ary = strm_ary_new(d->buf, n);

    d->i = 0;
    strm_emit(strm, strm_ary_value(ary), NULL);
  }
  return STRM_OK;
}