3 Apr 2009 Jasper1984   » (Observer)

How Lang does conversion to C or Lisp

Lang has a reader, reading trees with the symbols, a resolver, which resolves all the types from constants specification by the user and function overloading. This little article is about what follows, converting to C, or Lisp. (Or anything else)

From that last one one also, of course wants to convert to something that can actually execute. I used to have a rather ugly function to convert to C directly. The problem with that is that C does not have higher order functions or bodies inside function arguments.

The older solution solved that in the conversion itself, which is probably why it stunk so much. The newer version works differently; it uses conversion functions that can only convert a subset of Lang.

However, i add transformations that change Lang code such that it is in those subsets. That way, if i want to add conversions to other languages, it should be easy, unless the language a smaller subset then previously encountered. In that case, i would have to make another transformation. I might be overconfident here, though.

Note that it is still very incomplete, no higher order functions yet. Making a transformation to that subset for C might be tricky, for conversion to Common Lisp it isn't a subset. Another thing that i didn't do yet is types for the common lisp version. First, i am planning to express number types like this: (integer from to) and (number from to), that would work with lisp better. (I also want to keep C-like number treatment though.)

This principle, and the code might well be able to convert Common Lisp to other stuff as wel, i guess i don't have to worry that this work is useless if the Lang project fails.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!