soltanis
May 21st, 2009, 06:20 AM
My two favorite concepts in programming are C and lambda expressions (anonymous functions).
Now the biggest obstacle to having functions that write functions in C is the fact that C is compiled directly to machine-specific binary. With the ability to load shared libraries dynamically, on demand, and with modern C compilers, perhaps one could eventually realize the dream of such proposed languages as `C (which is C with more or less one extension, a backtick operator, which marks a block of code to be compiled at run-time).
What I'm saying is this; ostensibly, one could write a C compiler that did something like this:
1) Recognizes a certain section of code as being marked for run-time compilation; or allows arbitrary, run-time determined data to be compiled into machine code, then executed on demand;
2) Compiles the rest of the executable, and links to it a fast C compiler or C compiler library (ex. tcc).
3) At run-time, compiles code on demand by running the compiler through it, writing it into a shared library and loading the library into memory, mapping things like function pointers to functions in that library;
4) On-demand code can now be executed by use of function pointers.
The first versions of tcc didn't even write executable code to disk; they loaded the binary straight into memory. Those familiar with tcc also know that it can be used as a "scripting" language, whereby a C "script" is compiled and immediately executed by tcc. Which is pretty damn cool.
C, extended with the ability to have code that writes code, would be (in my opinion) one hell of an ultimate language.
Now the biggest obstacle to having functions that write functions in C is the fact that C is compiled directly to machine-specific binary. With the ability to load shared libraries dynamically, on demand, and with modern C compilers, perhaps one could eventually realize the dream of such proposed languages as `C (which is C with more or less one extension, a backtick operator, which marks a block of code to be compiled at run-time).
What I'm saying is this; ostensibly, one could write a C compiler that did something like this:
1) Recognizes a certain section of code as being marked for run-time compilation; or allows arbitrary, run-time determined data to be compiled into machine code, then executed on demand;
2) Compiles the rest of the executable, and links to it a fast C compiler or C compiler library (ex. tcc).
3) At run-time, compiles code on demand by running the compiler through it, writing it into a shared library and loading the library into memory, mapping things like function pointers to functions in that library;
4) On-demand code can now be executed by use of function pointers.
The first versions of tcc didn't even write executable code to disk; they loaded the binary straight into memory. Those familiar with tcc also know that it can be used as a "scripting" language, whereby a C "script" is compiled and immediately executed by tcc. Which is pretty damn cool.
C, extended with the ability to have code that writes code, would be (in my opinion) one hell of an ultimate language.