*** empty log message ***
[m17n/m17n-lib-cs.git] / MExpression.cs
index 959ea1d..560a6b1 100644 (file)
@@ -138,10 +138,13 @@ namespace M17N.Core
       {
        Console.Write ("(" + func.name);
        indent += "  ";
-       foreach (MExpression o in args)
+       foreach (object o in args)
          {
            Console.Write (" ");
-           o.pp (indent);
+           if (o is MExpression)
+             ((MExpression) o).pp (indent);
+           else
+             Console.Write (o);
          }
        Console.Write (")");
       }
@@ -542,7 +545,7 @@ namespace M17N.Core
        Console.Write (")");
       }
 
-      private static object define_function (object[] args, MPlist bindings)
+      public static object define_function (object[] args, MPlist bindings)
       {
        FunctionTable table = (FunctionTable) args[0];
        MSymbol sym = (MSymbol) args[1];
@@ -584,8 +587,30 @@ namespace M17N.Core
 
     public class FunctionTable
     {
-      internal Dictionary<MSymbol, Function> table
-       = new Dictionary<MSymbol, Function> ();
+      internal Dictionary<MSymbol, Function> table;
+
+      public FunctionTable ()
+      {
+       table = new Dictionary<MSymbol, Function> ();
+      }
+
+      public FunctionTable (FunctionTable table)
+      {
+       this.table = new Dictionary<MSymbol, Function> (table.table);
+      }
+
+      public void Copy (FunctionTable table)
+      {
+       foreach (KeyValuePair<MSymbol, Function> kv in this.table)
+         table.table[kv.Key] = kv.Value;
+      }
+
+      public void Copy (MSymbol name, FunctionTable table)
+      {
+       Function func;
+       if (this.table.TryGetValue (name, out func))
+         table.table[name] = func;
+      }
     }
 
     private static FunctionTable basic_table = new FunctionTable ();
@@ -598,19 +623,30 @@ namespace M17N.Core
       table.table[func.name] = func;
     }
 
+    public static void Defmacro (FunctionTable table, MSymbol name,
+                                MExpression expr)
+    {
+      object[] args = new object[4];
+      args[0] = table;
+      args[1] = name;
+      args[2] = new MPlist ();
+      args[3] = expr;
+      Function.define_function (args, null);
+    }
+
     private static Function Defun (string name, Evaluator evaluator,
                                   int min_arg, int max_arg,
                                   params Type[] arg_types)
     {
       MSymbol sym = MSymbol.Of (name);
       Function func = new Function (sym, evaluator, min_arg, max_arg,
-                                     arg_types);
+                                   arg_types);
       basic_table.table[sym] = func;
       return func;
     }
 
     private static Function Defun (string name, Evaluator evaluator,
-                                   int min_arg, int max_arg)
+                                  int min_arg, int max_arg)
     {
       return Defun (name, evaluator, min_arg, max_arg, typeof (MExpression));
     }