Extending InspecTree with support for semantic analysis

In my previous post, I showed how I wanted to transpile my C# lambdas to GLSL shaders in my rendering engine. I created a library, InspecTree, which gives you access to the entire syntax tree of a lambda, statement bodies and all. This was a great start, but I quickly realized that I would want more than just the syntax tree. I would also want to know the types of the variables, the return type of the lambda, which methods that were being called inside the lambda, and more specifically check if a lambda is capturing one or more variables from an outer scope (more on why this would be a problem later). ...

October 5, 2024 · 6 min · daniel cronqvist

InspecTree: C# Expression<T> with statement body support

What’s an Expression<T>? I strongly suggest you refer to the official documentation for a more in-depth explanation, but in short, an Expression<T> is a type in C# that will give you access to a supplied lambda expression as a syntax-tree-like object. This expression tree can then be traversed and inspected, and you can do all sorts of cool things with it, e.g. transpile it to another language, or even execute it. ...

September 14, 2024 · 7 min · daniel cronqvist