I do not understand how a program such as an interpreter can run and create code "on the fly" to run. Can someone help me understand what such a program would have to do in order to function?
I'm familiar with the process that a compiler takes the input file, creates the AST, produces the machine code, then the result is an .exe, .elf, etc. file to be run. The OS loader then takes the .exe (or .elf) file and loads that code into a memory chunk and starts execution. I understand that that process can fork and create a copy of it's process space, or create a new thread with system calls to the OS. I just don't understand how a program can run code itself. Does it just get extra space in its address space to write new code to? Does the typical CPU segmentation model even allow write access to the code segment? Is there a built in way to tell the OS Loader that the program will create and run new code on it's own?