Ejemplo n.º 1
0
static void read_symtab(symtab_t tab, const char *input, size_t limit) {
  token_t tok;
  const char *inputend = limit ? input + limit : NULL;
  token_init(tok);
  for (;;) {
    input = token_get(tok, input, inputend);
    if (tok->type != token_word) break;
    char *key = pbc_strdup(tok->s);
    input = token_get(tok, input, inputend);
    if (tok->type != token_word) {
      pbc_free(key);
      break;
    }
    symtab_put(tab, pbc_strdup(tok->s), key);
    pbc_free(key);
  }
  token_clear(tok);
}
Ejemplo n.º 2
0
static val_ptr val_new_error(const char *msg, ...) {
	va_list params;
	char buf[80];

	va_start(params, msg);
	vsnprintf(buf, 80, msg, params);
	va_end(params);

	val_ptr v = (val_ptr)pbc_malloc(sizeof(*v));
	v->type = v_error;
	v->msg = pbc_strdup(buf);
	return v;
}
Ejemplo n.º 3
0
void symtab_put(symtab_t t, void *data, const char *key) {
  int i, n = t->list->count;
  entry_ptr e;
  for (i=0; i<n; i++) {
    e = t->list->item[i];
    if (!strcmp(e->key, key)) goto doit;
  }
  e = pbc_malloc(sizeof(entry_t));
  e->key = pbc_strdup(key);
  darray_append(t->list, e);
doit:
  e->data = data;
}
Ejemplo n.º 4
0
tree_ptr tree_new_id(const char* s) {
	tree_ptr t = tree_new(eval_id);
	t->id = pbc_strdup(s);
	return t;
}