diff options
Diffstat (limited to 'src/Ref.vala')
-rw-r--r-- | src/Ref.vala | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/Ref.vala b/src/Ref.vala new file mode 100644 index 0000000..2510d78 --- /dev/null +++ b/src/Ref.vala @@ -0,0 +1,66 @@ +namespace Eva { + public class Ref : Object, Term { + public string node {get; construct;} + public int len {get; construct;} + public uint[] n {get; private set;} + public uint creation {get; construct;} + + public Ref(Erl.Ref reference) { + this.create(array_to_string(reference.node, Erl.MAXATOMLEN), reference.len, reference.n, reference.creation); + } + + private Ref.create(string node0, int len0, uint* n0, uint creation0) { + Object(node: node0, len: len0, creation: creation0); + + n = new uint[len]; + for(int i = 0; i < len; ++i) { + n[i] = n0[i]; + } + } + + public string to_string() { + return "#Ref"; + } + + 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); + } + + if(!(o is Ref)) + return false; + + Ref r = o as Ref; + + if(node != r.node || len != r.len || creation != r.creation) { + return false; + } + + for(int i = 0; i < len; ++i) { + if(n[i] != r.n[i]) + return false; + } + + return true; + } + + public void encode(Erl.Buffer buffer) { + Erl.Ref reference = Erl.Ref(); + char[]? nodedata = string_to_array(node); + assert(nodedata != null); + + Memory.copy(reference.node, nodedata, int.min(Erl.MAXATOMLEN, nodedata.length)); + reference.node[int.min(Erl.MAXATOMLEN, nodedata.length)] = 0; + + reference.len = len; + + for(int i = 0; i < len; ++i) { + reference.n[i] = n[i]; + } + + reference.creation = creation; + + buffer.encode_ref(reference); + } + } +} |