示例#1
0
    void ExecuteLine(string codeStr)
    {
        // at this point we either have a line to be immediately compiled and evaluated,
        // or a function definition.
        CHash  type = CHash.Expression;
        string className = null, assemblyName = null, funName = null;
        Match  funMatch = funDef.Match(codeStr);

        if (funMatch != Match.Empty)
        {
            type = CHash.Function;
        }
        if (type == CHash.Function)
        {
            funName = funMatch.Groups[1].ToString();
            macro.RemoveMacro(funName);
            className    = "Csi" + nextAssembly++;
            assemblyName = className + ".dll";
            codeStr      = codeStr.Insert(funMatch.Groups[1].Index, "_");
        }
        codeStr = macro.ProcessLine(codeStr);
        if (codeStr == "")  // may have been a prepro statement!
        {
            return;
        }
        bool wasAssignment;

        codeStr = MassageInput(codeStr, out wasAssignment);
        if (wasAssignment)
        {
            type = CHash.Assignment;
        }
        CompilerResults cr = CompileLine(codeStr.TrimStart(), type, assemblyName, className);

        if (cr != null)
        {
            Assembly ass = cr.CompiledAssembly;
            if (type != CHash.Function)
            {
                CodeChunk.Instantiate(ass, this);
            }
            else
            {
                CsiFunctionContext.Instantiate(ass, varTable, className, funName);
                string prefix = mustDeclare ? "" : "$";
                macro.AddMacro(funName, prefix + className + "._" + funName, null);
                AddReference(Path.GetFullPath(assemblyName));
            }
        }
    }
示例#2
0
    void ExecuteLine(string codeStr)
    {
        if (codeStr == lastCodeStr)
        {
            CodeChunk.Instantiate(lastAssembly, varTable);
            return;
        }
        // at this point we either have a line to be immediately compiled and evaluated,
        // or a function definition.
        // long st = Environment.TickCount;  // interpretation time is around 250 millesec
        string className = null, assemblyName = null, funName = null;
        Match  funMatch = funDef.Match(codeStr);
        bool   hasName  = funMatch != Match.Empty;

        if (hasName)
        {
            funName = funMatch.Groups[1].ToString();
            macro.RemoveMacro(funName);
            System.Console.WriteLine(funName);
            className    = "Csi" + nextAssembly++;
            assemblyName = className + ".dll";
            codeStr      = codeStr.Insert(funMatch.Groups[1].Index, "_");
        }
        codeStr = macro.ProcessLine(codeStr);
        if (codeStr == "")  // may have been a prepro statement!
        {
            return;
        }
        CompilerResults cr = CompileLine(codeStr, hasName, assemblyName, className);

        if (cr != null)
        {
            Assembly ass = cr.CompiledAssembly;
            if (!hasName)
            {
                CodeChunk.Instantiate(ass, varTable);
                lastCodeStr  = codeStr;
                lastAssembly = ass;
            }
            else
            {
                CsiFunctionContext.Instantiate(ass, varTable, className, funName);
                macro.AddMacro(funName, "$" + className + "._" + funName, null);
                AddReference(assemblyName);
            }
        }
        // long dt = Environment.TickCount - st;
        // Console.Write("alltime = " + dt + "\n");
    }
示例#3
0
    public static void Instantiate(Assembly a, Hashtable table)
    {
        long st = 0;

        try {
            st = Environment.TickCount;
            CodeChunk chunk = (CodeChunk)a.CreateInstance("CsiChunk");
            long      ddt   = Environment.TickCount - st; Write("time createinstance " + ddt + "\n"); st = Environment.TickCount;
            chunk.Go(table);
        }  catch (Exception ex) {
            Print(ex.GetType() + " was thrown: " + ex.Message);
        }
        long dt = Environment.TickCount - st;

        Write("time = " + dt + "   ...   " + Interpreter.rawLine + "\n");
    }
示例#4
0
    public static void Instantiate(Assembly a, Interpreter interp)
    {
        Hashtable table = interp.VarTable;

        try {
            CodeChunk chunk = (CodeChunk)a.CreateInstance("CsiChunk");
            chunk.Go(table);
            // vs 0.8 we display the type and value of expressions.  The variable $_ is
            // always set, which is useful if you want to save the result of the last
            // calculation.
            if (interp.returnsValue && DumpingValue)
            {
                object val   = table["_"];
                Type   type  = val.GetType();
                string stype = type.ToString();
                if (stype.StartsWith("System."))                  // to simplify things a little bit...
                {
                    stype = stype.Substring(7);
                }
                stype = "(" + stype + ")";
                if (val is string)
                {
                    Print(stype, "'" + val + "'");
                }
                else
                if (val is IEnumerable)
                {
                    Print(stype);
                    Dumpl((IEnumerable)val);
                }
                else
                {
                    Print(stype, val);
                }
            }
        }  catch (Exception ex) {
            Print(ex.GetType() + " was thrown: " + ex.Message);
        }
    }