The main goals – in details.
The DGL (Declarative GUI programming Language) Project is about developing a (Open Source) translator/compiler, and an interpreter, which will make it a lot more easier to develop desktop software.
The translator translates from a declarative programming language to GTK+ C code. Using a declarative language has several benefits. The benefits are (incomplete list):
- Describe what the program should accomplish, rather than describeing how to go about accomplishing it.
- Implement the use of actor based concurrency, that is, the declarative programming language will have implicit support for parallel programming of multi core microprocessors, without much effort of the programmer. The Actor based concurrency in DGL will use ideas from the Erlang programming language.
My thoughts about how to implement it.
My idea is to use the clang LLVM compiler API, and the LLVM infrastructure.
Everything below is made with the purpose to collect information to the declarative programming lanuge can do semantic checks and generate code:
- First we lets clang create an AST for the GTK+ C++ code header files (and its dependencies). The AST is saved in a LLVM bitcode file.
- From 1) we create our own AST – everything but the inheritance hierarchy is lost: This is our type information. It is used for doing type checks, and generate GTK+ C code macro type casts
- Now we will let clang create an AST of the GTK+ C code header file (and its dependecies)
- Create a file with translation rules for clangs AST to our own AST.
- This a huge step: A tree parser wich reads the file with translation rules, and reads the clang AST from step 3. From those 2 inputs it adds information to our existing AST from step 2.
The added information is f.x. this function belogs to this type. It is a constructor/desctructor/set property/get property/or a signal. A function also has a return type, and a argument list. Each argument does also has a type, and a type has a size in memory. I think i can borrow some code from clang (verbatim copying).
I think this is the required steps to obtain all the knowledge the declarative language will need.
After this I “only” need to create a lexical analyser for the language, a parser, a tree parser to create an AST, and a LLVM IR codegenrator.
There exisist LLVM tools wich translates to LLVM bitcode. LLVM bitcode can be translated into C and C++ code, and machine code for a number of microprocessor architectures. LLVM bitcode can also be used by LLVMs JIT compiler.
The declarative programming language will of course need to have a way of escapeing to an non-declarative programming language where the programmer can tell the machine how a task in an event handler should be accomplished, but what being said, if you only want to change some properties, and say, open a pop up menu, you can still use the declarative programming language.
The escape to a non-declarative programming language feature will have syntax to generate code wich creates declaration of variable(s) with the correct type. Syntax for generating code that sends a getter and/or setter message to the Application actor is also supported.
A simple language could also be supported in the future: Mozilla had created a new language called Rust, it looks interesting (it does also use LLVM). Lua is also possible and is a more mature language.
i think i will create an compiler first, and then an interpreter.
with an interpreter i can create a GTK+ widget wich shows the GUI while you are codeing in the language. That widget could be used in an editor. Needless to say what that widget should have a plugin architecture, so it can be extended in ways I never have thought of.
Currently I am doing some prototypeing on the grammar with the ANTLRWorks tool – it has some nice features:
I will not use the ANTLR generator – it isn’t the right tool for the job in my opinion (YMMV), but it is good for the initial work.
Please note that I take the liberty to delete any comments posted here that I deem inappropriate, off-topic, or insulting. And I excercise this liberty quite agressively. So yes, if you comment here, I might censor you. If you don’t want to be censored your are welcome to comment on your own blog instead.