From: handa Date: Thu, 17 Sep 2009 00:12:40 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd5dc7564e13dcc267d5f2513664b5d36e28074a;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/XmlExpr.cs b/XmlExpr.cs index 7d6cec1..947d326 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -10,12 +10,6 @@ namespace System.Xml.Expression { public static bool Debug = false; - public static void DebugWrite (string fmt, params object[] arg) - { - if (Debug) - Console.Write (fmt, arg); - } - public struct Name : IEquatable { private static NameTable nt = new NameTable (); @@ -150,17 +144,14 @@ namespace System.Xml.Expression for (int i = 0; i < args.Length; i++) { - object val = ((Xex) args[i]).Eval (domain); + object val = args[i]; + if (val is Xex) + val = ((Xex) val).Eval (domain); if (val == null) throw new Exception (args[i] + ":evaled to null"); args[i] = val; } - DebugWrite ("calling (" + this); - foreach (object a in args) - DebugWrite (" " + a); - DebugWrite (") => "); result = builtin (args, domain); - DebugWrite (result + "\n"); return result; } } @@ -178,15 +169,7 @@ namespace System.Xml.Expression public override object Call (object[] args, Domain domain) { - object result; - - DebugWrite ("calling (" + this); - foreach (object a in args) - DebugWrite (" " + a); - DebugWrite (") => "); - result = builtin (args, domain); - DebugWrite (result + "\n"); - return result; + return builtin (args, domain); } } @@ -268,10 +251,8 @@ namespace System.Xml.Expression Variable var = domain.GetVar (this.args[i]); domain.Bind (var, args[i]); } - DebugWrite ("calling (" + this); foreach (Xex e in body) result = e.Eval (domain); - DebugWrite (") => " + result + "\n"); } finally { domain.UnboundTo (current); } @@ -315,7 +296,7 @@ namespace System.Xml.Expression public abstract bool ValueP (object value); - public override string ToString () { return name + "=" + val; } + public override string ToString () { return name + "(" + val + ")"; } } internal class VarInt : Variable @@ -415,7 +396,7 @@ namespace System.Xml.Expression internal Bindings UnboundTo (Bindings boundary) { for (Bindings b = this; b != boundary; b = b.next) - vari.val = b.old_value; + b.vari.val = b.old_value; return boundary; } @@ -445,6 +426,7 @@ namespace System.Xml.Expression public class Domain { public object context; + public int depth = 0; internal Dictionary functions; internal Dictionary variables; @@ -470,7 +452,6 @@ namespace System.Xml.Expression internal void Bind (Variable vari, object value) { bindings = Bindings.Bind (bindings, vari, value); - DebugWrite ("binding " + vari); } internal void UnboundTo (Bindings boundary) @@ -630,6 +611,20 @@ namespace System.Xml.Expression str += ">"; return str; } + + public void DebugWrite (bool head, string fmt, params object[] arg) + { + if (Debug) + { + if (head) + { + Console.WriteLine (); + for (int i = 0; i < depth; i++) + Console.Write (" "); + } + Console.Write (fmt, arg); + } + } } public delegate object Builtin (object[] args, Domain domain); @@ -1038,9 +1033,18 @@ namespace System.Xml.Expression public override object Eval (Domain domain) { + domain.DebugWrite (true, "(({0}", func); for (int i = 0; i < args.Length; i++) - real_args[i] = args[i]; - return func.Call (real_args, domain); + { + domain.DebugWrite (false, " {0}", args[i]); + real_args[i] = args[i]; + } + domain.DebugWrite (false, ")"); + domain.depth += 2; + object result = func.Call (real_args, domain); + domain.depth -= 2; + domain.DebugWrite (true, " => {0})", result); + return result; } public override Name TypeOf { get { return Nfuncall; } } @@ -1063,6 +1067,7 @@ namespace System.Xml.Expression public override object Eval (Domain domain) { + domain.DebugWrite (true, "(get-value {0})", vari); return vari.val; } @@ -1080,7 +1085,11 @@ namespace System.Xml.Expression public Const (object val) { this.val = val; } - public override object Eval (Domain domain) { return val; } + public override object Eval (Domain domain) + { + domain.DebugWrite (true, "(const {0})\n", val); + return val; + } public override Name TypeOf { get diff --git a/xex.cs b/xex.cs index 30b0c8a..2afa166 100644 --- a/xex.cs +++ b/xex.cs @@ -13,5 +13,6 @@ public class Test Xex.Debug = true; Console.WriteLine (xex.Eval (domain)); + Console.WriteLine (domain); } }