When two or more persons shall be jointly indicted or prosecuted, the court may, at any time before the defendants have gone into their defense, direct any defendant to be discharged, that he may be a witness for the state. A defendant shall, also, when there is not sufficient evidence to put him on his defense, at any time before the evidence is closed, be discharged by the court for the purpose of giving his testimony for a codefendant. The order of discharge shall be a bar to another prosecution for the same offense.
§ 546.280, RSMo