Put type descriptors in strings created by the runtime. Progress on #2638.

This commit is contained in:
Michael Sullivan 2012-06-18 13:16:38 -07:00
parent b4484d51c1
commit 88ec259cee
4 changed files with 51 additions and 3 deletions

View File

@ -62,6 +62,7 @@ RUNTIME_CS_$(1) := \
rt/rust_uv.cpp \
rt/rust_log.cpp \
rt/rust_port_selector.cpp \
rt/rust_util.cpp \
rt/circular_buffer.cpp \
rt/isaac/randport.cpp \
rt/rust_kernel.cpp \

View File

@ -373,9 +373,7 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) {
size_t str_fill = args->len + 1;
size_t str_alloc = str_fill;
args->retval = (rust_opaque_box *)
task->kernel->malloc(sizeof(rust_opaque_box) +
vec_size<char>(str_fill),
"str_new_shared");
task->boxed.malloc(&str_body_tydesc, str_fill);
rust_str *str = (rust_str *)box_body(args->retval);
str->body.fill = str_fill;
str->body.alloc = str_alloc;
@ -425,6 +423,7 @@ upcall_s_str_concat(s_str_concat_args *args) {
rust_vec_box* v = (rust_vec_box*)
task->kernel->malloc(fill + sizeof(rust_vec_box),
"str_concat");
v->header.td = args->lhs->header.td;
v->body.fill = v->body.alloc = fill;
memmove(&v->body.data[0], &lhs->data[0], lhs->fill - 1);
memmove(&v->body.data[lhs->fill - 1], &rhs->data[0], rhs->fill);

43
src/rt/rust_util.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "rust_type.h"
#include "rust_shape.h"
// A hardcoded type descriptor for strings, since the runtime needs to
// be able to create them.
struct rust_shape_tables empty_shape_tables;
uint8_t str_body_shape[] = {
shape::SHAPE_UNBOXED_VEC,
0x1, // is_pod
0x1, 0x0, // size field: 1
shape::SHAPE_U8
};
struct type_desc str_body_tydesc = {
0, // unused
1, // size
1, // align
NULL, // take_glue
NULL, // drop_glue
NULL, // free_glue
NULL, // visit_glue
0, // unused
0, // unused
0, // unused
0, // unused
str_body_shape, // shape
&empty_shape_tables, // shape_tables
0, // unused
0, // unused
};
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//

View File

@ -5,6 +5,8 @@
#include "rust_task.h"
#include "rust_env.h"
extern struct type_desc str_body_tydesc;
// Inline fn used regularly elsewhere.
static inline size_t
@ -82,6 +84,7 @@ make_str(rust_kernel* kernel, const char* c, size_t strlen,
size_t str_alloc = str_fill;
rust_str *str = (rust_str *)
kernel->malloc(vec_size<char>(str_fill), name);
str->header.td = &str_body_tydesc;
str->body.fill = str_fill;
str->body.alloc = str_alloc;
memcpy(&str->body.data, c, strlen);
@ -94,6 +97,8 @@ make_str_vec(rust_kernel* kernel, size_t nstrs, char **strs) {
rust_vec_box *v = (rust_vec_box *)
kernel->malloc(vec_size<rust_vec_box*>(nstrs),
"str vec interior");
// FIXME: should have a real td (Issue #2639)
v->header.td = NULL;
v->body.fill = v->body.alloc = sizeof(rust_vec_box*) * nstrs;
for (size_t i = 0; i < nstrs; ++i) {
rust_str *str = make_str(kernel, strs[i],