Add static generator

Close #163
All of these functions should be marked as unsafe.