Cleanup Tuple to allow self-typing.
[rrq/rrqmisc.git] / vector / BindingTable.c
index 7f9d3440ef79e8b679e6873121bfcad8abcc5408..e3ef2147e91bf3ea286546e74a5e104bdf9e0af0 100644 (file)
@@ -117,11 +117,11 @@ void *BindingTable_get(BindingTable *bt,char *name) {
     return 0;
 }
 
-void BindingTable_deref(BindingTable *bt,int arity,tuple *t) {
+void BindingTable_deref(BindingTable *bt,int arity,Tuple *t) {
     int i;
     for ( i = 0; i < arity; i++ ) {
-       if ( (*t)[i] ) {
-           (*t)[i] = BindingTable_get( bt, (*t)[i] );
+       if ( t->elements[i] ) {
+           t->elements[i] = BindingTable_get( bt, t->elements[i] );
        }
     }
 }
@@ -141,16 +141,15 @@ int BindingTable_unify(
 
 #define COPYA(T,P,N) (T*) memcpy( malloc( N * sizeof(T) ), P, N * sizeof( T ) )
 
-tuple *BindingTable_tuple_get(BindingTable *bt,int arity,tuple *t) {
-    tuple *vt = (tuple*) memcpy(
-       malloc( arity * sizeof( void* ) ), t, arity * sizeof( void* ) );
+Tuple *BindingTable_tuple_get(BindingTable *bt,int arity,Tuple *t) {
+    Tuple *vt = Tuple_clone( arity, t );
     BindingTable_deref( bt, arity, vt );
     return vt;
 }
 
-void BindingTable_tuple_set(BindingTable *bt,int arity,tuple *nm,tuple *vs) {
+void BindingTable_tuple_set(BindingTable *bt,int arity,Tuple *nm,Tuple *vs) {
     int i;
     for ( i = 0; i < arity; i++ ) {
-       BindingTable_set( bt, (*nm)[i], (*vs)[i] );
+       BindingTable_set( bt, nm->elements[i], vs->elements[i] );
     }
 }