I had some new ideas today, and they are awesome. Beyond awesome. Let's start.
#1 Precompile templates. Cut whatever's necessary to do so. Currently on the list is the single-pass compilation stuff at least, maybe ADL (which I was going to cut anyway) and possibly extension methods (which I was going to add) and in addition quite possibly some of the freedom involved in the current specialization. This is going to be implemented by compiling functions to machine code which operate on compiler-internal types- effectively compiling the templates as a language to machine code. As they can be pre-compiled then concepts checking would be almost free, because it's running in machine code and is gonna be a couple data structure lookups.
#2 Add arbitrary compile-time functions. This means allow all Phase 1 types and functions, which basically means the entire Standard lib except I/O, including dynamic allocation, etc. Do not allow arbitrary string compilation (unless you write a compiler yourself). Phase 2 functions can create types, make copies (types are immutable in the current model), and they can take, read, and create functions in an AST form, which will allow them to take functions and convert them into, say, other languages like HLSL or SQL. These will also be pre-compiled. Phase 2 functions can, as an implementation addition, use C-style interfaces loaded from DLLs or maybe even included as .libs. Exceptions can be done in Intellisense.
#3 Run Phase 2 and Phase 1 functions and use Phase 2 and Phase 1 types at run-time.
TODO: Maybe merge Phase 2 and Phase 1? But that could get messy.
Languages aren't great, they're just theories. Implementations make great things happen.
boo lets you do this with what they call "syntactic macros". These work with a two-pass method: the compiler compiles the syntactic macros which are basically functions that take and produce ASTs, and then it compiles the stuff that uses these macros, by invoking them. Writing them is easy because ASTs are a first-class member of the language.
ReplyDelete