internal delegate void PrettyPrinter (Function func,
string indent, object[] args);
+ public enum ArgType
+ {
+ FIXED,
+ MANY,
+ UNEVALLED,
+ };
+
internal class Function
{
internal readonly MSymbol name;
internal readonly Evaluator eval;
internal readonly int min_arg;
- internal readonly int max_arg;
- internal readonly Type[] arg_types;
+ internal readonly ArgType arg_type;
internal object[] data;
public PrettyPrinter pp;
internal static Function literal, varref, block, defun;
public Function (MSymbol name, Evaluator eval,
- int min_arg, int max_arg, params Type[] arg_types)
+ int min_arg, enum ArgType arg_type)
{
this.name = name;
this.eval = eval;
this.min_arg = min_arg;
- this.max_arg = max_arg;
- this.arg_types = (Type []) arg_types.Clone ();
- if (arg_types.Length == 2 && arg_types[0] == typeof (MSymbol))
+ this.arg_type = arg_type;
+ if (min_arg == 2 && arg_type = ArgType.FIXED)
pp = set_pretty_printer;
else
pp = default_pretty_printer;
private static FunctionTable basic_table = new FunctionTable ();
public static void Defun (FunctionTable table, string name,
- Evaluator evaluator, int min_arg, int max_arg,
- params Type[] arg_types)
+ Evaluator evaluator, int min_arg,
+ enum ArgType arg_type)
{
- Function func = Defun (name, evaluator, min_arg, max_arg, arg_types);
+ Function func = Defun (name, evaluator, min_arg, arg_type);
table.table[func.name] = func;
}
}
private static Function Defun (string name, Evaluator evaluator,
- int min_arg, int max_arg,
- params Type[] arg_types)
+ int min_arg, enum ArgType arg_type)
{
MSymbol sym = MSymbol.Of (name);
- Function func = new Function (sym, evaluator, min_arg, max_arg,
- arg_types);
+ Function func = new Function (sym, evaluator, min_arg, arg_type);
basic_table.table[sym] = func;
return func;
}
private static Function Defun (string name, Evaluator evaluator,
- int min_arg, int max_arg)
+ int min_arg, enum ArgType arg_type)
{
- return Defun (name, evaluator, min_arg, max_arg, typeof (MExpression));
+ return Defun (name, evaluator, min_arg, arg_type, typeof (MExpression));
}
private static Function Find (MSymbol name, FunctionTable table)
return func;
}
- private void invalid_expression (object o)
+ private static void invalid_expression (object o)
{
throw new Exception ("Invalid expresssion: " + o);
}
this.args = (object[]) args.Clone ();
}
- private MExpression[] expression_list (MPlist plist, FunctionTable table)
+ private static MExpression[] expression_list (MPlist plist,
+ FunctionTable table)
{
int len = plist.Count;
MExpression[] expr_list = new MExpression[len];
}
}
- private static void regulalize_command (MPlist plist)
- {
- if (plist.IsSymbol)
- {
- MSymbol sym = plist.Symbol;
-
- if (sym == MSymbol.Of ("add"))
- plist.val = MSymbol.Of ("+=");
- regulalize_actions (plist.next);
- }
- }
-
- private static void regulalize_actions (MPlist plist)
- {
- for (; ! plist.IsEmpty; plist = plist.next)
- {
- if (plist.IsMText)
- {
- MText mt = plist.Text;
- MPlist p = new MPlist ();
- p.Add (MSymbol.symbol, Minsert);
- p.Add (MSymbol.mtext, mt);
- plist.key = MSymbol.plist;
- plist.val = p;
- }
- else if (plist.IsInteger)
- {
- int c = plist.Integer;
- MPlist p = new MPlist ();
- p.Add (MSymbol.symbol, Minsert);
- p.Add (MSymbol.integer, c);
- plist.key = MSymbol.plist;
- plist.val = p;
- }
- else if (plist.IsPlist)
- {
-
- }
- }
- }
-
private void parse_maps (MPlist plist)
{
for (; ! plist.IsEmpty; plist = plist.next)
p = p.next;
if (p.IsEmpty)
continue;
- regulalize_actions (p);
MExpression expr = new MExpression (p, local_table);
map.Add (keys, 0, expr);
}
continue;
MSymbol map_name = p.Symbol;
p = p.next;
- if (! p.IsEmpty)
- regulalize_actions (p);
- state.branches[map_name]
- = new MExpression (p, local_table);
+ state.branches[map_name] = new MExpression (p, local_table);
}
}
}