General Category > Ideas

Typeinfo at runtime

(1/1)

lerno:
I want to suggest that type info should be available at runtime. There are various way to implement this. In the end, the type should only be reduced to a number that’s used to access a generated a set of functions that are built during code generation.

To do this we need to introduce another built in type, ”vtype”.


--- Code: ---vtype x = typeof(a);
bool y = is_struct(x);

--- End code ---

What’s interesting here is for scripting and very dynamic plugins.
A function may take a void* plus the vtype and work on the data as if it was the given type, even though the code was built BEFORE the type was written.

The most general use for this is to dump structure data for debugging.
The macro can then be something like:


--- Code: ---#define DUMP(x) dump_data(typeof(x), (void*)&x)

--- End code ---

(Very rough, but hopefully you see what I mean)

dump_data here is a FUNCTION not a macro.

This is just a discussion starter. Add to the idea!

bas:
For the macro system we will need something like typeof(), eg for swap() (pseudo code)


--- Code: ---macro swap(x, y) {
   typeof(x) tmp = x;
   x = y;
   y = tmp;
}

--- End code ---

I don't really like the vtype as it makes the language more complex again..

lerno:
vtype could actually be simply an enum, generated at runtime.

Navigation

[0] Message Index

Go to full version