summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Term.vala37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/Term.vala b/src/Term.vala
index e0033d6..f2799e9 100644
--- a/src/Term.vala
+++ b/src/Term.vala
@@ -65,13 +65,13 @@ namespace Eva {
case Erl.TermType.SMALL_TUPLE:
case Erl.TermType.LARGE_TUPLE:
assert(Erl.decode_tuple_header(buffer, ref index, out size) == 0);
- Tuple term = new Tuple();
+ Term[] terms = new Term[size];
for(int i = 0; i < size; ++i) {
- term.value.add(do_decode(buffer, ref index));
+ terms[i] = do_decode(buffer, ref index);
}
- return term;
+ return new Tuple(terms);
case Erl.TermType.NIL:
case Erl.TermType.LIST:
@@ -269,18 +269,29 @@ namespace Eva {
}
public class Tuple : Object, Term {
- public Gee.List<Term?> value {get; construct;}
+ private Term[] elements {get; set;}
+
+ public Tuple(Term[] terms) {
+ elements = terms;
+ }
+
+ public int size {
+ get {
+ return elements.length;
+ }
+ }
- public Tuple() {
- Gee.List<Term?> list = new Gee.ArrayList<Term?>();
- Object(value: list);
+ public new unowned Term get(int i) {
+ assert(i >= 0 && i < size);
+
+ return elements[i];
}
public string to_string() {
string ret = "{";
bool first = true;
- foreach(Term term in value) {
+ foreach(Term term in elements) {
if(first) {
first = false;
ret += term.to_string();
@@ -303,11 +314,11 @@ namespace Eva {
Tuple t = o as Tuple;
- if(t.value.size != value.size)
+ if(t.size != size)
return false;
- for(int i = 0; i < value.size; ++i) {
- if(!value[i].do_match(t.value[i], vars, aliases))
+ for(int i = 0; i < size; ++i) {
+ if(!this[i].do_match(t[i], vars, aliases))
return false;
}
@@ -315,9 +326,9 @@ namespace Eva {
}
public void encode(Erl.Buffer buffer) {
- buffer.encode_tuple_header(value.size);
+ buffer.encode_tuple_header(size);
- foreach(Term term in value) {
+ foreach(Term term in elements) {
term.encode(buffer);
}
}