Back in the days, I've seen that with C files, which are compiled on the fly to a temporary file an run.
Something like //usr/bin/gcc -o main "$0"; ./main "$@"; exit
Something like //usr/bin/gcc -o main "$0"; ./main "$@"; exit
The main reason was to do all this without any dependencies beyond a C compiler and some POSIX standard library.