package org.mozartoz.truffle.runtime;

import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.ObjectType;
import com.oracle.truffle.api.object.Property;

public class RecordObjectType extends ObjectType {

	public static final RecordObjectType INSTANCE = new RecordObjectType();

	@Override
	public String toString(DynamicObject record) {
		Object label = Arity.LABEL_LOCATION.get(record);
		StringBuilder builder = new StringBuilder();
		builder.append(label).append('(');
		for (Property property : record.getShape().getProperties()) {
			Object value = property.get(record, record.getShape());
			builder.append(property.getKey()).append(':').append(value).append(' ');
		}
		builder.setCharAt(builder.length() - 1, ')');
		return builder.toString();
	}

}

@@ -464,16 +464,309 @@
 lder();%0A
+%09%09Arity arity = OzRecord.getArity(record);%0A%0A%09%09if (label == %22#%22 && arity.isTupleArity() && arity.getWidth() %3E= 2) %7B%0A%09%09%09int width = arity.getWidth();%0A%09%09%09for (long i = 1; i %3C= width; i++) %7B%0A%09%09%09%09builder.append(record.get(i));%0A%09%09%09%09if (i != width) %7B%0A%09%09%09%09%09builder.append(%22#%22);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09
 %09%09builde
@@ -794,16 +794,17 @@
 d('(');%0A
+%09
 %09%09for (P
@@ -862,16 +862,17 @@
 )) %7B%0A%09%09%09
+%09
 Object v
@@ -919,16 +919,17 @@
 ape());%0A
+%09
 %09%09%09build
@@ -996,22 +996,24 @@
 d(' ');%0A
+%09
 %09%09%7D%0A%09%09
+%09
 builder.
@@ -1050,16 +1050,21 @@
 , ')');%0A
+%09%09%7D%0A%0A
 %09%09return

Correctly print #-tuples