コード例 #1
0
ファイル: Functions.OS.cs プロジェクト: andyfreer/cscs
        protected override Variable Evaluate(ParsingScript script)
        {
            string funcReturn, funcName;

            Utils.GetCompiledArgs(script, out funcReturn, out funcName);

#if __ANDROID__ == false && __IOS__ == false
            Precompiler.RegisterReturnType(funcName, funcReturn);

            Dictionary <string, Variable> argsMap;
            string[] args = Utils.GetCompiledFunctionSignature(script, out argsMap);

            script.MoveForwardIf(Constants.START_GROUP, Constants.SPACE);
            int parentOffset = script.Pointer;

            string body = Utils.GetBodyBetween(script, Constants.START_GROUP, Constants.END_GROUP);

            Precompiler precompiler = new Precompiler(funcName, args, argsMap, body, script);
            precompiler.Compile();

            CustomCompiledFunction customFunc = new CustomCompiledFunction(funcName, body, args, precompiler, argsMap, script);
            customFunc.ParentScript = script;
            customFunc.ParentOffset = parentOffset;

            ParserFunction.RegisterFunction(funcName, customFunc, false /* not native */);
#endif
            return(new Variable(funcName));
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: themustafaahmed/compiler
        public static List <Variable> GetArgs(string data, ref int from,
                                              char start, char end, out bool isList)
        {
            List <Variable> args = new List <Variable>();

            isList = from < data.Length && data[from] == Constants.START_GROUP;

            if (from >= data.Length || data[from] == Constants.END_STATEMENT)
            {
                return(args);
            }

            int lastChar = from;

            Utils.GetBodyBetween(data, ref lastChar, start, end);

            while (from < lastChar)
            {
                Variable item = Utils.GetItem(data, ref from);
                if (item.Equals(Variable.EmptyInstance))
                {
                    break;
                }

                args.Add(item);
            }


            MoveForwardIf(data, ref from, end, Constants.SPACE);

            return(args);
        }
コード例 #3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string funcName = Utils.GetToken(script, Constants.TOKEN_SEPARATION);

            //Interpreter.Instance.AppendOutput("Registering function [" + funcName + "] ...");

            string[] args = Utils.GetFunctionSignature(script);
            if (args.Length == 1 && string.IsNullOrWhiteSpace(args[0]))
            {
                args = new string[0];
            }

            script.MoveForwardIf(Constants.START_GROUP, Constants.SPACE);
            int parentOffset = script.Pointer;

            string body = Utils.GetBodyBetween(script, Constants.START_GROUP, Constants.END_GROUP);

            CustomFunction customFunc = new CustomFunction(funcName, body, args);

            customFunc.ParentScript = script;
            customFunc.ParentOffset = parentOffset;

            ParserFunction.RegisterFunction(funcName, customFunc, false /* not native */);

            return(new Variable(funcName));
        }
コード例 #4
0
        public async Task <Variable> DebugBlockIfNeeded(ParsingScript stepInScript, bool done, Action <bool> doneEvent)
        {
            if (SteppingOut || Continue || ReplMode || !m_firstBlock)
            {
                return(null);
            }
            m_firstBlock = false;
            done         = stepInScript.GoToNextStatement() > 0;
            if (done)
            {
                return(Variable.EmptyInstance);
            }

            ProcessingBlock = true;

            ParsingScript tempScript = new ParsingScript(stepInScript.String, stepInScript.Pointer);

            tempScript.ParentScript = stepInScript;
            tempScript.InTryBlock   = stepInScript.InTryBlock;
            /* string body = */ Utils.GetBodyBetween(tempScript, Constants.START_GROUP, Constants.END_GROUP);

            await StepIn(stepInScript);

            ProcessingBlock = false;
            done            = stepInScript.Pointer >= tempScript.Pointer ||
                              LastResult.IsReturn ||
                              LastResult.Type == Variable.VarType.BREAK ||
                              LastResult.Type == Variable.VarType.CONTINUE;

            doneEvent(done);
            return(LastResult);
        }
コード例 #5
0
        public Variable DebugBlockIfNeeded(ParsingScript stepInScript, ref bool done)
        {
            if (SteppingOut || Continue || ReplMode || !m_firstBlock)
            {
                return(null);
            }
            m_firstBlock = false;
            done         = stepInScript.GoToNextStatement() > 0;
            if (done)
            {
                return(Variable.EmptyInstance);
            }

            ProcessingBlock = true;

            ParsingScript tempScript = new ParsingScript(stepInScript.String, stepInScript.Pointer);

            tempScript.ParentScript = stepInScript;
            tempScript.InTryBlock   = stepInScript.InTryBlock;
            string body = Utils.GetBodyBetween(tempScript, Constants.START_GROUP, Constants.END_GROUP);

            Trace("Started ProcessBlock");
            StepIn(stepInScript);

            ProcessingBlock = false;
            done            = stepInScript.Pointer >= tempScript.Pointer;

            Trace("Finished ProcessBlock");
            return(LastResult);
        }
コード例 #6
0
        public static async Task <List <Variable> > GetArgsAsync(ParsingScript script,
                                                                 char start, char end, Action <bool> outList)
        {
            List <Variable> args   = new List <Variable>();
            bool            isList = script.StillValid() && script.Current == Constants.START_GROUP;

            if (!script.StillValid() || script.Current == Constants.END_STATEMENT)
            {
                return(args);
            }

            ParsingScript tempScript = script.GetTempScript(script.String, script.Pointer);

            /*ParsingScript tempScript = new ParsingScript(script.String, script.Pointer);
             * tempScript.ParentScript = script;
             * tempScript.InTryBlock = script.InTryBlock;*/

            if (script.Current != start && script.TryPrev() != start &&
                (script.Current == ' ' || script.TryPrev() == ' '))
            { // Allow functions with space separated arguments
                start = ' ';
                end   = Constants.END_STATEMENT;
            }

            // ScriptingEngine - body is unsed (used in Debugging) but GetBodyBetween has sideeffects
#pragma warning disable 219
            string body = Utils.GetBodyBetween(tempScript, start, end);
#pragma warning restore 219
            // After the statement above tempScript.Parent will point to the last
            // character belonging to the body between start and end characters.

            while (script.Pointer < tempScript.Pointer)
            {
                Variable item = await Utils.GetItemAsync(script, false);

                args.Add(item);
                if (script.Pointer < tempScript.Pointer)
                {
                    script.MoveForwardIf(Constants.END_GROUP);
                    script.MoveForwardIf(Constants.NEXT_ARG);
                }
                if (script.Pointer == tempScript.Pointer - 1)
                {
                    script.MoveForwardIf(Constants.END_ARG, Constants.END_GROUP);
                }
            }

            if (script.Pointer <= tempScript.Pointer)
            {
                // Eat closing parenthesis, if there is one, but only if it closes
                // the current argument list, not one after it.
                script.MoveForwardIf(Constants.END_ARG, end);
            }

            script.MoveForwardIf(Constants.SPACE);
            //script.MoveForwardIf(Constants.SPACE, Constants.END_STATEMENT);
            outList(isList);
            return(args);
        }
コード例 #7
0
        public static void GetCompiledArgs(ParsingScript script, out string funcReturn, out string funcName)
        {
            string body  = Utils.GetBodyBetween(script, Constants.END_ARG, Constants.START_ARG);
            var    parts = body.Split();

            funcReturn = parts.Length > 1 ? parts[0] : "void";
            funcName   = parts.Last();
        }
コード例 #8
0
 protected override Variable Evaluate(ParsingScript script)
 {
     string body = script.TryPrev() == Constants.START_GROUP ?
                   Utils.GetBodyBetween(script, Constants.START_GROUP, Constants.END_GROUP) :
                   Utils.GetBodyBetween(script, Constants.START_ARG, Constants.END_ARG);
     ThreadPool.QueueUserWorkItem(ThreadProc, body);
     return Variable.EmptyInstance;
 }
コード例 #9
0
ファイル: Functions.OS.cs プロジェクト: 99hats/cscs
        protected override Variable Evaluate(ParsingScript script)
        {
            string body = Utils.GetBodyBetween(script, Constants.START_ARG,
                                               Constants.END_ARG);
            ParsingScript threadScript = new ParsingScript(body);

            lock (lockObject) {
                threadScript.ExecuteAll();
            }
            return(Variable.EmptyInstance);
        }
コード例 #10
0
ファイル: Functions.OS.cs プロジェクト: 99hats/cscs
        protected override Variable Evaluate(ParsingScript script)
        {
            string body = Utils.GetBodyBetween(script, Constants.START_ARG, Constants.END_ARG);

            Thread newThread = new Thread(ThreadFunction.ThreadProc);

            newThread.Start(body);

            int threadID = newThread.ManagedThreadId;

            return(new Variable(threadID));
        }
コード例 #11
0
ファイル: Functions.OS.cs プロジェクト: shincar/cscs
        protected override Variable Evaluate(ParsingScript script)
        {
            string body = Utils.GetBodyBetween(script, Constants.START_ARG,
                                               Constants.END_ARG);
            ParsingScript threadScript = new ParsingScript(body);

            // BUGBUG: Alfred - what is this actually locking?
            // Vassili - it's a global (static) lock. used when called from different threads
            lock (lockObject)
            {
                threadScript.ExecuteAll();
            }
            return(Variable.EmptyInstance);
        }
コード例 #12
0
        public static List <Variable> GetArgs(ParsingScript script,
                                              char start, char end, out bool isList)
        {
            List <Variable> args = new List <Variable>();

            isList = script.StillValid() && script.Current == Constants.START_GROUP;

            if (!script.StillValid() || script.Current == Constants.END_STATEMENT)
            {
                return(args);
            }

            ParsingScript tempScript = new ParsingScript(script.String, script.Pointer);

            tempScript.ParentScript = script;
            tempScript.InTryBlock   = script.InTryBlock;

            string body = Utils.GetBodyBetween(tempScript, start, end);

            // After the statement above tempScript.Parent will point to the last
            // character belonging to the body between start and end characters.

            while (script.Pointer < tempScript.Pointer)
            {
                Variable item = Utils.GetItem(script, false);
                args.Add(item);
                if (script.Pointer < tempScript.Pointer)
                {
                    script.MoveForwardIf(Constants.NEXT_ARG);
                }
                if (script.Pointer == tempScript.Pointer - 1)
                {
                    script.MoveForwardIf(Constants.END_ARG);
                }
            }

            if (script.Pointer <= tempScript.Pointer)
            {
                // Eat closing parenthesis, if there is one, but only if it closes
                // the current argument list, not one after it.
                script.MoveForwardIf(Constants.END_ARG);
            }

            script.MoveForwardIf(Constants.SPACE);
            //script.MoveForwardIf(Constants.SPACE, Constants.END_STATEMENT);
            return(args);
        }
コード例 #13
0
        internal async Task <Variable> ProcessForAsync(ParsingScript script)
        {
            string forString = Utils.GetBodyBetween(script, Constants.START_ARG, Constants.END_ARG);

            script.Forward();
            if (forString.Contains(Constants.END_STATEMENT.ToString()))
            {
                // Looks like: "for(i = 0; i < 10; i++)".
                await ProcessCanonicalForAsync(script, forString);
            }
            else
            {
                // Otherwise looks like: "for(item : array)"
                await ProcessArrayForAsync(script, forString);
            }

            return(Variable.EmptyInstance);
        }
コード例 #14
0
        string ProcessFunction(List <string> tokens, int id, ref bool newVarAdded)
        {
            //string restStr = string.Join("", tokens.GetRange(m_tokenId, tokens.Count - m_tokenId).ToArray());
            string restStr    = tokens[m_tokenId];
            int    paramStart = restStr.IndexOf("(");
            int    paramEnd   = paramStart < 0 ? restStr.Length : restStr.IndexOf(")", paramStart + 1);

            while (paramEnd < 0 && ++m_tokenId < tokens.Count)
            {
                paramEnd = tokens[m_tokenId].IndexOf(")");
                restStr += tokens[m_tokenId];
            }
            string functionName = paramStart < 0 ? restStr : restStr.Substring(0, paramStart);
            string argsStr      = "";

            if (paramStart >= 0)
            {
                if (paramEnd <= paramStart)
                {
                    paramEnd = restStr.Length;
                }
                //ParsingScript script = new ParsingScript (restStr.Substring (paramStart, paramEnd - paramStart));
                ParsingScript script = new ParsingScript(restStr.Substring(paramStart, restStr.Length - paramStart));
                argsStr = Utils.PrepareArgs(Utils.GetBodyBetween(script));
            }

            string result = "";

            if (ProcessArray(argsStr, functionName, ref result))
            {
                return(result);
            }

            string conversion = "";
            var    type       = GetVariableType(functionName);

            if (type != Variable.VarType.NONE)
            {
                conversion = type == Variable.VarType.NUMBER ? ".AsDouble()" : ".AsString()";
            }

            result = "Utils.RunCompiled(\"" + functionName + "\", \"" + argsStr + "\")" + conversion;
            return(result);
        }
コード例 #15
0
ファイル: Functions.cs プロジェクト: themustafaahmed/compiler
        protected override Variable Evaluate(string data, ref int from)
        {
            string funcName = Utils.GetToken(data, ref from, Constants.TOKEN_SEPARATION);

            _interpreter.AppendOutput("Registering function " + funcName + "()");

            string[] args = Utils.GetFunctionSignature(data, ref from);
            if (args.Length == 1 && string.IsNullOrWhiteSpace(args[0]))
            {
                args = new string[0];
            }

            Utils.MoveForwardIf(data, ref from, Constants.START_GROUP, Constants.SPACE);

            string body = Utils.GetBodyBetween(data, ref from, Constants.START_GROUP, Constants.END_GROUP);

            CustomFunction customFunc = new CustomFunction(funcName, body, args);

            ParserFunction.AddGlobal(funcName, customFunc);

            return(new Variable(funcName));
        }
コード例 #16
0
        string ProcessFunction(List <string> tokens, ref int id, ref string result, ref bool newVarAdded)
        {
            //string restStr = string.Join("", tokens.GetRange(m_tokenId, tokens.Count - m_tokenId).ToArray());
            string restStr    = tokens[m_tokenId];
            int    paramStart = restStr.IndexOf('(');
            int    paramEnd   = paramStart < 0 ? restStr.Length : restStr.IndexOf(')', paramStart + 1);

            while (paramEnd < 0 && ++m_tokenId < tokens.Count)
            {
                paramEnd = tokens[m_tokenId].IndexOf(')');
                restStr += tokens[m_tokenId];
            }
            string functionName = paramStart < 0 ? restStr : restStr.Substring(0, paramStart);
            string argsStr      = "";

            if (paramStart >= 0)
            {
                if (paramEnd <= paramStart)
                {
                    paramEnd = restStr.Length;
                }
                ParsingScript tmpScript = new ParsingScript(restStr.Substring(paramStart, restStr.Length - paramStart));
                argsStr = Utils.PrepareArgs(Utils.GetBodyBetween(tmpScript));
            }

            string token = "";

            if (ProcessArray(argsStr, functionName, ref token))
            {
                result += token;
                return(token);
            }

            string conversion = "";
            var    type       = GetVariableType(functionName);

            if (type != Variable.VarType.NONE)
            {
                conversion = type == Variable.VarType.NUMBER ? ".AsDouble()" : ".AsString()";
            }

            StringBuilder sb = new StringBuilder();
            char          ch = '(';

            int index = functionName.IndexOf('.');

            if (index > 0 && id < tokens.Count - 2 && tokens[id + 1] == "=")
            {
                //functionName = "SetProperty";
                argsStr = tokens[id + 2];
                sb.AppendLine("    __action =\"=\";");
                ch = '=';
                id = tokens.Count;
            }
            else
            {
                sb.AppendLine("    __action =\"\";");
            }

            sb.AppendLine("    __argsStr =\"" + argsStr + "\";");
            sb.AppendLine("    __script = new ParsingScript(__argsStr);");
            sb.AppendLine("    __func = new ParserFunction(__script, \"" + functionName + "\", '" + ch + "', ref __action);");

            if (AsyncMode)
            {
                sb.AppendLine("    __tempVar = await __func.GetValueAsync(__script);");
                sb.AppendLine("    __current = __tempVar.AsString();");
            }
            else
            {
                sb.AppendLine("    __current = __func.GetValue(__script).AsString();");
            }

            token = sb.ToString();
            if (tokens.Count >= 3 && tokens[1] == "=" && !string.IsNullOrEmpty(result))
            {
                result      = token + result + " __current;\n";
                newVarAdded = true;
            }
            else
            {
                result += token;
            }

            return(token);
        }