lib: move visitor code into entities
heap: move alloc functions to entities