diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-10 01:23:07 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-10 01:23:07 +0200 |
commit | f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a (patch) | |
tree | ded56a166ef4648061379bab6c65bc40e5d01f8d /src/Ref.vala | |
parent | 2fc49125e73554d68b4ee8874b9f84725b6f2157 (diff) | |
download | eva-f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a.tar eva-f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a.zip |
Split Term code to individual class sources
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); + } + } +} |