public static Symbol UncaughtThrow = "uncaught-throw";
private readonly Symbol name;
- private Term term = Zero;
+ private Term[] stack;
private XmlNode node;
public Error (Symbol name, XmlNode node, string fmt, params object[] args)
this.name = name;
}
- public Symbol ErrorName { get { return name; } }
- public XmlNode ErrorNode { get { return node; } set { node = value; } }
- public Term ErrorTerm { get { return term; } set { term = value; } }
+ public Symbol Name { get { return name; } }
+ public XmlNode Node {
+ get { return node; }
+ internal set { node = value; }
+ }
+ public Term[] Stack {
+ get { return stack; }
+ internal set { stack = value; }
+ }
}
public struct Symbol : IEquatable<Symbol>
Term result = Zero;
int limit = max_args >= 0 ? args.Length : args.Length - 1;
- for (int i = 0; i < limit; i++)
- {
- result = args[i].Eval (domain);
- if (domain.Thrown)
- return result;
- domain.Bind (this.args[i], result);
- }
- if (max_args < 0)
- {
- List<Term> list = new List<Term> ();
- list.InsertRange (0, args[result].Listval);
-
- for (int i = 0; i < list.Count; i++)
+ try {
+ for (int i = 0; i < limit; i++)
+ {
+ result = args[i].Eval (domain);
+ if (domain.Thrown)
+ return result;
+ domain.Bind (this.args[i], result);
+ }
+ if (max_args < 0)
+ {
+ List<Term> list = new List<Term> ();
+ list.InsertRange (0, args[result].Listval);
+
+ for (int i = 0; i < list.Count; i++)
+ {
+ result = list[i].Eval (domain);
+ if (domain.Thrown)
+ return result;
+ list[i] = result;
+ }
+ domain.Bind (this.args[limit], new Term (list));
+ }
+ try {
+ domain.Catch (CatchTag.Return);
+ foreach (Term term in body)
{
- result = list[i].Eval (domain);
- if (domain.Thrown)
+ result = term.Eval (domain);
+ if (domain.Thrown ())
return result;
- list[i] = result;
}
- domain.Bind (this.args[limit], new Term (list));
- }
- domain.Catch (CatchTag.Return);
- foreach (Term term in body)
- {
- result = term.Eval (domain);
- if (domain.Thrown ())
- return result;
+ } finally {
+ domain.Uncatch ();
}
- domain.Uncatch ();
- domain.UnboundTo (current);
+ } finally {
+ domain.UnboundTo (current);
+ }
return result;
}
}
Bindings current = domain.bindings;
Term result = Zero;
- for (int i = 0; i < args.Length; i++)
- domain.Bind (this.args[i], args[i]);
- domain.Catch (CatchTag.Return);
- foreach (Term term in body)
- {
- result = term.Eval (domain);
- if (domain.Thrown ())
- break;
+ try {
+ for (int i = 0; i < args.Length; i++)
+ domain.Bind (this.args[i], args[i]);
+ try {
+ domain.Catch (CatchTag.Return);
+ foreach (Term term in body)
+ {
+ result = term.Eval (domain);
+ if (domain.Thrown ())
+ break;
+ }
+ } finally {
+ domain.Uncatch ();
}
- domain.Uncatch ();
- domain.UnboundTo (current);
+ } finally {
+ domain.UnboundTo (current);
+ }
return result;
}
}
private static Term Fset (Domain domain, Variable vari, Term[] args)
{
if (vari == null)
- return new Term (new ErrorTerm (Error.NoVariableName,
- "No variable name to set"));
+ throw new Error (Error.NoVariableName, "No variable name to set"));
vari.SetValue (args[0]);
return args[0];
}
return new ErrorTerm (ename, message);
}
- public Term[] CallStack { get { return stack; } set { stack = value; } }
+ public Term[] CallStack {
+ get { return stack; }
+ internal set { stack = value; }
+ }
public override TermValue Clone ()
{
public override bool Equals (object obj)
{
ErrorTerm e = obj as ErrorTerm;
- if (e == null || e.ename != ename || e.message != message
- || (e.stack == null ? stack != null
- : (stack == null || e.stack.Length != stack.Length)))
- return false;
- if (stack != null)
- for (int i = 0; i < stack.Length; i++)
- if (! stack[i].Equals (e.stack[i]))
- return false;
- return true;
+ return (e != null && e.ename = ename && e.message != message
+ && (e.stack == null ? stack == null
+ : (stack != null && e.stack.Length == stack.Length)))
}
public override int GetHashCode ()