From: handa Date: Tue, 15 Sep 2009 09:28:39 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=c3ac31d76f0ec73cf72908e4369c95d21c3d3a57;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/XmlExpr.cs b/XmlExpr.cs index 2338fb1..f72a72e 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -115,22 +115,11 @@ namespace System.Xml.Expression this.max_arg = max_arg; } - public virtual object Call (Xex[] args, Domain domain) - { - object result; - - Console.Write ("calling (" + this); - foreach (Xex a in args) - Console.Write (" " + a); - Console.Write (") => "); - result = builtin (args, domain); - Console.WriteLine (result); - return result; - } + public abstract object Call (Xex[] args, Domain domain); public override string ToString () { - return str; + return name; } internal class Subroutine : Function @@ -146,10 +135,18 @@ namespace System.Xml.Expression public override object Call (Xex[] args, Domain domain) { + object result; + foreach (Xex a in args) if (a.Eval (domain) == null) throw new Exception (a + ":evaled to null"); - return base.Call (args, domain); + Console.Write ("calling (" + this); + foreach (Xex a in args) + Console.Write (" " + a); + Console.Write (") => "); + result = builtin (args, domain); + Console.WriteLine (result); + return result; } } @@ -166,6 +163,15 @@ namespace System.Xml.Expression public override object Call (Xex[] args, Domain domain) { + object result; + + Console.Write ("calling (" + this); + foreach (Xex a in args) + Console.Write (" " + a); + Console.Write (") => "); + result = builtin (args, domain); + Console.WriteLine (result); + return result; } } @@ -199,7 +205,6 @@ namespace System.Xml.Expression public void Setup (XmlNode node, Domain domain) { - lambda = new Lambda (); node = node.FirstChild; if (node.Name == Nargs) { @@ -210,36 +215,6 @@ namespace System.Xml.Expression SetBody (node, domain); } - public static Name ParseHead (XmlNode node, - out int min_arg, out int max_arg) - { - Name name = node.Attributes[Nfname].Value; - int nargs = 0, noptions = 0, nrest = 0; - XmlNode n; - - for (n = node.FirstChild; n != null; n = n.NextSibling) - { - if (n.Name == Noptional || n.Name == Nrest) - break; - nargs++; - } - if (n != null && n.Name == Noptional) - for (n = n.NextSibling; n != null; n = n.NextSibling) - { - if (n.Name == Nrest) - break; - noptions++; - } - if (n != null && n.Name == Nrest) - for (n = n.NextSibling; n != null; n = n.NextSibling) - nrest++; - min_arg = nargs; - max_arg = nargs + noptions + nrest; - if (nrest == 1) - max_arg = - max_arg; - return name; - } - public override object Call (Xex[] args, Domain domain) { Bindings current = domain.bindings; @@ -272,10 +247,10 @@ namespace System.Xml.Expression public override string ToString () { - str = "(" + name; + string str = "(" + name; foreach (Xex a in args) str += " " + a; - str += ")"; + return (str + ")"); } } } @@ -487,14 +462,44 @@ namespace System.Xml.Expression = new Function.SpecialForm (builtin, name, min_arg, max_arg); } + private static Name ParseHead (XmlNode node, + out int min_arg, out int max_arg) + { + Name name = node.Attributes[Nfname].Value; + int nargs = 0, noptions = 0, nrest = 0; + XmlNode n; + + for (n = node.FirstChild; n != null; n = n.NextSibling) + { + if (n.Name == Noptional || n.Name == Nrest) + break; + nargs++; + } + if (n != null && n.Name == Noptional) + for (n = n.NextSibling; n != null; n = n.NextSibling) + { + if (n.Name == Nrest) + break; + noptions++; + } + if (n != null && n.Name == Nrest) + for (n = n.NextSibling; n != null; n = n.NextSibling) + nrest++; + min_arg = nargs; + max_arg = nargs + noptions + nrest; + if (nrest == 1) + max_arg = - max_arg; + return name; + } + internal Function.Lambda RegisterFunction (XmlNode node) { int min_arg, max_arg; - Name name = Function.ParseHead (node, out min_arg, out max_arg); - Lambda lambda = new Function.Lambda (name, min_arg, max_arg); + Name name = ParseHead (node, out min_arg, out max_arg); + Function.Lambda lambda = new Function.Lambda (name, min_arg, max_arg); functions[name] = lambda; - return func; + return lambda; } internal Function Defun (XmlNode node)