diff options
-rw-r--r-- | src/Ref.vala | 13 | ||||
-rw-r--r-- | src/Term.vala | 2 | ||||
-rw-r--r-- | src/Util.vala | 2 | ||||
-rw-r--r-- | src/Var.vala | 10 |
4 files changed, 19 insertions, 8 deletions
diff --git a/src/Ref.vala b/src/Ref.vala index b1fd4e9..17ae2cf 100644 --- a/src/Ref.vala +++ b/src/Ref.vala @@ -1,5 +1,5 @@ namespace Eva { - public class Ref : Object, Term { + public class Ref : Object, Term, Gee.Comparable<Ref> { public string node {get; construct;} public int len {get; construct;} public uint[] n {get; private set;} @@ -22,6 +22,17 @@ namespace Eva { return "#Ref"; } + public int compare_to(Ref o) { + for(int i = 0; i < len; ++i) { + if(n[i] < o.n[i]) + return -1; + if(n[i] > o.n[i]) + return 1; + } + + return 0; + } + protected bool do_match(Term o, Gee.Map<string, Term> vars, Gee.Map<string, string> aliases) { if(o is Var) { return o.do_match(this, vars, aliases); diff --git a/src/Term.vala b/src/Term.vala index 4b1215d..5c1c968 100644 --- a/src/Term.vala +++ b/src/Term.vala @@ -16,7 +16,7 @@ namespace Eva { foreach(string a in aliases.keys) { string v = Var.alias(a, aliases); - if(v in vars) + if(v in vars.keys) vars[a] = vars[v]; } diff --git a/src/Util.vala b/src/Util.vala index e840a07..b33cb5f 100644 --- a/src/Util.vala +++ b/src/Util.vala @@ -16,7 +16,7 @@ namespace Eva { } private char[]? string_to_binary(string str) { - char[] ret = new char[str.len()]; + char[] ret = new char[str.length]; int index = 0; for(unowned string rest = str; rest.length > 0; rest = rest.next_char()) { diff --git a/src/Var.vala b/src/Var.vala index eb44637..177e2fa 100644 --- a/src/Var.vala +++ b/src/Var.vala @@ -13,7 +13,7 @@ namespace Eva { } internal static string alias(string key, Gee.Map<string, string> aliases) { - if(!(key in aliases)) + if(!(key in aliases.keys)) return key; else return alias(aliases[key], aliases); @@ -37,19 +37,19 @@ namespace Eva { if(key == vkey) return true; - if(key in vars && vkey in vars) + if(key in vars.keys && vkey in vars.keys) return vars[key].do_match(vars[vkey], vars, aliases); - else if(!(vkey in vars)) { + else if(!(vkey in vars.keys)) { aliases[vkey] = key; return true; } - else /* !(key in vars) */ { + else /* !(key in vars.keys) */ { aliases[key] = vkey; return true; } } else { - if(key in vars) { + if(key in vars.keys) { return vars[key].do_match(o, vars, aliases); } else { |