コード例 #1
0
ファイル: Compiler.cs プロジェクト: kameronbrooks/UnityCCL
        /// <summary>
        /// Main compilation entry
        /// </summary>
        /// <returns></returns>
        ///
        protected virtual CompiledScript _InternalCompile()
        {
            _cdata = new CompilerData(_assembly);
            List <Func <object> > functions = new List <Func <object> >();

            while (!isAtEnd)
            {
                Func <object> function = null;
                object        compiled = CompileDeclaration();
                if (compiled == null)
                {
                    continue;
                }
                Type returnType = CompilerUtility.GetReturnType(compiled);

                TypeDef typeDef = _assembly.GetTypeDef(returnType);

                if (CompilerUtility.IsFunc(compiled))
                {
                    if (compiled.GetType() != typeof(Func <object>))
                    {
                        function = typeDef.ToGenericFunction(compiled, _cdata);
                    }
                    else
                    {
                        function = (Func <object>)compiled;
                    }
                }
                else if (CompilerUtility.IsReference(compiled))
                {
                    function = ((Reference)compiled).CreateGetFunction(_cdata);
                }
                else
                {
                    function = () => { return(compiled); };
                }
                functions.Add(function);
            }
            Func <object>[] funcArray = functions.ToArray();

            CompiledScript compiledScript = new CompiledScript(() =>
            {
                object output = null;
                for (int mn = 0; mn < funcArray.Length; mn += 1)
                {
                    output = funcArray[mn]();
                    if ((_cdata._runtimeFlags & (int)CompilerData.ControlInstruction.Exit) != 0)
                    {
                        break;
                    }
                }
                _cdata._runtimeFlags = 0;
                return(_cdata._returnValue);
            },
                                                               _cdata);

            return(compiledScript);
        }
コード例 #2
0
    public void OnCompile()
    {
        Stopwatch watch = new Stopwatch();

        watch.Start();

#if UNITY_EDITOR
        _script = CCL.ScriptUtility.CompileScript(_inputText.text, typeof(Context));
        _script.SetContext(new Context(_outputText));
#else
        try
        {
            _script = CCL.ScriptUtility.CompileScript(_inputText.text, typeof(Context));
            _script.SetContext(new Context(_outputText));
        } catch (System.Exception e)
        {
            _outputText.text = "Compilation Error: " + e.Message;
        }
#endif

        watch.Stop();
        _compileTimeText.text = "Compile: " + watch.ElapsedMilliseconds + "ms";
    }