jl_value_t *jl_readuntil(ios_t *s, uint8_t delim) { jl_array_t *a; // manually inlined common case char *pd = (char*)memchr(s->buf+s->bpos, delim, s->size - s->bpos); if (pd) { size_t n = pd-(s->buf+s->bpos)+1; a = jl_alloc_array_1d(jl_array_uint8_type, n); memcpy(jl_array_data(a), s->buf+s->bpos, n); s->bpos += n; } else { a = jl_alloc_array_1d(jl_array_uint8_type, 80); ios_t dest; jl_ios_mem(&dest, 0); ios_setbuf(&dest, a->data, 80, 0); size_t n = ios_copyuntil(&dest, s, delim); if (dest.buf != a->data) { a = jl_takebuf_array(&dest); } else { a->length = n; a->nrows = n; ((char*)a->data)[n] = '\0'; } } JL_GC_PUSH(&a); jl_struct_type_t* string_type = u8_isvalid(a->data, a->length) == 1 ? // ASCII jl_ascii_string_type : jl_utf8_string_type; jl_value_t *str = alloc_2w(); str->type = (jl_type_t*)string_type; jl_fieldref(str,0) = (jl_value_t*)a; JL_GC_POP(); return str; }
DLLEXPORT jl_value_t *jl_compress_ast(jl_value_t *ast) { ios_t dest; jl_ios_mem(&dest, 0); int en = jl_gc_is_enabled(); jl_gc_disable(); tree_literal_values = jl_alloc_cell_1d(0); jl_serialize_value(&dest, ast); //ios_printf(ios_stderr, "%d bytes, %d values\n", dest.size, vals->length); jl_value_t *v = (jl_value_t*)jl_takebuf_array(&dest); if (tree_literal_values->length == 0) tree_literal_values = (jl_array_t*)jl_an_empty_cell; v = (jl_value_t*)jl_tuple(4, v, tree_literal_values, jl_lam_body((jl_expr_t*)ast)->etype, jl_lam_capt((jl_expr_t*)ast)); tree_literal_values = NULL; if (en) jl_gc_enable(); return v; }
DLLEXPORT jl_value_t *jl_uncompress_ast(jl_tuple_t *data) { jl_array_t *bytes = (jl_array_t*)jl_tupleref(data, 0); tree_literal_values = (jl_array_t*)jl_tupleref(data, 1); ios_t src; jl_ios_mem(&src, 0); ios_setbuf(&src, bytes->data, bytes->length, 0); src.size = bytes->length; int en = jl_gc_is_enabled(); jl_gc_disable(); jl_gc_ephemeral_on(); jl_value_t *v = jl_deserialize_value(&src); jl_gc_ephemeral_off(); if (en) jl_gc_enable(); tree_literal_values = NULL; return v; }