static void jl_serialize_tag_type(ios_t *s, jl_value_t *v) { if (jl_is_struct_type(v)) { writetag(s, (jl_value_t*)jl_struct_kind); jl_serialize_value(s, jl_struct_kind); write_uint16(s, jl_tuple_len(((jl_struct_type_t*)v)->names)); write_int32(s, ((jl_struct_type_t*)v)->uid); write_int32(s, ((jl_struct_type_t*)v)->size); write_int32(s, ((jl_struct_type_t*)v)->alignment); size_t nf = jl_tuple_len(((jl_struct_type_t*)v)->names); ios_write(s, (char*)&((jl_struct_type_t*)v)->fields[0], nf*sizeof(jl_fielddesc_t)); jl_serialize_value(s, ((jl_struct_type_t*)v)->name); jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters); jl_serialize_value(s, ((jl_struct_type_t*)v)->super); jl_serialize_value(s, ((jl_struct_type_t*)v)->names); jl_serialize_value(s, ((jl_struct_type_t*)v)->types); jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory); jl_serialize_value(s, ((jl_struct_type_t*)v)->env); jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo); jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr); } else if (jl_is_bits_type(v)) { writetag(s, jl_struct_kind); jl_serialize_value(s, jl_bits_kind); if (v == (jl_value_t*)jl_int32_type) write_uint8(s, 2); else if (v == (jl_value_t*)jl_bool_type) write_uint8(s, 3); else if (v == (jl_value_t*)jl_int64_type) write_uint8(s, 4); else write_uint8(s, 0); jl_serialize_value(s, ((jl_tag_type_t*)v)->name); jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters); write_int32(s, ((jl_bits_type_t*)v)->nbits); jl_serialize_value(s, ((jl_bits_type_t*)v)->super); write_int32(s, ((jl_bits_type_t*)v)->uid); } else { assert(jl_is_tag_type(v)); writetag(s, jl_tag_kind); jl_serialize_value(s, ((jl_tag_type_t*)v)->name); jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters); jl_serialize_value(s, ((jl_tag_type_t*)v)->super); } }
static void jl_serialize_tag_type(ios_t *s, jl_value_t *v) { if (jl_is_struct_type(v)) { writetag(s, (jl_value_t*)jl_struct_kind); jl_serialize_value(s, jl_struct_kind); jl_serialize_value(s, ((jl_struct_type_t*)v)->name); jl_serialize_value(s, ((jl_struct_type_t*)v)->parameters); jl_serialize_value(s, ((jl_struct_type_t*)v)->super); jl_serialize_value(s, ((jl_struct_type_t*)v)->names); jl_serialize_value(s, ((jl_struct_type_t*)v)->types); jl_serialize_value(s, ((jl_struct_type_t*)v)->ctor_factory); jl_serialize_value(s, ((jl_struct_type_t*)v)->env); jl_serialize_value(s, ((jl_struct_type_t*)v)->linfo); jl_serialize_fptr(s, ((jl_struct_type_t*)v)->fptr); write_int32(s, ((jl_struct_type_t*)v)->uid); } else if (jl_is_bits_type(v)) { writetag(s, jl_struct_kind); jl_serialize_value(s, jl_bits_kind); if (v == (jl_value_t*)jl_int32_type) write_uint8(s, 2); else if (v == (jl_value_t*)jl_bool_type) write_uint8(s, 3); else if (v == (jl_value_t*)jl_int64_type) write_uint8(s, 4); else write_uint8(s, 0); jl_serialize_value(s, ((jl_tag_type_t*)v)->name); jl_serialize_value(s, ((jl_bits_type_t*)v)->parameters); write_int32(s, ((jl_bits_type_t*)v)->nbits); jl_serialize_value(s, ((jl_bits_type_t*)v)->super); write_int32(s, ((jl_bits_type_t*)v)->uid); } else { assert(jl_is_tag_type(v)); writetag(s, jl_tag_kind); jl_serialize_value(s, ((jl_tag_type_t*)v)->name); jl_serialize_value(s, ((jl_tag_type_t*)v)->parameters); jl_serialize_value(s, ((jl_tag_type_t*)v)->super); } }
static void jl_serialize_value_(ios_t *s, jl_value_t *v) { if (v == NULL) { write_uint8(s, Null_tag); return; } void **bp = ptrhash_bp(&ser_tag, v); if (*bp != HT_NOTFOUND) { write_as_tag(s, (uint8_t)(ptrint_t)*bp); return; } if (tree_literal_values) { // compressing tree if (!is_ast_node(v)) { writetag(s, (jl_value_t*)LiteralVal_tag); write_uint16(s, literal_val_id(v)); return; } } else { bp = ptrhash_bp(&backref_table, v); if (*bp != HT_NOTFOUND) { write_uint8(s, BackRef_tag); write_int32(s, (ptrint_t)*bp); return; } ptrhash_put(&backref_table, v, (void*)(ptrint_t)ios_pos(s)); } size_t i; if (jl_is_tuple(v)) { size_t l = ((jl_tuple_t*)v)->length; if (l <= 255) { writetag(s, jl_tuple_type); write_uint8(s, (uint8_t)l); } else { writetag(s, (jl_value_t*)LongTuple_tag); write_int32(s, l); } for(i=0; i < l; i++) { jl_serialize_value(s, jl_tupleref(v, i)); } } else if (jl_is_symbol(v)) { size_t l = strlen(((jl_sym_t*)v)->name); if (l <= 255) { writetag(s, jl_symbol_type); write_uint8(s, (uint8_t)l); } else { writetag(s, (jl_value_t*)LongSymbol_tag); write_int32(s, l); } ios_write(s, ((jl_sym_t*)v)->name, l); } else if (jl_is_array(v)) { jl_array_t *ar = (jl_array_t*)v; writetag(s, (jl_value_t*)jl_array_type); jl_serialize_value(s, ar->type); jl_value_t *elty = jl_tparam0(ar->type); for (i=0; i < ar->ndims; i++) jl_serialize_value(s, jl_box_long(jl_array_dim(ar,i))); if (jl_is_bits_type(elty)) { size_t tot = ar->length * ar->elsize; ios_write(s, ar->data, tot); } else { for(i=0; i < ar->length; i++) { jl_serialize_value(s, jl_cellref(v, i)); } } } else if (jl_is_expr(v)) { jl_expr_t *e = (jl_expr_t*)v; size_t l = e->args->length; if (l <= 255) { writetag(s, jl_expr_type); write_uint8(s, (uint8_t)l); } else { writetag(s, (jl_value_t*)LongExpr_tag); write_int32(s, l); } jl_serialize_value(s, e->head); jl_serialize_value(s, e->etype); for(i=0; i < l; i++) { jl_serialize_value(s, jl_exprarg(e, i)); } } else if (jl_is_some_tag_type(v)) { jl_serialize_tag_type(s, v); } else if (jl_is_typevar(v)) { writetag(s, jl_tvar_type); jl_serialize_value(s, ((jl_tvar_t*)v)->name); jl_serialize_value(s, ((jl_tvar_t*)v)->lb); jl_serialize_value(s, ((jl_tvar_t*)v)->ub); write_int8(s, ((jl_tvar_t*)v)->bound); } else if (jl_is_function(v)) { writetag(s, jl_func_kind); jl_serialize_value(s, v->type); jl_function_t *f = (jl_function_t*)v; jl_serialize_value(s, (jl_value_t*)f->linfo); jl_serialize_value(s, f->env); if (f->linfo && f->linfo->ast && (jl_is_expr(f->linfo->ast) || jl_is_tuple(f->linfo->ast)) && f->fptr != &jl_trampoline) { write_int32(s, 0); } else { jl_serialize_fptr(s, f->fptr); } } else if (jl_is_lambda_info(v)) { writetag(s, jl_lambda_info_type); jl_lambda_info_t *li = (jl_lambda_info_t*)v; jl_serialize_value(s, li->ast); jl_serialize_value(s, (jl_value_t*)li->sparams); // don't save cached type info for code in the Base module, because // it might reference types in the old System module. if (li->module == jl_base_module) jl_serialize_value(s, (jl_value_t*)jl_null); else jl_serialize_value(s, (jl_value_t*)li->tfunc); jl_serialize_value(s, (jl_value_t*)li->name); jl_serialize_value(s, (jl_value_t*)li->specTypes); jl_serialize_value(s, (jl_value_t*)li->specializations); jl_serialize_value(s, (jl_value_t*)li->inferred); jl_serialize_value(s, (jl_value_t*)li->file); jl_serialize_value(s, (jl_value_t*)li->line); jl_serialize_value(s, (jl_value_t*)li->module); } else if (jl_typeis(v, jl_module_type)) { jl_serialize_module(s, (jl_module_t*)v); } else if (jl_typeis(v, jl_methtable_type)) { writetag(s, jl_methtable_type); jl_methtable_t *mt = (jl_methtable_t*)v; jl_serialize_methlist(s, mt->defs); jl_serialize_methlist(s, mt->cache); jl_serialize_value(s, mt->cache_1arg); write_int32(s, mt->max_args); } else if (jl_typeis(v, jl_task_type)) { jl_error("Task cannot be serialized"); } else { jl_value_t *t = (jl_value_t*)jl_typeof(v); if (jl_is_bits_type(t)) { void *data = jl_bits_data(v); if (t == (jl_value_t*)jl_int64_type && *(int64_t*)data >= S32_MIN && *(int64_t*)data <= S32_MAX) { writetag(s, (jl_value_t*)SmallInt64_tag); write_int32(s, (int32_t)*(int64_t*)data); } else { int nb = ((jl_bits_type_t*)t)->nbits; writetag(s, jl_bits_kind); jl_serialize_value(s, t); ios_write(s, data, nb/8); } } else if (jl_is_struct_type(t)) { writetag(s, jl_struct_kind); jl_serialize_value(s, t); size_t nf = ((jl_struct_type_t*)t)->names->length; size_t i; for(i=0; i < nf; i++) { jl_value_t *fld = ((jl_value_t**)v)[i+1]; jl_serialize_value(s, fld); } if (t == jl_idtable_type) { jl_cell_1d_push(idtable_list, v); } } else { assert(0); } } }