protected static LpObject send(LpObject self, LpObject[] args, LpObject block = null) { var methodName = args[0].stringValue; var sendedArgs = args.Skip(1).Take(args.Length - 1).ToArray(); return(self.funcall(methodName, sendedArgs, block)); }
private static LpObject loop(LpObject self, LpObject[] args, LpObject block = null) { LpObject ret = LpNl.initialize(); if (block == null) { return(ret); } while (true) { ret = block.funcall("call", args, null); // break文 if (ret.controlStatus == ControlCode.BREAK) { ret.controlStatus = ControlCode.NONE; break; } // next文 if (ret.controlStatus == ControlCode.NEXT) { ret.controlStatus = ControlCode.NONE; break; } } return(ret); }
static long runNode(string[] argv) { string fileName = argv[0]; string code = readFile(fileName); var parser = new Parser.LpGrammer(); var language = new LanguageData(parser); ScriptApp app = new ScriptApp(language); var tree = app.Parser.Parse(code); Object.LpObject result = null; try { result = (Object.LpObject)app.Evaluate(tree); if (result == null) { Debug.WriteLine("null"); } else { Console.WriteLine(result); Console.WriteLine("result: {0}", result); result.funcall("display", new Object.LpObject[] { }, null); } } catch (Error.LpError e) { Console.WriteLine(e.ToString()); } Debug.WriteLine("Finish"); return(0); }
static void consoleReadFile() { printVersion(); // Console.WriteLine("[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin"); // Console.WriteLine("[Type 'help' 'copyright' 'credits' or 'licence' for more information"); Debug.WriteLine("initialize"); var parser = new Parser.LpGrammer(); //Console.WriteLine("initialize parser"); var language = new LanguageData(parser); //Console.WriteLine("initialize language"); ScriptApp app = new ScriptApp(language); Debug.WriteLine("parse"); string line = null; do { Console.Write(" >> "); line = Console.ReadLine(); try { var tree = app.Parser.Parse(line); if (tree == null) { Debug.WriteLine("parse error"); } else { Object.LpObject result = (Object.LpObject)app.Evaluate(tree); if (result == null) { Debug.WriteLine("null"); } else { result.funcall("display", new Object.LpObject[] { }, null); } } } catch (Error.LpError e) { printError(e); } } while (true); }
public static LpObject new_(LpObject self, LpObject[] args, LpObject block = null) { var class_name = args[0].stringValue; if (!classes.ContainsKey(class_name)) { classes[class_name] = create_mold_class(class_name); } LpObject klass = classes[class_name]; if (null != block) { block.funcall("call", block, new LpObject[] { }, null); } klass.methods["new"] = new LpMethod(new BinMethod(initialize), -1); return(klass); }
public static LpObject new_(LpObject self, LpObject[] args, LpObject block = null) { var arg = args[0]; if (!classes.ContainsKey(arg.stringValue)) { LpObject kls = LpClass.initialize().Clone(); kls.class_name = arg.stringValue; classes[arg.stringValue] = kls; } LpObject klass = classes[arg.stringValue]; if (null != block) { //Util.LpIndexer.push(self); block.funcall("call", block, new LpObject[] { }, null); //Util.LpIndexer.pop(); } klass.methods["new"] = new LpMethod(new BinMethod(initialize), -1); return(klass); }
protected static LpObject instance_eval(LpObject self, LpObject[] args, LpObject block = null) { return(block.funcall("call", null, null)); }
static long runTestCode() { /* * Console.WriteLine("benckmark:start"); * System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); * sw.Start(); */ //string code = readFile(argv[0]); //string code = "/* 111 */ 2"; //string code = "1"; //string code = ":aaaa"; //string code = "\"Hello\""; //string code = "true"; //string code = "nl"; //string code = "/regex/"; //string code = "[]"; //string code = "{}"; //string code = "do |a| end"; //string code = "-> do |a| end"; //string code = "a=1"; //string code = "a=1; a"; //string code = "let a=1; a"; //string code = "b? = 2; b?"; //string code = "@a = 3; @a"; //string code = "@@a = 4; @@a"; //string code = "let a"; //string code = "1; 2; 3"; //string code = "a='(1+2); ?a"; //string code = "a='(1+2); `(1+3)"; //string code = "a='(2+3); `(1+?a)"; //string code = "1+a"; //string code = "1+1"; //string code = "2*3"; //string code = "!true"; //string code = "1+2*3+4"; //string code = "1.to_s()"; //string code = "Console"; string code = "Console.WriteLine(\"Hello,World\")"; //string code = "def hoge() end"; //string code = "def hoge(a) 1; 2; 3 end"; //string code = "def hoge(a, b) 1; 2; 3 end"; //string code = "public def hoge(a) 1; 2; 3 end"; //string code = "abc=1+5*5; abc"; //string code = "def bbb(a,b,c) 1; 2; c end; bbb(1,2,3)"; //string code = "class Aaa; 1;2;3 end"; //string code = "public class A; 1;2;3 end"; //string code = "public class A < B; 1;2;3 end"; //string code = "module Aaa; 1;2;3 end"; //string code = "public module Aaa; 1;2;3 end"; //string code = "if true; 1 end"; //string code = "if false; 1 else 2 end"; //string code = "if false; 1 elsif true; 2 end"; //string code = "case 1; end"; //string code = "case false; else 1 end"; //string code = "case 1; when 1; 3 end"; Debug.WriteLine("initialize"); var parser = new Parser.LpGrammer(); //Console.WriteLine("initialize parser"); var language = new LanguageData(parser); //Console.WriteLine("initialize language"); ScriptApp app = new ScriptApp(language); Debug.WriteLine("parse"); var tree = app.Parser.Parse(code); //Console.WriteLine("tree"); //Console.WriteLine(tree); /* * if (tree.HasErrors()) * { * Console.WriteLine(tree.ParserMessages.First().Message); * Console.WriteLine(tree.FileName); * Console.WriteLine(tree.ParserMessages.First().Location); * return 0; * } */ Debug.WriteLine("evaluate"); Object.LpObject result = null; try { result = (Object.LpObject)app.Evaluate(tree); if (result == null) { Debug.WriteLine("null"); } else { Console.WriteLine(result); Console.WriteLine("result: {0}", result); result.funcall("display", new Object.LpObject[] { }, null); } } catch (Error.LpError e) { Console.WriteLine(e.ToString()); } Debug.WriteLine("Finish"); /* * sw.Stop(); * Console.WriteLine(sw.Elapsed.TotalSeconds); * Console.WriteLine("benckmark:end"); */ return(0); }
static LpObject map(LpObject self, LpObject[] args, LpObject block = null) { return(LpArray.initialize(self.arrayValues.Select((v) => block.funcall("call", block, new LpObject[] { v }, null)).ToArray())); }