private Unit LinkForeignModule(Unit self, Reference mod) { var dll = string.Equals(mod.DllName, "std", StringComparison.OrdinalIgnoreCase) ? "Dyalect.Library" : mod.DllName; if (!FindModuleExact(self.FileName, dll + ".dll", mod, out var path)) { return(null); } if (!AssemblyMap.TryGetValue(path, out Dictionary <string, Type> dict)) { dict = LoadAssembly(path, mod); } if (dict != null) { if (!dict.TryGetValue(mod.ModuleName, out Type sysType)) { AddError(LinkerError.AssemblyModuleNotFound, mod.SourceFileName, mod.SourceLocation, mod.ModuleName, mod.DllName); return(null); } object module; try { module = Activator.CreateInstance(sysType); } catch (Exception ex) { AddError(LinkerError.AssemblyModuleLoadError, mod.SourceFileName, mod.SourceLocation, mod.ModuleName, mod.DllName, ex.Message); return(null); } if (!(module is Unit unit)) { AddError(LinkerError.InvalidAssemblyModule, mod.SourceFileName, mod.SourceLocation, mod.ModuleName, mod.DllName); return(null); } unit.FileName = path; return(unit); } return(null); }
private Dictionary <string, ForeignUnit>?LookupAssembly(Unit self, string dll, Reference? @ref = null) { if (!AssemblyMap.TryGetValue(dll, out var dict)) { if (!Lookup.Find(Path.GetDirectoryName(self.FileName), dll, out var path)) { return(null); } dict = LoadAssembly(path, @ref ?? Reference.Empty); if (dict is not null) { AssemblyMap.Add(dll, dict); } if (dll == DYALECTLIB) { dyalectLib = dict; } } return(dict); }