Easy Bytecode

Posted by Kaya Kupferschmidt • Wednesday, February 28. 2007 • Category: Programming
Writing a interpreter for a custom scripting language always seems to be more complex than writing a small bytecode compiler and bytecode interpreter. At a first glance, writing a direct interpreter might be easier, but if the scripting language contains flow control (like loops, if/else statements and similar constructs involving jumps), this turns out to be false. The primary problem lies in the fact that one needs to duplicate large parts of the parser - simply for skipping over the parts of a script that are not executed (like with a conditional if-block whose conditioon turns out to be false at runtime).

Because of this insight, I began to concentrate on writing an easy-to-implement bytecode compiler that would transform a text-based script into a more machine-friendly representation. A positive side-effect of bytecode is that simple fact that it is much faster to execute than the original textual representation. The downside of this approach is the fact that it involves writing a compiler - something that sounds to be a complex and difficult task.

But after analysing the process of parsing a script, I came to the conclusion that such a compiler and its corresponding bytecode interpreter ("virtual machine") would be rather straight-forward and easy to implement, if the underlying model of the virtual machine is chosen carefully. In my opinion the best machine model (in terms of simplicity to implement a compiler and interpreter) it a purely stack-based RPN (Reverse Polish notation) machine. And such a model not only is easy to implement, but it also easy to extract the original syntax tree from the bytecode, which in turn allows further optimisation techniques as a postprocessing step (it even wouldn't be to hard to turn bytecode into native assembler).

Continue reading "Easy Bytecode"

Reflection for C++

Posted by Kaya Kupferschmidt • Monday, February 26. 2007 • Category: C++
One hot topic I am currently busy in, is reflection for C++. Reflection for a computer language means that you can access all types toegther with their methods and members at runtime using a simple string-based interface. Such a feature especially simplifies binding scripting-languages to a program by providing one wrapper that operates on the reflection information instead of binding each class, method or function by hand. Other possible usages are remote-method-invocations, serialisation, XML based configurations etc.

C++ offers only some very basic runtime type information (RTTI) out of the box and lacks full reflection. There are some projects on the net that try to close this gap (most notably the Reflex framework), but none of them really seem to be as powerful, flexible and easy-to-use as their native counterparts in Java or C#.

Dimajix's framework Magnum soon will contain some new modules that try to fill this gap, by offering the following tools:

  • A generic Meta-Compiler based upon gccxml together with a specialised XML-based transformation language.

  • Non-intrusive, full reflection for all public elements of any C++ program given in source.

  • A Java-like scripting language built on top of the reflection together with a custom bytecode compiler.


With these tools, one can easily add generic scripting capabilities to any C++ program with only some little one-time effort. Plus it is possible to use the Metacompiler for automatically transforming any type-information given in C++ headers in any kind of text-based files, by providing a set of transformation rules which will be applied to the C++ metainformation generated with gccxml.

The new package is not completely finished yet, there are some features still missing, but work is steadily progressing. For a preview, you can simply check out the latest version of Magnum using Subversion at svn://subversion.dimajix.de/magnum.

Promotional Video for Windows 386

Posted by Kaya Kupferschmidt • Monday, January 29. 2007 • Category: Weird
While all people are talking about Windows Vista, lets look back in time:

The 80s really were a weird time, with a very strange taste for clothing. And a real laughable highlight is the Promotional Video for Windows 386 promoting the wodners of multitasking, with the best part coming at minute 7 after a boring start. Some people even wouldn't be surprised if it turned out to be sleazy porn scene.. It shouldn't be a surprise that you will not find many hits for the directory David Vik on google.

I am so glad that the 80s are over.

Status of Magnum

Posted by Kaya Kupferschmidt • Saturday, January 13. 2007 • Category: C++
A short intermission with a status report of Magnum. Finally I put up a public SVN repository which can be reached under svn://dimajix.de/magnum. The repository has public read access for everyone and is synched with my private development repository every night, so it is always almost up-to-date.

The most important feature that will be included in the next release version is full reflection. This means that one can access the complete type information including classes, structs, unions, enums, methods, functions, fields and variables via a dynamic interface at runtime. You can even invoke any method or create new instances of arbitrary objects. This should make it rather easy to make up a small scripting language which can access all types defined in Magnum.

This is a really huge undertaking, but most of the really hard stuff is already working (you can download the newest version via Subversion, as indicated above.). Still missing is some intelligent automatic argument casting for method-invocation (so you do not have to care about the exact needed types), some fixes for non-public class members and - most importantly - the integration into the build system.

The really special about my implementation of the reflection is that you will not need to modify your source-code (at least I try really hard to avoid the need of changes to the source code for which reflection is to be generated.) to make your classes accessible via reflection. The meta-compiler, which reads in all headers and creates some cpp files containing the needed runtime information for reflection, is also outstanding in that it uses a generic XML-based language to transform the meta-information parsed from the original header files into a new text-based output file. The metacompiler is not tied to my implementation of reflection and can (and will) be used for many other automatic header-transformations. For example one could write an XML template that generates serialisation code for arbitrary classes (this actually shouldn't be too hard). Other possible uses include the generation of COM or .Net wrappers (or for any other scripting language), etc.

Why Windows Home Server will be a success

Posted by Kaya Kupferschmidt • Tuesday, January 9. 2007 • Category: Workstations
According to ars technica, Bill Gates showed off his newest product, the Windows Home Server as part of his keynote last Sunday at the CES. The WHS is a small device intended to be the central server for home users for storing their photos, music etc. Paul Thurrot has a small preview of this server and a hardware implementation done by HP (Microsoft only delviers the operating system). On OSNews there has been a debate for the need of such a product.

I predict that the Windows Home Server will be a big success for Microsoft, and I will try to elaborate on the reasons: Nowadays we live in the so called "information age", that is after industrialisation, information is the new driving force in out culture. More and more people have have multiple computers at home (you do not want to know how many I own) and other electronic devices like digital cameras, media players, digital video recorders etc are already standard equipment in many households.

This means that digital content and properties replace traditional values in our life. This also means there is a new need for protection of your personal investments - ten years ago, you could mainly lose your possesions in terms of a physical loss. Nowadays more and more important and valuable data is stored on various computers at each home. This imposes two problems: First you want a centralized storage for all your digital data (photos, movies, music, documents etc), and second you want a secure backup of all your data. Many people become increasingly aware of the first problem, but the second is the really important one. In former times, you only lost part of your values if - for example - a CD got scratches or was stolen.

But nowadays if your harddisc crashes, you probably will lose a lot of irretrievable data like your private email etc. So you wish that you had a backup of all your data, or even better a centralized storage that is protected against hardware faults by some redundancy.

These are just the reasons why a home server makes sense for a lot of people today. One can argue that there are already a lot of good and affordable NAS boxes out there, but most of them are not more than simple NAS boxes (one exception would be Infrants product reportoire) that don't offer comfortable backup utilities or are too complicated for the average user. This is why I see espceially Windows Home Server to be a success - if done right and with the help of Microsofts massive marketing forces.

For me, I probably won't buy a Windows Home Server, because I want something more professional - I want to have a blindingly fast RAID server with tons of storage, support for different file protocols (NFS comes to my mind), although the hardware specs of HPs machien are promising: 1.8 GHz AMD Sempron paired with 512MB of RAM. This should offer twice the performance of Thecus N5200 NAS solution, which is already by far the fastest affordable home NAS out there (although with many firmware limitations and problems).

If Life Ran on a Solaris Cluster

Posted by Kaya Kupferschmidt • Monday, January 8. 2007 • Category: Weird
You might wonder what the girls at Sun expect from a boy friend. You can find the answer in a small spot at YouTube:

  • availability

  • reliability

  • redundancy


A Simple Sidebar