Index: uspace/app/sbi/src/rdata.c
===================================================================
--- uspace/app/sbi/src/rdata.c	(revision 1ebc1a62b0e759c001488fc0e221be6347082167)
+++ uspace/app/sbi/src/rdata.c	(revision 23de644e12ee218601dd193540374b779a6364d7)
@@ -27,8 +27,26 @@
  */
 
-/** @file Run-time data representation. */
+/** @file Run-time data representation.
+ *
+ * At run time SBI represents all data as a graph of interconnected @c var
+ * nodes (variable nodes). Any piece of memory addressable by the program
+ * (i.e. all variables) are stored in var nodes. However, var nodes are also
+ * used internally to implement value items. (I.e. values in value items
+ * have exactly the same structure as program variables).
+ *
+ * Unlike byte- or word-oriented memory on a real machine, var nodes provide
+ * structured and typed storage. (This typing is dynamic, however and has
+ * nothing to do with the static type system).
+ *
+ * There are several types of var nodes, one for each primitive type,
+ * reference, delegate, array, and object. A reference var node contains
+ * a pointer to another var node. Delegate var node points to some stree
+ * declaration. Array and object var nodes refer to a collection of child
+ * nodes (fields, elements).
+ */
 
 #include <stdlib.h>
 #include <assert.h>
+#include "bigint.h"
 #include "mytypes.h"
 #include "stree.h"
@@ -50,5 +68,9 @@
 static void rdata_var_print(rdata_var_t *var);
 
-
+/** Allocate new data item.
+ *
+ * @param ic	Item class.
+ * @return	New item.
+ */
 rdata_item_t *rdata_item_new(item_class_t ic)
 {
@@ -65,4 +87,8 @@
 }
 
+/** Allocate new address.
+ *
+ * @return	New address.
+ */
 rdata_addr_var_t *rdata_addr_var_new(void)
 {
@@ -78,4 +104,8 @@
 }
 
+/** Allocate new named property address.
+ *
+ * @return	New named property address.
+ */
 rdata_aprop_named_t *rdata_aprop_named_new(void)
 {
@@ -91,4 +121,8 @@
 }
 
+/** Allocate new indexed property address.
+ *
+ * @return	New indexed property address.
+ */
 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
 {
@@ -104,4 +138,9 @@
 }
 
+/** Allocate new property address.
+ *
+ * @param apc	Property address class.
+ * @return	New property address.
+ */
 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
 {
@@ -118,4 +157,9 @@
 }
 
+/** Allocate new address.
+ *
+ * @param ac	Address class.
+ * @return	New address.
+ */
 rdata_address_t *rdata_address_new(address_class_t ac)
 {
@@ -132,4 +176,8 @@
 }
 
+/** Allocate new value.
+ *
+ * @return	New value.
+ */
 rdata_value_t *rdata_value_new(void)
 {
@@ -145,4 +193,9 @@
 }
 
+/** Allocate new var node.
+ *
+ * @param vc	Var node class (varclass).
+ * @return	New var node.
+ */
 rdata_var_t *rdata_var_new(var_class_t vc)
 {
@@ -159,4 +212,8 @@
 }
 
+/** Allocate new reference.
+ *
+ * @return	New reference.
+ */
 rdata_ref_t *rdata_ref_new(void)
 {
@@ -172,4 +229,8 @@
 }
 
+/** Allocate new delegate.
+ *
+ * @return	New delegate.
+ */
 rdata_deleg_t *rdata_deleg_new(void)
 {
@@ -185,4 +246,8 @@
 }
 
+/** Allocate new array.
+ *
+ * @return	New array.
+ */
 rdata_array_t *rdata_array_new(int rank)
 {
@@ -205,4 +270,8 @@
 }
 
+/** Allocate new object.
+ *
+ * @return	New object.
+ */
 rdata_object_t *rdata_object_new(void)
 {
@@ -218,4 +287,8 @@
 }
 
+/** Allocate new integer.
+ *
+ * @return	New integer.
+ */
 rdata_int_t *rdata_int_new(void)
 {
@@ -231,4 +304,8 @@
 }
 
+/** Allocate new string.
+ *
+ * @return	New string.
+ */
 rdata_string_t *rdata_string_new(void)
 {
@@ -244,4 +321,8 @@
 }
 
+/** Allocate new resource.
+ *
+ * @return	New resource.
+ */
 rdata_resource_t *rdata_resource_new(void)
 {
@@ -257,4 +338,10 @@
 }
 
+/** Allocate array elements.
+ *
+ * Allocates var nodes for elements of @a array.
+ *
+ * @param array		Array.
+ */
 void rdata_array_alloc_element(rdata_array_t *array)
 {
@@ -282,4 +369,6 @@
  * Dimension is the total number of elements in an array, in other words,
  * the product of all extents.
+ *
+ * @param array		Array.
  */
 static int rdata_array_get_dim(rdata_array_t *array)
@@ -294,5 +383,12 @@
 }
 
-/** Make copy of a variable. */
+/** Make copy of a variable.
+ *
+ * Creates a new var node that is an exact copy of an existing var node.
+ * This can be thought of as a shallow copy.
+ *
+ * @param src		Source var node.
+ * @param dest		Place to store pointer to new var node.
+ */
 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
 {
@@ -328,10 +424,20 @@
 }
 
+/** Copy integer.
+ *
+ * @param src		Source integer.
+ * @param dest		Place to store pointer to new integer.
+ */
 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
 {
 	*dest = rdata_int_new();
-	(*dest)->value = src->value;
-}
-
+	bigint_clone(&src->value, &(*dest)->value);
+}
+
+/** Copy string.
+ *
+ * @param src		Source string.
+ * @param dest		Place to store pointer to new string.
+ */
 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
 {
@@ -340,4 +446,9 @@
 }
 
+/** Copy reference.
+ *
+ * @param src		Source reference.
+ * @param dest		Place to store pointer to new reference.
+ */
 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
 {
@@ -346,4 +457,9 @@
 }
 
+/** Copy delegate.
+ *
+ * @param src		Source delegate.
+ * @param dest		Place to store pointer to new delegate.
+ */
 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
 {
@@ -353,4 +469,9 @@
 }
 
+/** Copy array.
+ *
+ * @param src		Source array.
+ * @param dest		Place to store pointer to new array.
+ */
 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
 {
@@ -360,4 +481,9 @@
 }
 
+/** Copy object.
+ *
+ * @param src		Source object.
+ * @param dest		Place to store pointer to new object.
+ */
 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
 {
@@ -367,4 +493,9 @@
 }
 
+/** Copy resource.
+ *
+ * @param src		Source resource.
+ * @param dest		Place to store pointer to new resource.
+ */
 static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
 {
@@ -375,5 +506,12 @@
 /** Read data from a variable.
  *
- * Return value stored in variable @a var.
+ * This copies data from the variable to a value item. Ideally any read access
+ * to a program variable should go through this function. (Keep in mind
+ * that although values are composed of var nodes internally, but are not
+ * variables per se. Therefore this function is not used to read from values)
+ *
+ * @param var		Variable to read from (var node where it is stored).
+ * @param ritem		Place to store pointer to new value item read from
+ *			the variable.
  */
 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
@@ -393,5 +531,11 @@
 /** Write data to a variable.
  *
- * Store @a value to variable @a var.
+ * This copies data to the variable from a value. Ideally any write access
+ * to a program variable should go through this function. (Keep in mind
+ * that even though values are composed of var nodes internally, but are not
+ * variables per se. Therefore this function is not used to write to values)
+ *
+ * @param var		Variable to write to (var node where it is stored).
+ * @param value		The value to write.
  */
 void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
@@ -418,4 +562,8 @@
 }
 
+/** Print data item in human-readable form.
+ *
+ * @param item		Item to print.
+ */
 void rdata_item_print(rdata_item_t *item)
 {
@@ -437,4 +585,13 @@
 }
 
+/** Print address in human-readable form.
+ *
+ * Actually this displays contents of the var node that is being addressed.
+ *
+ * XXX Maybe we should really rather print the address and not the data
+ * it is pointing to?
+ *
+ * @param item		Address to print.
+ */
 static void rdata_address_print(rdata_address_t *address)
 {
@@ -449,4 +606,8 @@
 }
 
+/** Print value in human-readable form.
+ *
+ * @param value		Value to print.
+ */
 void rdata_value_print(rdata_value_t *value)
 {
@@ -454,9 +615,15 @@
 }
 
+/** Print contents of var node in human-readable form.
+ *
+ * @param item		Var node to print.
+ */
 static void rdata_var_print(rdata_var_t *var)
 {
 	switch (var->vc) {
 	case vc_int:
-		printf("int(%d)", var->u.int_v->value);
+		printf("int(");
+		bigint_print(&var->u.int_v->value);
+		printf(")");
 		break;
 	case vc_string:
