-
Notifications
You must be signed in to change notification settings - Fork 2
metaprogramming
metaprogramming — write programs that writes programs. Meta let us use topmost high-level design still making very effective and compact software, able to work fast even on very tiny computers starting from 8K SRAM microcontrollers.
What is has the power of right programming language is an ability to define new control structures, and to dig into compiler/interpreter internals work.
The most primitive way to feel this is using FORTH language, take some intro book and play with any programming language you are friendly with. Take Python or JS for the first time, define stack, vocabulary, and define a few dozens of primitive VM commands as functions. I did this replacing the most Forth disadvantage: uncontrollable memory writing, and results look really good. I replaced memory addresses by names items in an associative array (Python dictionary), and now I can address objects and storage places in vocabulary by names.
Next, you should define interpreter which will execute vectors as a sequential program, words (functions) which create a new executable vector from single elements, and interpreter parses user input and searches names element in vocabulary.
That's all, you already have a primitive programming language, which you can modify itself (in runtime too).
Next step is unavailable in classical Forth, but has really extra power: you must add programming language composing elements into your language, works like lex/yacc or PEG grammar parser.
This required DSL-definition feature has the real power: now you can define any programming language you want, with any syntax, including C, Pascal, Python (with some work), or even C++ (need some powerful grammar definition engine). This also must be my next step in metaprogramming language design: I’m digging into making Prolog in Python to use complex context-sensitive DCG parsing.