Beispiel #1
0
bool func_assert(cell_t **cp, type_rep_t t) {
  cell_t *c = clear_ptr(*cp, 3);
  alt_set_t alt_set = 0;
  if(!reduce_arg(c, 1, &alt_set, T_INT)) goto fail;
  clear_flags(c);  
  cell_t *p = c->arg[1];
  if(!(is_var(p) || p->val[0])) goto fail;
  c->func = func_id;
  c->size = 1;
  c->arg[1] = (cell_t *)alt_set_ref(alt_set);
  drop(p);
  return false;
 fail:
  fail(cp);
  return false;
}
Beispiel #2
0
bool func_compose(cell_t **cp, type_rep_t t) {
  cell_t *const c = clear_ptr(*cp, 3);
  alt_set_t alt_set = 0;

  if(!(reduce_arg(c, 0, &alt_set, T_LIST) &&
       reduce_arg(c, 1, &alt_set, T_LIST))) goto fail;
  clear_flags(c);
  cell_t *res = compose_nd(ref(c->arg[0]), ref(c->arg[1]));
  res->alt_set = alt_set_ref(alt_set);
  drop(res->alt);
  res->alt = c->alt;
  store_reduced(cp, res);
  return true;

 fail:
  fail(cp);
  return false;
}
Beispiel #3
0
bool func_pushl(cell_t **cp, type_rep_t t) {
  cell_t *c = clear_ptr(*cp, 3);
  alt_set_t alt_set = 0;
  if(!reduce_arg(c, 1, &alt_set, T_LIST)) goto fail;
  clear_flags(c);
  cell_t *q = c->arg[1];
  bool rvar = is_var(q);
  cell_t *res = pushl_nd(ref(c->arg[0]), ref(q));
  if(rvar) res->type |= T_VAR;
  drop(res->alt);
  res->alt = c->alt;
  res->alt_set = alt_set_ref(alt_set);
  store_reduced(cp, res);
  return true;

  fail:
    fail(cp);
    return false;
}
Beispiel #4
0
/*
bool type_check(cell_t **cp, type_t type) {
  cell_t *c = clear_ptr(*cp, 3);
  if(!reduce(&c->arg[0], type)) goto fail;
  c->alt = closure_split1(c, 0);
  cell_t *p = get(c->arg[0]);
  if(!((p->type == type) ||
       is_var(p))) goto fail;
  store_reduced(c, mod_alt(c->arg[0], c->alt,
			   c->arg[0]->alt_set));
  return true;
 fail:
  fail(cp);
  return false;
}
*/
bool func_id(cell_t **cp, type_rep_t t) {
  cell_t *c = clear_ptr(*cp, 3);
  alt_set_t alt_set = (alt_set_t)c->arg[1];
  if(alt_set || c->alt) {
    if(!reduce_arg(c, 0, &alt_set, t)) goto fail;
    clear_flags(c);
    cell_t *p = c->arg[0];
    if(p->alt) alt_set_ref(alt_set);
    store_reduced(cp, mod_alt(ref(p), c->alt, alt_set));
    alt_set_drop(alt_set);
    return true;
  } else {
    cell_t *p = ref(c->arg[0]);
    drop(c);
    *cp = p;
    return false;
  }

 fail:
  fail(cp);
  return false;
}
Beispiel #5
0
bool func_pushr(cell_t **cp, type_rep_t t) {
  cell_t *c = clear_ptr(*cp, 3);
  alt_set_t alt_set = 0;
  if(!reduce_arg(c, 0, &alt_set, T_LIST)) goto fail;
  clear_flags(c);
  cell_t *p = c->arg[0];

  int n = list_size(p);
  cell_t *res = expand(ref(p), 1);
  memmove(res->ptr+1, res->ptr, sizeof(cell_t *)*n);
  res->ptr[0] = ref(c->arg[1]);
  res->alt_set = alt_set_ref(alt_set);
  drop(res->alt);
  res->alt = c->alt;

  store_reduced(cp, res);
  return true;

 fail:
  fail(cp);
  return false;
}
Beispiel #6
0
bool func_op2(cell_t **cp, type_rep_t t, intptr_t (*op)(intptr_t, intptr_t)) {
  cell_t *res = 0;
  cell_t *const c = clear_ptr(*cp, 3);
  alt_set_t alt_set = 0;

  if(t == T_ANY || t == T_INT) t = T_INT;
  else goto fail;

  if(!reduce_arg(c, 0, &alt_set, t) ||
     !reduce_arg(c, 1, &alt_set, t)) goto fail;
  clear_flags(c);
  cell_t *p = c->arg[0], *q = c->arg[1];
  res = is_var(p) || is_var(q) ? var(t) : _op2(op, p, q);
  res->alt = c->alt;
  res->alt_set = alt_set_ref(alt_set);
  store_reduced(cp, res);
  return true;

 fail:
  drop(res);
  fail(cp);
  return false;
}
Beispiel #7
0
UtilStrbuf::UtilStrbuf (char *buf, unsigned long len, bool init, bool nl)
{
	clear_ptr (this);

	this->buf    = buf;
	this->size   = len;
	this->eot_nl = nl;

	if (!this->buf || !this->size) {
		this->buf  = NULL;
		this->size = 0;
		return;
	}

	if (init) memset (this->buf, 0, this->size);

	this->ptr = strchr (this->buf, 0);
	if (this->ptr) {
		this->left = this->size - (this->ptr - this->buf);
	} else {
		this->left = 0;
	}
}