Sure, in a perfect world the patent application for software would consist of submitting all the lines of your source code. It would be granted automatically as long as it was not a copy itself. The source code would not have to be disclosed to the public. Anyone found copying your source code or compiler output verbatim would be prima facie infringing but all others would be free to compete with your "invention" via their own development effort.