コード例 #1
0
ファイル: PlatformProvider.cs プロジェクト: djlw78/crayon
        public AbstractPlatform GetPlatform(string name)
        {
            if (platforms == null)
            {
                platforms = new Dictionary <string, AbstractPlatform>();
                foreach (System.Reflection.Assembly assembly in GetRawAssemblies())
                {
                    AbstractPlatform platform = this.GetPlatformInstance(assembly);
                    platform.PlatformProvider = this;
                    string key = platform.Name.ToLowerInvariant();
                    if (platforms.ContainsKey(key))
                    {
                        throw new System.InvalidOperationException("Multiple platforms with the same ID: '" + key + "'");
                    }
                    platforms[key] = platform;
                }
            }

            if (name != null)
            {
                name = name.ToLowerInvariant();
                if (platforms.ContainsKey(name))
                {
                    return(platforms[name]);
                }
            }

            return(null);
        }
コード例 #2
0
        public string TranslateNativeInvocation(Token throwToken, AbstractPlatform translator, string functionName, object[] args)
        {
            if (this.translations == null)
            {
                string methodTranslations = this.ReadFile(System.IO.Path.Combine("methods", this.platformName + ".txt"), false);
                this.translations = new Dictionary <string, string>();
                foreach (string line in methodTranslations.Split('\n'))
                {
                    string[] parts = line.Trim().Split(':');
                    if (parts.Length > 1)
                    {
                        string key   = parts[0];
                        string value = parts[1];
                        for (int i = 2; i < parts.Length; ++i)
                        {
                            value += ":" + parts[i];
                        }
                        this.translations[key.Trim()] = value.Trim();
                    }
                }
            }

            if (this.translations.ContainsKey(functionName))
            {
                string output = this.translations[functionName];
                for (int i = 0; i < args.Length; ++i)
                {
                    string argAsString = translator.Translate(args[i]);
                    output = output.Replace("[ARG:" + (i + 1) + "]", argAsString);
                }
                return(output);
            }

            throw new ParserException(throwToken, "No native translation provided for " + functionName);
        }
コード例 #3
0
        private static void Compile(string[] args)
        {
            BuildContext     buildContext = Program.GetBuildContext(args);
            AbstractPlatform platform     = GetPlatformInstance(buildContext);

            platform.Compile(buildContext, buildContext.SourceFolder, buildContext.OutputFolder);
        }
コード例 #4
0
 public LibraryResourceDatabase(Library library, AbstractPlatform platform)
 {
     this.library                 = library;
     this.exportEntities          = null;
     this.ApplicablePlatformNames = new HashSet <string>();
     while (platform != null)
     {
         this.ApplicablePlatformNames.Add(platform.Name);
         platform = platform.ParentPlatform;
     }
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: geofrey/crayon
		public Parser(AbstractPlatform platform, BuildContext buildContext, SystemLibraryManager sysLibMan)
		{
			this.NullablePlatform = platform;
			this.IsTranslateMode = platform != null;
			this.CurrentClass = null;
			this.CurrentSystemLibrary = null;
			this.BuildContext = buildContext;
			this.VariableIds = new VariableIdAllocator();
			this.SystemLibraryManager = sysLibMan ?? new SystemLibraryManager();
			this.CurrentNamespace = "";
			this.NamespacePrefixLookupForCurrentFile = new List<string>();
		}
コード例 #6
0
ファイル: Parser.cs プロジェクト: falun/crayon
 public Parser(AbstractPlatform platform, BuildContext buildContext, SystemLibraryManager sysLibMan)
 {
     this.NullablePlatform     = platform;
     this.IsTranslateMode      = platform != null;
     this.CurrentClass         = null;
     this.CurrentSystemLibrary = null;
     this.BuildContext         = buildContext;
     this.SystemLibraryManager = sysLibMan ?? new SystemLibraryManager();
     this.CurrentNamespace     = "";
     this.NamespacePrefixLookupForCurrentFile = new List <string>();
     this.ConstantAndEnumResolutionState      = new Dictionary <Executable, int>();
 }
コード例 #7
0
        public string GetLibrarySwitchStatement(AbstractPlatform platform)
        {
            List <string> output = new List <string>();

            foreach (string name in this.orderedListOfFunctionNames)
            {
                output.Add("case " + this.libFunctionIds[name] + ":\n");
                output.Add("$_comment('" + name + "');");
                output.Add(this.importedLibraries[this.functionNameToLibraryName[name]].GetTranslationCode(name));
                output.Add("\nbreak;\n");
            }
            if (this.orderedListOfFunctionNames.Count == 0)
            {
                output.Add("case 0: break;");
            }
            return(string.Join("\n", output));
        }
コード例 #8
0
ファイル: InterpreterCompiler.cs プロジェクト: geofrey/crayon
		public InterpreterCompiler(AbstractPlatform platform, SystemLibraryManager sysLibMan)
		{
			this.platform = platform;
			this.interpreterParser = new Parser(platform, null, sysLibMan);
		}
コード例 #9
0
		internal ExpressionTranslator(AbstractPlatform platform)
		{
			this.platform = platform;
			this.Platform = platform.PlatformId;
			this.Language = platform.LanguageId;
		}
コード例 #10
0
ファイル: InterpreterCompiler.cs プロジェクト: falun/crayon
 public InterpreterCompiler(AbstractPlatform platform, SystemLibraryManager sysLibMan)
 {
     this.platform          = platform;
     this.interpreterParser = new Parser(platform, null, sysLibMan);
 }