Modified to work with existing runtime api

This commit is contained in:
Justin Ethier 2015-12-11 21:24:24 -05:00
parent d8a96d17b7
commit 35e9ec76d5

145
test.c
View file

@ -68,34 +68,6 @@ set_insert(ck_hs_t *hs, const void *value)
h = CK_HS_HASH(hs, hs_hash, value);
return ck_hs_put(hs, h, value);
}
//static void *table_get(ck_ht_t *ht, const char *value)
//{
// ck_ht_entry_t entry;
// ck_ht_hash_t h;
// size_t l = strlen(value);
// void *v = NULL;
//
// ck_ht_hash(&h, ht, value, l);
// ck_ht_entry_key_set(&entry, value, l);
//
// if (ck_ht_get_spmc(ht, h, &entry) == true) {
// v = ck_ht_entry_value(&entry);
// }
// return v;
//}
//
//static int table_insert(ck_ht_t *ht, const char *key, const void *value)
//{
// ck_ht_entry_t entry;
// ck_ht_hash_t h;
// size_t l = strlen(key);
//
// ck_ht_hash(&h, ht, key, l);
// ck_ht_entry_set(&entry, h, key, l, "VALUE"); //value);
// return ck_ht_put_spmc(ht, h, &entry);
//}
//// END CK section
//
char *_strdup (const char *s) {
char *d = malloc (strlen (s) + 1);
@ -103,43 +75,37 @@ char *_strdup (const char *s) {
return d;
}
//object find_symbol_by_name(const char *name) {
// //list l = symbol_table;
// //for (; !nullp(l); l = cdr(l)) {
// // const char *str = symbol_pname(car(l));
// // if (strcmp(str, name) == 0) return car(l);
// //}
// //return nil;
// object result = set_get(&hs_symbol_table, name);
// if (result) {
// printf("found symbol %s\n", symbol_pname(result));
// }
// return result;
//}
//
//object add_symbol(symbol_type *psym) {
// //symbol_table = mcons(psym, symbol_table);
// printf("Adding symbol %s\n", symbol_pname(psym));
// set_insert(&hs_symbol_table, symbol_pname(psym), psym);
// return psym;
//}
//
//object add_symbol_by_name(const char *name) {
// symbol_type sym = {{0}, symbol_tag, _strdup(name), nil};
// symbol_type *psym = malloc(sizeof(symbol_type));
// memcpy(psym, &sym, sizeof(symbol_type));
// return add_symbol(psym);
//}
//
//object find_or_add_symbol(const char *name){
// object sym = find_symbol_by_name(name);
// if (sym){
// return sym;
// } else {
// return add_symbol_by_name(name);
// }
//}
//
object find_symbol_by_name(const char *name) {
symbol_type tmp = {{0}, symbol_tag, name, nil};
object result = set_get(&hs_symbol_table, &tmp);
if (result) {
printf("found symbol %s\n", symbol_pname(result));
}
return result;
}
object add_symbol(symbol_type *psym) {
printf("Adding symbol %s\n", symbol_pname(psym));
set_insert(&hs_symbol_table, psym);
return psym;
}
object add_symbol_by_name(const char *name) {
symbol_type sym = {{0}, symbol_tag, _strdup(name), nil};
symbol_type *psym = malloc(sizeof(symbol_type));
memcpy(psym, &sym, sizeof(symbol_type));
return add_symbol(psym);
}
object find_or_add_symbol(const char *name){
object sym = find_symbol_by_name(name);
if (sym){
return sym;
} else {
return add_symbol_by_name(name);
}
}
void main()
{
char astr[] = "a";
@ -160,31 +126,32 @@ void main()
}
set_insert(&hs_symbol_table, &a);
printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
printf("has \"a\" = %p\n", set_get(&hs_symbol_table, &aa));
printf("has \"b\" = %p\n", set_get(&hs_symbol_table, &b));
printf("has \"c\" = %p\n", set_get(&hs_symbol_table, &c));
// set_insert(&hs_symbol_table, &a);
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
// printf("has \"a\" = %p\n", set_get(&hs_symbol_table, &aa));
// printf("has \"b\" = %p\n", set_get(&hs_symbol_table, &b));
// printf("has \"c\" = %p\n", set_get(&hs_symbol_table, &c));
//
// set_insert(&hs_symbol_table, &b);
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
// printf("has \"a\" = %p\n", set_get(&hs_symbol_table, &aa));
// printf("has \"b\" = %p\n", set_get(&hs_symbol_table, &b));
// printf("has \"c\" = %p\n", set_get(&hs_symbol_table, &c));
set_insert(&hs_symbol_table, &b);
object asym = find_or_add_symbol("a");
printf("%p\n", asym);
object bsym = find_or_add_symbol("b");
printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
object csym = find_or_add_symbol("c");
printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
object dsym = find_or_add_symbol("d");
printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
object aasym = find_or_add_symbol("a");
printf("%p\n", aasym);
printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
printf("has \"a\" = %p\n", set_get(&hs_symbol_table, &aa));
printf("has \"b\" = %p\n", set_get(&hs_symbol_table, &b));
printf("has \"c\" = %p\n", set_get(&hs_symbol_table, &c));
// object a = find_or_add_symbol("a");
// printf("%p\n", a);
//
// object b = find_or_add_symbol("b");
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
//
// object c = find_or_add_symbol("c");
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
//
// object d = find_or_add_symbol("d");
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
//
// object aa = find_or_add_symbol("a");
// printf("%p\n", aa);
// printf("hs length = %ld\n", ck_hs_count(&hs_symbol_table));
return;
}