Friday, May 22, 2009

Building a framework for compilers...

I'm taking a break from the Parser Compiler madness to work on some functionality that would be useful for a compiler. It's what I call an AssemblyWorkspace. It's basically a large scale wrapper around the concept of an INamespaceParent (which is also a type parent). In creating an AssemblyWorkspace, you provide it with the assembly that's its 'core' assembly. Typical examples would be the Intermediate Project you're working on building through the infrastructure. On top of the core assembly, there's the referenced assemblies.

The namespace of the workspace is a union of all the namespaces within its scope, same goes for the types. When a type is encountered, if there are multiple instances of that type in the current scope, a light-weight wrapper type is introduced into the system, an ambiguity type. The ambiguity type contains a list of the types that are locked for the name.

Now the concept is simple, but making it work is a lot of work. I'm making it as simple and straight forward as any other INamespaceParent, so you can iterate the namespace names, types, and so on without having to worry about where that type comes from. Its aim is to simplify the symbol resolution phase. It'll be used for the global scope that exists beyond the current type hierarchy the code structure has available to it. I'll likely create a scope system which will use an AssemblyWorkspace as its core aspect and go from there. The other fun issue with it is making it malleable so that when references are inserted and removed, the workspace remains current. The final issue is speed. The higher level the implementation the more likely it is to be slow. The Abstraction Project is very high level. Its meant to be as simple as can be and every concept that can be expressed in a simplified form, is.

Common example:

var myAssembly = IntermediateGateway.CreateAssembly("myAssembly");
myAssembly.AssemblyInformation.AssemblyVersion = new Version(1, 0);
var defaultNamespace = myAssembly.Namespaces.Add("MyNamespace.Subnamespace");
var testClass = defaultNamespace.Classes.Add("TestClass");
var bitwiseAndOp = testClass.BinaryOperatorCoercions.Add(CoercibleBinaryOperators.BitwiseAnd, testClass);

The scope implementation will have an alias system, an import system (for namespaces) and general querying functionality to simplify lookup.

On an amusing note, I create some hellateous type-names:

No comments: