|September 18, 2003|
|Floating-point and addresses in Metacode|
It's always hard to find time to make progress on the Metacode implementation, but there was actually some progress over the summer.
First I implemented some support for floating-point. Ideally, this should emulate the target machine model, but for now I did something quick that uses the host machine facilities. In fact, I currently assume that host and target have floating point types of the same size. Mostly I worked on the floating-point expression support to enable the universal mypow example that I used as an illustration in the original Metacode presentation. So that works now.
I have also started work on the implementation of “addresses”. I.e., everything having to do with pointers and references (that includes array indexing, this pointers, and so forth). The main issue, of course, is that we cannot every allow metacode to cause the compiler to crash. Hence I needed a relatively elaborate and yet portable scheme to support all the strange things that C++ says are possible. I think the final result is not too bad, but I'm only at the beginning stages of implementing this.
One of the issues I had to cope with was that pointer types are POD types, and therefore one could memcpy a pointer value from some location and that might be OK. However, if it's not OK I'd better not try to actually derefence a random location. In the end, I chose to represent pointers by indices into a dynamic table of active location values. With some care, you can ensure that every entry in that table is valid, and it's easy enough to ensure that every “pointer” honors the table bounds.
Once that will be working decently, I will be able to add a metacode function to allocate memory dynamically, which in turn will ease the implementation of some of the dynamic structures I described in the original Metacode presentation (things like stdmeta::array and stdmeta::id. It also looks like it would not be hard to add some garbage collection to this system and so I might just do that for the fun of it.