示例#1
0
        static void DoFileWrite(string path, File.Script s)
        {
            string      filename = Path.Combine(path, s.Name);
            BlockToCode output   = CreateOutput(s.Name);

            GetScriptWriter(output).Write(s);
            output.WriteToFile(filename);
        }
示例#2
0
        public void Write(File.Script script)
        {
            ILBlock block = script.Block;

            if (block == null)
            {
                output.Error("Code '{0}' empty, but used here for script", script.Name);
                return; // error
            }
            else
            {
                File.Code codeData = script.Code;
                if (block == null)
                {
                    output.Error("Code '{0}' empty, but used here", codeData.Name);
                }
                else if (!codeUsed.ContainsKey(codeData.Name) || !codeUsed.TryAdd(codeData.Name, true)) // check if already done
                {
                    AddBlockToLocals(block);
                }
            }
            CheckAllVars();
            int arguments = 0;

            foreach (var e in block.GetSelfAndChildrenRecursive <ILExpression>(x => x.Code == GMCode.Var))
            {
                ILVariable v     = e.Operand as ILVariable;
                Match      match = Context.ScriptArgRegex.Match(v.Name);
                if (match != null && match.Success)
                {
                    int arg = int.Parse(match.Groups[1].Value) + 1; // we want the count
                    if (arg > arguments)
                    {
                        arguments = arg;
                    }
                }
            }
            ScriptInfo oi = new ScriptInfo();

            oi.Locals        = locals.ToDictionary(x => x.Key, z => z.Value);
            oi.Script        = script;
            oi.ArgumentCount = arguments;
            oi.Block         = block;
            WriteScript(oi);
        }