Example #1
0
static int
exec_seq(strm_state* state, int argc, strm_value* args, strm_value* ret)
{
  long start, end, inc=1;
  struct seq_seeder *s;

  switch (argc) {
  case 1:
    start = 1;
    end = strm_value_int(args[0]);
    break;
  case 2:
    start = strm_value_int(args[0]);
    end = strm_value_int(args[1]);
    break;
  case 3:
    start = strm_value_int(args[0]);
    inc = strm_value_int(args[1]);
    end = strm_value_int(args[2]);
    break;
  default:
    node_raise(state, "wrong number of arguments");
    return STRM_NG;
  }
  s = malloc(sizeof(struct seq_seeder));
  s->n = start;
  s->inc = inc;
  s->end = end;
  *ret = strm_task_value(strm_task_new(strm_task_prod, seq_seed, NULL, (void*)s));
  return STRM_OK;
}
Example #2
0
File: exec.c Project: faicm/streem
static void
node_init(node_ctx* ctx)
{
  strm_var_def("STDIN", strm_task_value(strm_readio(0 /* stdin*/)));
  strm_var_def("STDOUT", strm_task_value(strm_writeio(1 /* stdout*/)));
  strm_var_def("STDERR", strm_task_value(strm_writeio(2 /* stdout*/)));
  strm_var_def("puts", strm_cfunc_value(exec_puts));
  strm_var_def("+", strm_cfunc_value(exec_plus));
  strm_var_def("-", strm_cfunc_value(exec_minus));
  strm_var_def("*", strm_cfunc_value(exec_mult));
  strm_var_def("/", strm_cfunc_value(exec_div));
  strm_var_def("<", strm_cfunc_value(exec_lt));
  strm_var_def("<=", strm_cfunc_value(exec_le));
  strm_var_def(">", strm_cfunc_value(exec_gt));
  strm_var_def(">=", strm_cfunc_value(exec_ge));
  strm_var_def("==", strm_cfunc_value(exec_eq));
  strm_var_def("!=", strm_cfunc_value(exec_neq));
  strm_var_def("|", strm_cfunc_value(exec_bar));
}
Example #3
0
File: csv.c Project: fenglyu/streem
static int
csv(strm_state* state, int argc, strm_value* args, strm_value* ret)
{
  strm_task *task;
  struct csv_data *cd = malloc(sizeof(struct csv_data));

  if (!cd) return STRM_NG;
  cd->headers = NULL;
  cd->types = NULL;
  cd->prev = NULL;
  cd->n = 0;

  task = strm_task_new(strm_task_filt, csv_accept, NULL, (void*)cd);
  *ret = strm_task_value(task);
  return STRM_OK;
}
Example #4
0
static int
exec_bar(strm_state* state, int argc, strm_value* args, strm_value* ret)
{
  strm_value lhs, rhs;

  assert(argc == 2);
  /* int x int */
  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 STRM_OK;
  }

  lhs = args[0];
  /* lhs: io */
  if (strm_io_p(lhs)) {
    strm_io *io = strm_value_io(lhs);
    lhs = strm_task_value(strm_io_open(io, STRM_IO_READ));
  }
  /* lhs: lambda */
  else if (strm_lambda_p(lhs)) {
    strm_lambda *lmbd = strm_value_lambda(lhs)
    lhs = strm_task_value(strm_task_new(strm_task_filt, blk_exec, NULL, (void*)lmbd));
  }
  /* lhs: array */
  else if (strm_array_p(lhs)) {
    struct array_data *arrd = malloc(sizeof(struct array_data));
    arrd->arr = strm_value_array(lhs);
    arrd->n = 0;
    lhs = strm_task_value(strm_task_new(strm_task_prod, arr_exec, arr_finish, (void*)arrd));
  }
  /* lhs: should be task */

  rhs = args[1];
  /* rhs: io */
  if (strm_io_p(rhs)) {
    strm_io *io = strm_value_io(rhs);
    rhs = strm_task_value(strm_io_open(io, STRM_IO_WRITE));
  }
  /* rhs: lambda */
  else if (strm_lambda_p(rhs)) {
    strm_lambda *lmbd = strm_value_lambda(rhs);
    rhs = strm_task_value(strm_task_new(strm_task_filt, blk_exec, NULL, (void*)lmbd));
  }
  /* rhs: cfunc */
  else if (strm_cfunc_p(rhs)) {
    void *func = rhs.val.p;
    rhs = strm_task_value(strm_task_new(strm_task_filt, cfunc_exec, NULL, func));
  }

  /* task x task */
  if (strm_task_p(lhs) && strm_task_p(rhs)) {
    if (lhs.val.p == NULL || rhs.val.p == NULL) {
      node_raise(state, "task error");
      return STRM_NG;
    }
    strm_task_connect(strm_value_task(lhs), strm_value_task(rhs));
    *ret = rhs;
    return STRM_OK;
  }

  node_raise(state, "type error");
  return STRM_NG;
}