+void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyList &props) {
+ const TypeDescription &td(TypeDescription::Get(typeId));
+ for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
+ const FieldDescription &fd(td.GetField(i->first));
+ const TypeDescription &fieldType(TypeDescription::Get(fd.TypeId()));
+ if (CanLink(*i->second)) {
+ char *dest(object + fd.Offset());
+ if (fd.IsAggregate()) {
+ int arraySize(i->second->GetLiteral().ArraySize());
+ char *aggregate(alloc.Alloc(fieldType.Size() * arraySize));
+ char *iter(aggregate);
+ if (i->second->GetLiteral().GetType() == Literal::ARRAY_PROPS) {
+ const vector<PropertyList *> &list(i->second->GetLiteral().GetPropertyLists());
+ for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
+ fieldType.Construct(iter);
+ ReadObject(fieldType.TypeId(), -1, iter, **j);
+ }
+ } else {
+ const vector<Value *> &list(i->second->GetLiteral().GetValues());
+ for (vector<Value *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
+ fieldType.Construct(iter);
+ ReadLiteral(fieldType.TypeId(), -1, iter, (*j)->GetLiteral());
+ }
+ }
+ if (fd.IsReferenced()) {
+ std::memcpy(dest, &aggregate, sizeof(char *));
+ dest += sizeof(char *);
+ std::memcpy(dest, &arraySize, sizeof(int));
+ } else {
+ throw Error("aggregate type fields must be referenced");
+ }
+ } else if (i->second->IsLiteral() && !fd.IsReferenced()) {
+ // inline literals
+ if (i->second->GetLiteral().IsObject()) {
+ ReadObject(fd.TypeId(), -1, dest, *i->second->GetLiteral().GetProperties());
+ } else {
+ ReadLiteral(fd.TypeId(), -1, dest, i->second->GetLiteral());
+ }
+ } else {
+ char *src(reinterpret_cast<char *>(GetObject(fd.TypeId(), *i->second)));
+ if (fd.TypeId() == TypeDescription::GetTypeId("Image")) {
+ src = reinterpret_cast<char *>(GetImage(src));
+ }
+ if (fd.IsReferenced()) {
+ std::memcpy(dest, &src, sizeof(char *));
+ } else {
+ std::memcpy(dest, src, fieldType.Size());
+ }
+ }
+ } else {
+ Postpone(typeId, id, fd.Offset(), i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced());
+ }