// Returns true if any export is necessary i.e. bytecode-only libraries will return false. private bool GetLibraryCode(string baseDir, LibraryForExport library, List <LangCSharp.DllFile> dllsOut, Dictionary <string, FileOutput> filesOut, ILibraryNativeInvocationTranslatorProvider libraryNativeInvocationTranslatorProviderForPlatform) { string libraryName = library.Name; this.Translator.CurrentLibraryFunctionTranslator = libraryNativeInvocationTranslatorProviderForPlatform.GetTranslator(libraryName); List <string> libraryLines = new List <string>(); if (library.ManifestFunction != null) { string libraryDir = baseDir + "Libraries/" + libraryName; libraryLines.Add(this.GenerateCodeForFunction(this.Translator, library.ManifestFunction)); foreach (FunctionDefinition funcDef in library.Functions) { libraryLines.Add(this.GenerateCodeForFunction(this.Translator, funcDef)); } filesOut[libraryDir + "/LibraryWrapper.cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join(this.NL, "using System;", "using System.Collections.Generic;", "using System.Linq;", "using Interpreter;", "using Interpreter.Structs;", "using Interpreter.Vm;", "", "namespace Interpreter.Libraries." + libraryName, "{", " public static class LibraryWrapper", " {", this.IndentCodeWithSpaces(string.Join(this.NL, libraryLines), 8), " }", "}", ""), }; foreach (ExportEntity codeFile in library.ExportEntities["COPY_CODE"]) { string targetPath = codeFile.Values["target"].Replace("%LIBRARY_PATH%", libraryDir); filesOut[targetPath] = codeFile.FileOutput; } foreach (ExportEntity dllFile in library.ExportEntities["DOTNET_DLL"]) { dllsOut.Add(new LangCSharp.DllFile(dllFile)); } return(true); } return(false); }
private void GetLibraryCode( TemplateReader templateReader, string baseDir, LibraryForExport library, List <LangCSharp.DllFile> dllsOut, HashSet <string> dotNetRefs, Dictionary <string, FileOutput> filesOut) { string libraryName = library.Name; TemplateSet libTemplates = templateReader.GetLibraryTemplates(library); List <string> libraryLines = new List <string>(); string libraryDir = baseDir + "Libraries/" + libraryName; foreach (string structKey in libTemplates.GetPaths("gen/structs/")) { string structFileName = structKey.Substring(structKey.LastIndexOf('/') + 1); string structName = System.IO.Path.GetFileNameWithoutExtension(structFileName); filesOut[libraryDir + "/" + structName + ".cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = libTemplates.GetText(structKey), }; } foreach (string helperFile in libTemplates.GetPaths("source/")) { filesOut[libraryDir + "/" + helperFile.Substring("source/".Length)] = new FileOutput() { Type = FileOutputType.Text, TextContent = libTemplates.GetText(helperFile), }; } filesOut[libraryDir + "/LibraryWrapper.cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = libTemplates.GetText("gen/LibraryWrapper.cs"), }; foreach (ExportEntity dllFile in library.ExportEntities["DOTNET_DLL"]) { dllsOut.Add(new LangCSharp.DllFile(dllFile)); } foreach (ExportEntity dotNetRef in library.ExportEntities["DOTNET_REF"]) { dotNetRefs.Add(dotNetRef.StringValue); } }
public ILibraryNativeInvocationTranslator GetTranslator(string libraryName) { LibraryForExport libraryForExport = null; foreach (LibraryForExport lfe in this.librariesForExport) { if (lfe.Name == libraryName) { libraryForExport = lfe; break; } } if (libraryForExport == null) { throw new Exception(); } return(new LibraryNativeInvocationTranslator(this.libraries[libraryName], libraryForExport)); }
public LibraryNativeInvocationTranslator(LibraryMetadata library, LibraryForExport lfe) { this.library = library; this.Library = lfe; }
// Returns true if any export is necessary i.e. bytecode-only libraries will return false. private bool GetLibraryCode( TemplateStorage templates, string baseDir, LibraryForExport library, List <LangCSharp.DllFile> dllsOut, Dictionary <string, FileOutput> filesOut) { string libraryName = library.Name; List <string> libraryLines = new List <string>(); if (library.HasPastelCode) { string libraryDir = baseDir + "Libraries/" + libraryName; string allFunctionCode = templates.GetCode("library:" + libraryName + ":functions"); libraryLines.Add(allFunctionCode); foreach (string structKey in templates.GetTemplateKeysWithPrefix("library:" + libraryName + ":struct:")) { string structName = templates.GetName(structKey); filesOut[libraryDir + "/Structs/" + structName + ".cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = this.WrapStructCode(templates.GetCode(structKey)), }; } filesOut[libraryDir + "/LibraryWrapper.cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join(this.NL, "using System;", "using System.Collections.Generic;", "using System.Linq;", "using Interpreter;", "using Interpreter.Structs;", "using Interpreter.Vm;", "", "namespace Interpreter.Libraries." + libraryName, "{", " public static class LibraryWrapper", " {", IndentCodeWithSpaces(string.Join(this.NL, libraryLines), 8), " }", "}", ""), }; foreach (ExportEntity codeFile in library.ExportEntities["COPY_CODE"]) { string targetPath = codeFile.Values["target"].Replace("%LIBRARY_PATH%", libraryDir); filesOut[targetPath] = codeFile.FileOutput; } foreach (ExportEntity dllFile in library.ExportEntities["DOTNET_DLL"]) { dllsOut.Add(new LangCSharp.DllFile(dllFile)); } return(true); } return(false); }