// static KMETHOD ParseStmt_Block(CTX, ksfp_t *sfp _RIX) private static int ParseStmt_Block(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e) { //Console.WriteLine("ParseStmt_Block name:" + name.Name); Token tk = tls[s]; if(tk.Type == TokenType.CODE) { stmt.map.Add(name, new CodeExpr(tk)); return s + 1; } var parser = new Parser(ctx, stmt.ks); if (tk.Type == TokenType.AST_BRACE) { BlockExpr bk = parser.CreateBlock(stmt, tk.Sub, 0, tk.Sub.Count, ';'); stmt.map.Add(name, bk); return s + 1; } else { BlockExpr bk = parser.CreateBlock(stmt, tls, s, e, ';'); stmt.map.Add(name, bk); return e; } }
// static KMETHOD ParseStmt_Params(CTX, ksfp_t *sfp _RIX) private static int ParseStmt_Params(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tokens, int s, int e) { int r = -1; Token tk = tokens[s]; if (tk.Type == TokenType.AST_PARENTHESIS) { var tls = tk.Sub; int ss = 0; int ee = tls.Count; if (0 < ee && tls[0].Keyword == KeywordType.Void) ss = 1; // f(void) = > f() BlockExpr bk = new Parser(ctx, stmt.ks).CreateBlock(stmt, tls, ss, ee, ','); stmt.map.Add(name, bk); r = s + 1; } return r; }
// static kstatus_t KonohaSpace_eval(CTX, kKonohaSpace *ks, const char *script, kline_t uline) public dynamic Eval(string script) { var tokens = tokenize(script); var parser = new Parser(ctx, this); var converter = new Converter(ctx, this); var block = parser.CreateBlock(null, tokens, 0, tokens.Count(), ';'); dynamic ast = converter.Convert(block); string dbv = typeof(Expression).InvokeMember("DebugView", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty, null, ast, null); Console.WriteLine("### DLR AST Dump ###"); Console.WriteLine(dbv); var f = ast.Compile(); return f(); }