void LoadType(TypeDefinition typeDef) { Raise<TypeCheckException>.If(_structTypes.ContainsKey(typeDef.Name), "There is a type with the same name!"); var typeRef = Module.Import(typeDef); var structType = new StructType(typeRef.Name, typeRef); structType.Ctor = Module.Import(typeDef.Methods.First(m => m.Name == ".ctor")); structType.TypeEquals = Module.Import(typeDef.Methods.First(m => m.Name == "MyEquals")); _types.Add(typeRef.Name, structType); _structTypes.Add(typeRef.Name, structType); }
StructType AddStructType(StructDecl decl) { var name = decl.Name.ToLower(); Raise<TypeCheckException>.If(_types.ContainsKey(name)); const string nmsp = "DanglingLang.Runner"; const TypeAttributes typeAttr = TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.SequentialLayout; var typeDef = new TypeDefinition(nmsp, name, typeAttr, Module.Import(typeof(object))); var type = new StructType(name, typeDef); foreach (var f in decl.Fields) { var fieldType = GetType(f.Item2); Raise<TypeCheckException>.IfAreEqual("void", fieldType.Name, "Field cannot be void"); type.AddField(f.Item1, fieldType); } _types.Add(name, type); _structTypes.Add(name, type); return type; }