simpler implementation of compile_function