static cDict *unpack_dict(cBuf *buf, Long *buf_pos) { cDict *dict; cList *keys, *values; Int i; keys = unpack_list(buf, buf_pos); values = unpack_list(buf, buf_pos); if (keys->len <= 64) { dict = dict_new(keys, values); list_discard(keys); list_discard(values); return dict; } else { dict = EMALLOC(cDict, 1); dict->keys = keys; dict->values = values; dict->hashtab_size = read_long(buf, buf_pos); dict->links = EMALLOC(Int, dict->hashtab_size); dict->hashtab = EMALLOC(Int, dict->hashtab_size); for (i = 0; i < dict->hashtab_size; i++) { dict->links[i] = read_long(buf, buf_pos); dict->hashtab[i] = read_long(buf, buf_pos); } dict->refs = 1; return dict; } }
void unpack_object(cBuf *buf, Long *buf_pos, Obj *obj) { obj->parents = unpack_list(buf, buf_pos); obj->children = unpack_list(buf, buf_pos); unpack_vars(buf, buf_pos, obj); unpack_methods(buf, buf_pos, obj); obj->objname = read_ident(buf, buf_pos); }
void pretty_print(const type_declaration_class klass) { // Get the info struct class_declaration info = klass.type; // Print final, if we are if(info.is_final) { std::cout << "final "; } // Print abstract, if we are if(info.is_abstract) { std::cout << "abstract "; } // Print the 'class' keyword, the class name, and the class we extend // (in non inheriting classes this will be java.lang.Object). std::cout << "class " << info.name.identifier_string << " extends " << name_to_string(info.extends); // If we're implementing anything if(info.implements.empty() == false) { // Then write out the 'implements' keyword, and a comma seperated // list of implements std::cout << " implements "; std::cout << concat(info.implements, name_to_string, ", "); } // Newline because we like allman style std::cout << std::endl; // Start brace, and newline std::cout << "{" << std::endl; // Print all members unpack_list(info.members, pretty_print); // End brace, and newline std::cout << "}" << std::endl; }
static void unpack_anything(t_unpack *x, t_symbol *s, int ac, t_atom *av) { t_atom *av2 = (t_atom *)getbytes((ac + 1) * sizeof(t_atom)); int i; for (i = 0; i < ac; i++) av2[i + 1] = av[i]; SETSYMBOL(av2, s); unpack_list(x, 0, ac+1, av2); freebytes(av2, (ac + 1) * sizeof(t_atom)); }
void unpack_data(cBuf *buf, Long *buf_pos, cData *data) { data->type = read_long(buf, buf_pos); switch (data->type) { case INTEGER: data->u.val = read_long(buf, buf_pos); break; case FLOAT: data->u.fval = read_float(buf, buf_pos); break; case STRING: data->u.str = string_unpack(buf, buf_pos); break; case OBJNUM: data->u.objnum = read_long(buf, buf_pos); break; case LIST: data->u.list = unpack_list(buf, buf_pos); break; case SYMBOL: data->u.symbol = read_ident(buf, buf_pos); break; case T_ERROR: data->u.error = read_ident(buf, buf_pos); break; case FROB: data->u.frob = TMALLOC(cFrob, 1); data->u.frob->cclass = read_long(buf, buf_pos); unpack_data(buf, buf_pos, &data->u.frob->rep); break; case DICT: data->u.dict = unpack_dict(buf, buf_pos); break; case BUFFER: { Int len; len = read_long(buf, buf_pos); data->u.buffer = buffer_new(len); data->u.buffer->len = len; MEMCPY(data->u.buffer->s, &(buf->s[*buf_pos]), len); (*buf_pos) += len; break; } #ifdef USE_PARENT_OBJS case OBJECT: break; #endif default: { INSTANCE_RECORD(data->type, r); r->unpack(buf, buf_pos, data); } } }
bool UNPACK_VALUE(serial_context *ser_cont, as_val **value) { int32_t type = READ_CHAR(ser_cont->fd, ser_cont->line_no, ser_cont->col_no, ser_cont->bytes); if (type == EOF) { err("Error while reading value type"); return false; } switch (type) { case 0xc0: // nil return unpack_nil(ser_cont, value); case 0xc3: // boolean true return unpack_boolean(ser_cont, true, value); case 0xc2: // boolean false return unpack_boolean(ser_cont, false, value); case 0xca: { // float float tmp; return extract_float(ser_cont, &tmp) && unpack_double(ser_cont, tmp, value); } case 0xcb: { // double double tmp; return extract_double(ser_cont, &tmp) && unpack_double(ser_cont, tmp, value); } case 0xd0: { // signed 8 bit integer int8_t tmp; return extract_uint8(ser_cont, (uint8_t *)&tmp) && unpack_integer(ser_cont, tmp, value); } case 0xcc: { // unsigned 8 bit integer uint8_t tmp; return extract_uint8(ser_cont, &tmp) && unpack_integer(ser_cont, tmp, value); } case 0xd1: { // signed 16 bit integer int16_t tmp; return extract_uint16(ser_cont, (uint16_t *)&tmp) && unpack_integer(ser_cont, tmp, value); } case 0xcd: { // unsigned 16 bit integer uint16_t tmp; return extract_uint16(ser_cont, &tmp) && unpack_integer(ser_cont, tmp, value); } case 0xd2: { // signed 32 bit integer int32_t tmp; return extract_uint32(ser_cont, (uint32_t *)&tmp) && unpack_integer(ser_cont, tmp, value); } case 0xce: { // unsigned 32 bit integer uint32_t tmp; return extract_uint32(ser_cont, &tmp) && unpack_integer(ser_cont, tmp, value); } case 0xd3: { // signed 64 bit integer int64_t tmp; return extract_uint64(ser_cont, (uint64_t *)&tmp) && unpack_integer(ser_cont, tmp, value); } case 0xcf: { // unsigned 64 bit integer uint64_t tmp; return extract_uint64(ser_cont, &tmp) && unpack_integer(ser_cont, (int64_t)tmp, value); } case 0xc4: case 0xd9: { // raw bytes with 8 bit header uint8_t size; return extract_uint8(ser_cont, &size) && unpack_blob(ser_cont, size, value); } case 0xc5: case 0xda: { // raw bytes with 16 bit header uint16_t size; return extract_uint16(ser_cont, &size) && unpack_blob(ser_cont, size, value); } case 0xc6: case 0xdb: { // raw bytes with 32 bit header uint32_t size; return extract_uint32(ser_cont, &size) && unpack_blob(ser_cont, size, value); } case 0xdc: { // list with 16 bit header uint16_t size; return extract_uint16(ser_cont, &size) && unpack_list(ser_cont, size, value); } case 0xdd: { // list with 32 bit header uint32_t size; return extract_uint32(ser_cont, &size) && unpack_list(ser_cont, size, value); } case 0xde: { // map with 16 bit header uint16_t size; return extract_uint16(ser_cont, &size) && unpack_map(ser_cont, size, value); } case 0xdf: { // map with 32 bit header uint32_t size; return extract_uint32(ser_cont, &size) && unpack_map(ser_cont, size, value); } default: if ((type & 0xe0) == 0xa0) { // raw bytes with 8 bit combined header return unpack_blob(ser_cont, type & 0x1f, value); } if ((type & 0xf0) == 0x80) { // map with 8 bit combined header return unpack_map(ser_cont, type & 0x0f, value); } if ((type & 0xf0) == 0x90) { // list with 8 bit combined header return unpack_list(ser_cont, type & 0x0f, value); } if (type < 0x80) { // 8 bit combined unsigned integer return unpack_integer(ser_cont, type, value); } if (type >= 0xe0) { // 8 bit combined signed integer return unpack_integer(ser_cont, type - 0xe0 - 32, value); } return false; } }