static void debug_print_hash(lref_t obj, lref_t port, bool machine_readable) { assert(HASHP(obj)); WRITE_TEXT_CONSTANT(port, _T("{")); /* REVISIT: Print shallow flag? */ debug_print_hash_elements(obj, port, machine_readable); write_char(port, '}'); }
EVAL_INLINE lref_t apply(lref_t function, size_t argc, lref_t argv[], lref_t *env, lref_t *retval) { lref_t args[3]; if (SUBRP(function)) { return subr_apply(function, argc, argv, env, retval); } else if (CLOSUREP(function)) { lref_t c_code = CLOSURE_CODE(function); *env = extend_env(arg_list_from_buffer(argc, argv), CAR(c_code), CLOSURE_ENV(function)); return CDR(c_code); /* tail call */ } else if (argc > 0) { if (HASHP(function) || STRUCTUREP(function)) { args[0] = function; args[1] = argv[0]; args[2] = (argc > 1) ? argv[1] : NIL; *retval = lslot_ref(MAX2(argc + 1, 2), args); return NIL; } else if (SYMBOLP(function)) { if (HASHP(argv[0]) || STRUCTUREP(argv[0])) { args[0] = argv[0]; args[1] = function; args[2] = (argc > 1) ? argv[1] : NIL; *retval = lslot_ref(MAX2(argc + 1, 2), args); return NIL; } } } vmerror_wrong_type(function); return NIL; }
static void debug_print_hash_elements(lref_t obj, lref_t port, bool machine_readable) { assert(HASHP(obj)); fixnum_t count = 0; lref_t key, val; hash_iter_t ii; hash_iter_begin(obj, &ii); while (hash_iter_next(obj, &ii, &key, &val)) { count++; write_char(port, _T(' ')); debug_print_object(key, port, machine_readable); write_char(port, _T(' ')); debug_print_object(val, port, machine_readable); } }
bool hash_iter_next(lref_t hash, hash_iter_t * iter, lref_t * key, lref_t * val) { assert(HASHP(hash)); while (*iter < HASH_SIZE(hash)) { if (hash_entry_used_p(HASH_ENTRY(hash, *iter))) { if (key) *key = HASH_ENTRY(hash, *iter)->key; if (val) *val = HASH_ENTRY(hash, *iter)->val; *iter = *iter + 1; return true; } *iter = *iter + 1; } return false; }
INLINE unsigned int HASH_COUNT(lref_t hash) { assert(HASHP(hash)); return hash->as.hash.table->count; }
INLINE void SET_HASH_COUNT(lref_t hash, unsigned int count) { assert(HASHP(hash)); hash->as.hash.table->count = count; }
INLINE bool HASH_SHALLOW(lref_t hash) { assert(HASHP(hash)); return hash->as.hash.table->is_shallow; }
INLINE void SET_HASH_SHALLOW(lref_t hash, bool is_shallow) { assert(HASHP(hash)); hash->as.hash.table->is_shallow = is_shallow; }
INLINE struct hash_entry_t *HASH_ENTRY(lref_t hash, size_t index) { assert(HASHP(hash)); return &(hash->as.hash.table->data[index]); }
INLINE void SET_HASH_MASK(lref_t obj, size_t mask) { checked_assert(HASHP(obj)); obj->as.hash.table->mask = mask; }
INLINE size_t HASH_MASK(lref_t obj) { checked_assert(HASHP(obj)); return obj->as.hash.table->mask; }
void hash_iter_begin(lref_t hash, hash_iter_t * iter) { assert(HASHP(hash)); *iter = 0; }