コード例 #1
0
 public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
 {
     this.cachedProc = proc;
     if (proc.CurrentScope.Exists("CrLf"))
     {
         this.crlf = proc.CurrentScope.GetVariable("CrLf");
     }
     else
     {
         this.crlf       = new Variable(proc.Name, true);
         this.crlf.Value = @"\r\n";
     }
     if (proc.CurrentScope.Exists(proc.DefaultWriter))
     {
         this.defaultWriter = proc.CurrentScope.GetVariable(proc.DefaultWriter);
         if (!this.defaultWriter.IsGlobal)
         {
             this.cachedComp.UpdateParameters(converter, proc, this.defaultWriter.Name, true);
         }
         if (this.parts != null)
         {
             foreach (ICompiler c in this.parts)
             {
                 c.Convert(converter, proc, file);
             }
         }
         else
         {
             converter.Convert(this);
         }
     }
 }
コード例 #2
0
        public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
        {
            // pas de test sur l'existence du tableau dans le dictionnaire
            IData res = Helper.ConvertNewExpression(this.cachedComp, proc, converter, this.expression);

            this.index = res.ValueString;
            // add a new variable or change an existing variable
            this.value = Helper.ConvertNewDictionaryArray(this.cachedComp, proc, converter, this.varName);
            converter.Convert(this);
        }
コード例 #3
0
 public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
 {
     if (converter.ImplementedFunctions.Exists(new Predicate <IFunction>(delegate(IFunction f) { return(f.StrictName == this.processName); })))
     {
         converter.Convert(this);
     }
     else
     {
         throw new Exception("Pour convertir le programme, les processus doivent être implémentés avant leur exécution; le processus '" + this.processName + "' n'a pas été déclaré.");
     }
 }
コード例 #4
0
        public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
        {
            IData res = Helper.ConvertNewExpression(this.cachedComp, proc, converter, this.expression);

            this.index = res.ValueString;
            if (proc.CurrentScope.Exists(proc.DefaultWriter))
            {
                this.defaultWriter = proc.CurrentScope.GetVariable(proc.DefaultWriter);
                if (!this.defaultWriter.IsGlobal)
                {
                    this.cachedComp.UpdateParameters(converter, proc, this.defaultWriter.Name, true);
                }
                converter.Convert(this);
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            string source = null;

            if (args.Length == 0)
            {
                Console.WriteLine("No input file specified");
                Environment.Exit(1);
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("Input file does not exist");
                Environment.Exit(1);
            }

            try
            {
                ICodeConverter cvt = (ICodeConverter) new CSCodeGenerator();
                source = cvt.Convert(File.ReadAllText(args[0]));
            }
            catch (Exception e)
            {
                Console.WriteLine("Conversion failed:\n" + e.Message);
                Environment.Exit(1);
            }

            source = CreateCSCompilerScript(source);

            try
            {
                Console.WriteLine(CompileFromDotNetText(source, "a.out"));
            }
            catch (Exception e)
            {
                Console.WriteLine("Conversion failed: " + e.Message);
                Environment.Exit(1);
            }

            Environment.Exit(0);
        }
コード例 #6
0
 public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
 {
     this.cachedProc = proc;
     if (proc.CurrentScope.Exists(this.varName))
     {
         this.isFromDict = false;
         this.value      = proc.CurrentScope.GetVariable(this.varName);
         // update parameters for this variable to use
         this.cachedComp.UpdateParameters(converter, proc, this.varName, false);
     }
     else if (proc.CurrentDictionnaire.IsString(this.varName))
     {
         this.isFromDict = true;
     }
     if (proc.CurrentScope.Exists(proc.DefaultWriter))
     {
         this.defaultWriter = proc.CurrentScope.GetVariable(proc.DefaultWriter);
         if (!this.defaultWriter.IsGlobal)
         {
             this.cachedComp.UpdateParameters(converter, proc, this.defaultWriter.Name, true);
         }
         converter.Convert(this);
     }
 }
コード例 #7
0
 public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
 {
     this.result = Helper.ConvertNewInferedVariable(this.cachedComp, proc, converter, this.expression, this.varName);
     converter.Convert(this);
 }
コード例 #8
0
        /// <summary>
        /// Converts script from LSL to CS and calls CompileFromCSText
        /// </summary>
        /// <param name="Script">LSL script</param>
        /// <returns>Filename to .dll assembly</returns>
        public void PerformScriptCompile(string Script, string asset, UUID ownerUUID,
                                         out string assembly, out Dictionary <KeyValuePair <int, int>, KeyValuePair <int, int> > linemap)
        {
            //            m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);

            IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface <IScriptModuleComms>();

            linemap = null;
            m_warnings.Clear();

            assembly = GetCompilerOutput(asset);

            if (!Directory.Exists(ScriptEnginesPath))
            {
                try
                {
                    Directory.CreateDirectory(ScriptEnginesPath);
                }
                catch (Exception)
                {
                }
            }

            if (!Directory.Exists(Path.Combine(ScriptEnginesPath,
                                               m_scriptEngine.World.RegionInfo.RegionID.ToString())))
            {
                try
                {
                    Directory.CreateDirectory(ScriptEnginesPath);
                }
                catch (Exception)
                {
                }
            }

            // Don't recompile if we already have it
            // Performing 3 file exists tests for every script can still be slow
            if (File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map"))
            {
                // If we have already read this linemap file, then it will be in our dictionary.
                // Don't build another copy of the dictionary (saves memory) and certainly
                // don't keep reading the same file from disk multiple times.
                if (!m_lineMaps.ContainsKey(assembly))
                {
                    m_lineMaps[assembly] = ReadMapFile(assembly + ".map");
                }
                linemap = m_lineMaps[assembly];
                return;
            }

            if (Script == String.Empty)
            {
                throw new Exception("Cannot find script assembly and no script text present");
            }

            enumCompileType language = DefaultCompileLanguage;

            if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture))
            {
                language = enumCompileType.cs;
            }
            if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture))
            {
                language = enumCompileType.vb;
                // We need to remove //vb, it won't compile with that

                Script = Script.Substring(4, Script.Length - 4);
            }
            if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture))
            {
                language = enumCompileType.lsl;
            }

            if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture))
            {
                language = enumCompileType.js;
            }

            if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
            {
                language = enumCompileType.yp;
            }

            //            m_log.DebugFormat("[Compiler]: Compile language is {0}", language);

            if (!AllowedCompilers.ContainsKey(language.ToString()))
            {
                // Not allowed to compile to this language!
                string errtext = String.Empty;
                errtext += "The compiler for language \"" + language.ToString() + "\" is not in list of allowed compilers. Script will not be executed!";
                throw new Exception(errtext);
            }

            if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false)
            {
                // Not allowed to compile to this language!
                string errtext = String.Empty;
                errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!";
                throw new Exception(errtext);
            }

            string compileScript = Script;

            if (language == enumCompileType.lsl)
            {
                // Its LSL, convert it to C#
                LSL_Converter = (ICodeConverter) new CSCodeGenerator(comms, m_insertCoopTerminationCalls);
                compileScript = LSL_Converter.Convert(Script);

                // copy converter warnings into our warnings.
                foreach (string warning in LSL_Converter.GetWarnings())
                {
                    AddWarning(warning);
                }

                linemap = ((CSCodeGenerator)LSL_Converter).PositionMap;
                // Write the linemap to a file and save it in our dictionary for next time.
                m_lineMaps[assembly] = linemap;
                WriteMapFile(assembly + ".map", linemap);
            }

            switch (language)
            {
            case enumCompileType.cs:
            case enumCompileType.lsl:
                compileScript = CreateCSCompilerScript(
                    compileScript,
                    m_scriptEngine.ScriptClassName,
                    m_scriptEngine.ScriptBaseClassName,
                    m_scriptEngine.ScriptBaseClassParameters);
                break;

            case enumCompileType.vb:
                compileScript = CreateVBCompilerScript(
                    compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName);
                break;
            }

            assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
        }
コード例 #9
0
 public void Convert(ICodeConverter converter, IProcessInstance proc, FinalFile file)
 {
     this.value = Helper.ConvertNewDictionaryString(this.cachedComp, proc, converter, this.varName);
     converter.Convert(this);
 }
コード例 #10
0
        ////private ICodeCompiler icc = codeProvider.CreateCompiler();
        //public string CompileFromFile(string LSOFileName)
        //{
        //    switch (Path.GetExtension(LSOFileName).ToLower())
        //    {
        //        case ".txt":
        //        case ".lsl":
        //            Common.ScriptEngineBase.Shared.SendToDebug("Source code is LSL, converting to CS");
        //            return CompileFromLSLText(File.ReadAllText(LSOFileName));
        //        case ".cs":
        //            Common.ScriptEngineBase.Shared.SendToDebug("Source code is CS");
        //            return CompileFromCSText(File.ReadAllText(LSOFileName));
        //        default:
        //            throw new Exception("Unknown script type.");
        //    }
        //}

        /// <summary>
        /// Converts script from LSL to CS and calls CompileFromCSText
        /// </summary>
        /// <param name="Script">LSL script</param>
        /// <returns>Filename to .dll assembly</returns>
        public string PerformScriptCompile(string Script, string asset)
        {
            m_positionMap = null;
            m_warnings.Clear();

            string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
                                              m_scriptEngine.World.RegionInfo.RegionID.ToString(),
                                              FilePrefix + "_compiled_" + asset + ".dll"));

//            string OutFile = Path.Combine(ScriptEnginesPath,
//                    FilePrefix + "_compiled_" + asset + ".dll");

            if (!Directory.Exists(ScriptEnginesPath))
            {
                try
                {
                    Directory.CreateDirectory(ScriptEnginesPath);
                }
                catch (Exception)
                {
                }
            }

            if (!Directory.Exists(Path.Combine(ScriptEnginesPath,
                                               m_scriptEngine.World.RegionInfo.RegionID.ToString())))
            {
                try
                {
                    Directory.CreateDirectory(ScriptEnginesPath);
                }
                catch (Exception)
                {
                }
            }

            if (Script == String.Empty)
            {
                if (File.Exists(OutFile))
                {
                    return(OutFile);
                }

                throw new Exception("Cannot find script assembly and no script text present");
            }

            // Don't recompile if we already have it
            //
            if (File.Exists(OutFile) && File.Exists(OutFile + ".text") && File.Exists(OutFile + ".map"))
            {
                ReadMapFile(OutFile + ".map");
                return(OutFile);
            }

            enumCompileType l = DefaultCompileLanguage;

            if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture))
            {
                l = enumCompileType.cs;
            }
            if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture))
            {
                l = enumCompileType.vb;
                // We need to remove //vb, it won't compile with that

                Script = Script.Substring(4, Script.Length - 4);
            }
            if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture))
            {
                l = enumCompileType.lsl;
            }

            if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture))
            {
                l = enumCompileType.js;
            }

            if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
            {
                l = enumCompileType.yp;
            }

            if (!AllowedCompilers.ContainsKey(l.ToString()))
            {
                // Not allowed to compile to this language!
                string errtext = String.Empty;
                errtext += "The compiler for language \"" + l.ToString() + "\" is not in list of allowed compilers. Script will not be executed!";
                throw new Exception(errtext);
            }

            string compileScript = Script;

            if (l == enumCompileType.lsl)
            {
                // Its LSL, convert it to C#
                LSL_Converter = (ICodeConverter) new CSCodeGenerator();
                compileScript = LSL_Converter.Convert(Script);

                // copy converter warnings into our warnings.
                foreach (string warning in LSL_Converter.GetWarnings())
                {
                    AddWarning(warning);
                }

                m_positionMap = ((CSCodeGenerator)LSL_Converter).PositionMap;
            }

            if (l == enumCompileType.yp)
            {
                // Its YP, convert it to C#
                compileScript = YP_Converter.Convert(Script);
            }

            switch (l)
            {
            case enumCompileType.cs:
            case enumCompileType.lsl:
                compileScript = CreateCSCompilerScript(compileScript);
                break;

            case enumCompileType.vb:
                compileScript = CreateVBCompilerScript(compileScript);
                break;

            case enumCompileType.js:
                compileScript = CreateJSCompilerScript(compileScript);
                break;

            case enumCompileType.yp:
                compileScript = CreateYPCompilerScript(compileScript);
                break;
            }

            return(CompileFromDotNetText(compileScript, l, asset));
        }
コード例 #11
0
ファイル: LSL2CS.cs プロジェクト: boodie/Opensim2
 public string Convert(ref string script)
 {
     //m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap;
     return(Converter.Convert(script));
 }
コード例 #12
0
        public void ConvertToParallel(ICodeConverter converter, ICompilateurInstance comp, IProcessInstance previousProc, FinalFile file)
        {
            EndJobs ej = new EndJobs();

            this.cachedComp         = comp;
            this.cachedPreviousFunc = converter.ImplementedFunctions.FindLast(new Predicate <IFunction>(delegate(IFunction search)
            {
                return(search.StrictName == previousProc.FunctionName);
            }));

            // première instruction
            this.Statements[0].Convert(converter, previousProc, file);

            // implémenter les fonctions job_xxx
            for (int index = 1; index < this.Statements.Count - 1; ++index)
            {
                ICompiler tache = this.Statements[index];
                // Check if it's a call job (blindage)
                if (tache is CallJob)
                {
                    CallJob cj = this.Statements[index] as CallJob;
                    ej.Jobs.Add(cj);

                    this.cachedProc = this.cachedComp.GetJobProcess(cj.ProcessName);
                    // Ecriture du code de la fonction
                    IFunction newFunc = Helper.MakeNewMethod(converter, this.cachedProc);
                    Helper.FillNewMethod(comp, this.cachedProc, converter, newFunc, file);
                    newFunc.IsJob = true;
                    //if (this.cachedProc.HasChanged) previousProc.HasChanged = true;

                    // aller chercher les variables exterieures au processus appellé
                    this.cachedFunc = converter.ImplementedFunctions.FindLast(new Predicate <IFunction>(delegate(IFunction func) { return(func.IsJob && func.StrictName == cj.ProcessName); }));
                    if (!converter.CallingFunctions.Exists(new Predicate <IFunction>(delegate(IFunction func) { return(func.IsJob && func.StrictName == cj.ProcessName && func.InstanceNumber == this.cachedFunc.InstanceNumber); })))
                    {
                        converter.CallingFunctions.Add(this.cachedFunc);
                    }

                    // convertir pour le parallèllisme
                    if (!this.alreadyInstantiated)
                    {
                        // create a new structure to contain all external values
                        string structTypeName = this.cachedComp.Unique.ComputeNewString();
                        ++converter.CurrentFunction.PrivateVariableCounter;
                        string structInstanceName = structTypeName + converter.CurrentFunction.PrivateVariableCounter.ToString();

                        // Construit une structure et indique que l'instance doit être mutable
                        this.structRef = converter.CreateNewField(structTypeName, structInstanceName, true);
                    }

                    // ajoute une instance de la structure déclarée dans la fonction en cours
                    if (converter.IsStronglyTyped)
                    {
                        this.cachedFunc.InstancesStructure.Add(this.Structure.PrefixedFieldName, this.Structure.StructureType);
                    }
                    else
                    {
                        this.cachedFunc.InstancesStructure.Add(this.Structure.FieldName, this.Structure.StructureType);
                    }

                    // créer un nouveau paramètre et y inscrire tous les autres paramètres
                    Converters.Parameter parStructure = new Parameter();
                    parStructure.EffectiveParameter = this.Structure.PrefixedFieldName;
                    parStructure.FormalParameter    = this.Structure.PrefixedFieldName;
                    parStructure.VariableName       = this.Structure.FieldName;
                    parStructure.IsComputable       = false;
                    parStructure.IsMutableParameter = true;
                    // stocker tous les paramètres dans le nouveau paramètre de type structure
                    List <IStructure> newParams = this.GetElements(this.structList, converter, this.cachedFunc).ToList();
                    parStructure.StructureReferences.AddRange(newParams);
                    this.structList       = newParams;
                    parStructure.DataType = EnumDataType.E_STRUCTURE;

                    this.cachedFunc.Parameters.Clear();
                    this.cachedFunc.Parameters.Add(parStructure);
                    this.alreadyInstantiated = true;
                }
            }

            // ajout de la structure
            converter.Convert(this);

            // création des instructions en parallèle
            // appels des fonctions job_xxx
            for (int index = 1; index < this.Statements.Count - 1; ++index)
            {
                ICompiler tache = this.Statements[index];
                // Check if it's a call job (blindage)
                if (tache is CallJob)
                {
                    CallJob cj = tache as CallJob;
                    cj.StructureReference = this.Structure;
                    this.cachedProc       = this.cachedComp.GetJobProcess(cj.ProcessName);
                    this.cachedProc.MakeOneInstance(previousProc, new RunInnerInstanceProcess(delegate(IProcessInstance previous, IProcessInstance i)
                    {
                        cj.Convert(converter, i, file);
                    }));
                }
            }

            // attendre la fin de toutes les tâches
            ej.WaitForAllJobs(converter);

            // dernière instruction
            this.Statements[this.Statements.Count - 1].Convert(converter, previousProc, file);
        }
コード例 #13
0
 public void WaitForAllJobs(ICodeConverter converter)
 {
     converter.Convert(this);
 }