コード例 #1
0
ファイル: cont.c プロジェクト: hopkinsr/picrin
struct pic_proc *
pic_make_cont(pic_state *pic, struct pic_cont *cont)
{
  static const pic_data_type cont_type = { "cont", pic_free, NULL };
  struct pic_proc *c;
  struct pic_data *e;

  c = pic_make_proc(pic, cont_call, "<cont-procedure>");

  e = pic_data_alloc(pic, &cont_type, cont);

  /* save the escape continuation in proc */
  pic_proc_env_set(pic, c, "escape", pic_obj_value(e));

  return c;
}
コード例 #2
0
ファイル: regexp.c プロジェクト: krig/picrin
static pic_value
pic_regexp_regexp(pic_state *pic)
{
  const char *ptrn, *flags = "";
  int cflags, err;
  struct pic_regexp_t *reg;

  pic_get_args(pic, "z|z", &ptrn, &flags);

  cflags = REG_EXTENDED;

  while (*flags) {
    switch (*flags++) {
    case 'g':
    case 'G':
      /* pass */
      break;
    case 'i':
    case 'I':
      cflags |= REG_ICASE;
      break;
    case 'm':
    case 'M':
      cflags |= REG_NEWLINE;
      break;
    }
  }

  reg = pic_alloc(pic, sizeof(struct pic_regexp_t));
  reg->flags = flags;

  if ((err = regcomp(&reg->reg, ptrn, cflags)) != 0) {
    char errbuf[regerror(err, &reg->reg, NULL, 0)];

    regerror(err, &reg->reg, errbuf, sizeof errbuf);
    regexp_dtor(pic, &reg->reg);

    pic_errorf(pic, "regexp compilation error: %s", errbuf);
  }

  return pic_obj_value(pic_data_alloc(pic, &regexp_type, reg));
}