private void button10_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { CSLE.ICLS_Expression exp = compilerResult; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); //try { CSLE.CLS_Content content = this.scriptService.CreateContent(); returnvalue = exp.ComputeValue(content); } //catch (Exception err) //{ // Log_Error("执行错误" + err.ToString()); //} if (returnvalue.type != null) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
private void button2_Click(object sender, EventArgs e) { listLog.Items.Clear(); tokensResult = null; try { tokensResult = this.scriptService.ParserToken(richTextBox_Code.Text); using (System.IO.Stream fiels = System.IO.File.OpenWrite(curCodeFile + ".bytes")) { this.scriptService.tokenParser.SaveTokenList(tokensResult, fiels); } } catch (Exception err) { Log_Error("词法识别失败"); } using (System.IO.Stream fiels = System.IO.File.OpenRead(curCodeFile + ".bytes")) { tokensResult = this.scriptService.tokenParser.ReadTokenList(fiels); } if (tokensResult != null && tokensResult.Count > 0) { compilerResult = scriptService.Expr_CompilerToken(tokensResult); //if (compilerResult == null) //{ // Log("尝试作为表达式编译"); // compilerResult = scriptService.CompilerToken(tokens, true); //} //compilerResult = compiler.Optimize(compilerResult); ShowExp(compilerResult); } }
private void button6_Click(object sender, EventArgs e) { if (compilerResult == null) { return; } compilerResult = this.scriptService.Expr_Optimize(compilerResult); ShowExp(compilerResult); }
void ShowExp(CSLE.ICLS_Expression value) { treeViewExp.Nodes.Clear(); if (value == null) { return; } TreeNode node = new TreeNode(); ShowExpNode(node, value); treeViewExp.Nodes.Add(node); treeViewExp.ExpandAll(); }
private void button9_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { DateTime t1 = DateTime.Now; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); int count = 1000; for (int i = 0; i < count; i++) { CSLE.ICLS_Expression exp = compilerResult; try { CSLE.CLS_Content content = this.scriptService.CreateContent(); returnvalue = exp.ComputeValue(content); } catch (Exception err) { Log_Error("执行错误" + err.ToString()); return; } } DateTime t2 = DateTime.Now; Log("C#Lite count=" + count + "time:" + (t2 - t1).TotalSeconds); if (returnvalue.type != null) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
void ShowExpNode(TreeNode node, CSLE.ICLS_Expression value) { if (value == null) { node.Text = "null"; } else { node.Text = value.ToString(); CSLE.ICLS_Expression exp = value as CSLE.ICLS_Expression; if (exp != null && exp.listParam != null) { foreach (var v in exp.listParam) { TreeNode subnode = new TreeNode(); ShowExpNode(subnode, v); node.Nodes.Add(subnode); } } } }
private void button3_Click(object sender, EventArgs e) { listLog.Items.Clear(); if (compilerResult == null) { button2_Click(sender, e); } if (compilerResult != null) { CSLE.ICLS_Expression exp = compilerResult; CSLE.CLS_Content.Value returnvalue = new CSLE.CLS_Content.Value(); CSLE.CLS_Content content = this.scriptService.CreateContent(); try { returnvalue = exp.ComputeValue(content); } catch (Exception err) { string contentValue = content.DumpValue(); string contentStack = content.DumpStack(null); string systemError = "SystemError:\n" + err.ToString(); MessageBox.Show(contentValue + "\n" + contentStack + "\n" + systemError); Log_Error("执行错误" + err.ToString() + ":" + contentStack + "\n" + contentValue); } if (returnvalue == null) { Log("result=<none>"); } else if (null != returnvalue.type) { Log("result=<" + returnvalue.type.Name + ">" + returnvalue.value); } else { Log("result=<unknown>" + returnvalue.value); } } }
private void Profile(int count) { string code = richTextBox_Code.Text; try { string codelite = "return " + code; var tokens = this.scriptService.ParserToken(code); compilerResult = this.scriptService.Expr_CompilerToken(tokens, true); compilerResult = this.scriptService.Expr_Optimize(compilerResult); if (compilerResult != null) { CSLE.CLS_Content.Value result = null; DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { CSLE.CLS_Content content = this.scriptService.CreateContent(); //compilerResult = compiler.Compiler(code); CSLE.ICLS_Expression exp = compilerResult; result = exp.ComputeValue(content); } DateTime t2 = DateTime.Now; Log("C#Lite count=" + count + "time:" + (t2 - t).TotalSeconds); if (result.type != null) { Log("result=<" + result.type.Name + ">" + result.value.ToString()); } else { Log("result=null"); } } } catch (Exception err) { Log("C#Lite error"); } string codelua = "function test() \n return " + code + "\nend"; try { int result = 0; var lua = UniLua.LuaAPI.NewState(); var state = lua.L_DoString(codelua); int itop = lua.GetTop(); DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { //lua.SetTop(itop); lua.GetGlobal("test"); // 加载 lua 中定义的一个名叫 foo 的全局函数到堆栈 lua.Call(0, 1); // 调用函数 foo, 指明有2个参数,没有返回值 //lua.SetTop(0); //lua.PCall(0, -1, 0); result = lua.ToInteger(-1); lua.Pop(1); //lua.p(1); } DateTime t2 = DateTime.Now; Log("unilua count=" + count + " time=" + (t2 - t).TotalSeconds); Log("result=<int>" + result); } catch (Exception err) { Log("unilua error."); } try { object ssresult = null; ScriptNET.Script ssc = ScriptNET.Script.CompileExpression(code); DateTime t = DateTime.Now; for (int i = 0; i < count; i++) { ssc.Context = new ScriptNET.Runtime.ScriptContext(); ssresult = ssc.Execute(); } DateTime t2 = DateTime.Now; Log("ssharp count=" + count + " time=" + (t2 - t).TotalSeconds); Log("result=<int>" + ssresult); } catch (Exception err) { Log("ssharp error."); } }
private void button6_Click(object sender, EventArgs e) { if (compilerResult == null) return; compilerResult = this.scriptService.Expr_Optimize(compilerResult); ShowExp(compilerResult); }
private void button2_Click(object sender, EventArgs e) { listLog.Items.Clear(); tokensResult = null; try { tokensResult = this.scriptService.ParserToken(richTextBox_Code.Text); using (System.IO.Stream fiels = System.IO.File.OpenWrite(curCodeFile + ".bytes")) { this.scriptService.tokenParser.SaveTokenList(tokensResult, fiels); } } catch (Exception err) { Log_Error("词法识别失败"); } using (System.IO.Stream fiels = System.IO.File.OpenRead(curCodeFile + ".bytes")) { tokensResult = this.scriptService.tokenParser.ReadTokenList(fiels); } //try //{ if (tokensResult != null && tokensResult.Count > 0) { compilerResult = scriptService.Expr_CompilerToken(tokensResult); //if (compilerResult == null) //{ // Log("尝试作为表达式编译"); // compilerResult = scriptService.CompilerToken(tokens, true); //} //compilerResult = compiler.Optimize(compilerResult); ShowExp(compilerResult); } //} //catch(Exception err) //{ // Log_Error("编译失败"); //} }