gen: fix ~ operator implementation