Interpreter.ExecuteLine C# (CSharp) Method

ExecuteLine() private method

private ExecuteLine ( string codeStr ) : void
codeStr string
return void
    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));
            }
        }
    }
	

Usage Example

示例#1
0
 public void CheckSet()
 {
     interpreter.ExecuteLine("set a 5");
     CheckValue(5, "a");
     CheckCount(1);
     interpreter.ExecuteLine("set a 2");
     CheckValue(2, "a");
     CheckCount(1);
     interpreter.ExecuteLine("set b 1");
     CheckValue(1, "b");
     CheckCount(2);
 }
All Usage Examples Of Interpreter::ExecuteLine