Dynamic typing <=> Static typing

I am currently working on a type system for owlisp.

Obviously, the requirement is that it can map the dynamic nature of Common Lisp types to the statically typed LLVM-IR representation.

My current idea of solving this is to represent a Lisp value in LLVM-IR as some LLVM structure type that looks like this:

{ i8, i8* }

The i8 carries a “type id”, which tells you what kind of type the i8* pointer really points to (RTTI). Depending on that type id, a dispatcher logic decides which type to cast the value behind the i8* pointer to.

If, for example, a type id of 2 represents the integer type, then the value behind i8* will would probably be cast to an i64 value before working on it.

I call the process of converting a primitive LLVM value (e.g. an i64 value) to a value of the above structure “boxing” and the reverse process “unboxing”.

I have already managed to implement compile-time versions of functions that do the boxing and unboxing and am currently trying to implement runtime versions of these. These will of course be necessary in order to implement a dynamically typed language, since this implies that type information is available at runtime.

I wonder how much more complicated all this will get… 😉 I’ll just advance step by step – once I got a working basic runtime type system, things will probably be simplified somewhat, so I can then move on and work on the next issue.

Since I am learning new stuff all along the way, I always have to be conscious of where I can introduce reasonable abstractions in my code. However, refactorings again in turn help me to gain a better understanding of what is going on 😉

Exciting stuff 🙂