add functions that use textlib, and fix bugs in codegen.c
fix up error handling in the kernel code