gen: move the management of ds[] to gen.c