示例#1
0
文件: ht.c 项目: FelixZhang00/carp
int main () {
  carp_bool status;
  carp_ht h;
  carp_ht_entry *res;
  const char *key = "mykey";
  const char *badkey = "badkey";
  carp_value value = 17;

  plan(NO_PLAN);

  carp_ht_init(&h, 10);

  status = carp_ht_del(&h, key);
  ok(status == 1, "Delete fails with empty table.");

  status = carp_ht_set(&h, key, value);
  ok(status == 0, "Set returns successfully.");

  res = carp_ht_get(&h, key);
  ok(res->value == value && !strcmp(key, res->key), \
     "Gets correct struct back.");

  res = carp_ht_get(&h, badkey);
  ok(res == NULL, "Bad key gives null response.");

  carp_ht_cleanup(&h);

  done_testing();
}
示例#2
0
文件: carp_machine.c 项目: esaul/carp
/*
  Free the code, stack, varible table, and label table.
*/
void carp_vm_cleanup (carp_machine_state *m) {
  assert(m != NULL);

  free(m->code);
  carp_stack_cleanup(&m->stack);
  carp_ht_cleanup(&m->labels);
}
示例#3
0
文件: lexer.c 项目: Zhangli88/carp
/*
  Exits cleanly by cleaning up first.
*/
static void carp_lex_exit (carp_tok *tokens, carp_ht *labels, int code) {
  assert(tokens != NULL);
  assert(labels != NULL);

  carp_lex_cleanup(tokens);
  carp_ht_cleanup(labels);
  exit(code);
}