Skip to content

Commit

Permalink
WIP nameds in the callsite
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Apr 10, 2014
1 parent 5eedf49 commit b80ddf0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/core/args.c
Expand Up @@ -69,6 +69,7 @@ MVMCallsite * MVM_args_proc_to_callsite(MVMThreadContext *tc, MVMArgProcContext
res->arg_count = ctx->arg_count;
res->num_pos = ctx->num_pos;
res->has_flattening = 0;
res->arg_name = NULL;
return res;
}
else {
Expand Down
17 changes: 15 additions & 2 deletions src/core/bytecode.c
Expand Up @@ -3,7 +3,7 @@
/* Some constants. */
#define HEADER_SIZE 92
#define MIN_BYTECODE_VERSION 1
#define MAX_BYTECODE_VERSION 2
#define MAX_BYTECODE_VERSION 3
#define FRAME_HEADER_SIZE (9 * 4 + (rs->version >= 2 ? 2 : 1) * 2)
#define FRAME_HANDLER_SIZE (4 * 4 + 2 * 2)
#define SCDEP_HEADER_OFFSET 12
Expand Down Expand Up @@ -687,7 +687,20 @@ static MVMCallsite ** deserialize_callsites(MVMThreadContext *tc, MVMCompUnit *c
callsites[i]->arg_count = positionals + nameds;
callsites[i]->has_flattening = has_flattening;
callsites[i]->is_interned = 0;
callsites[i]->with_invocant = NULL;
callsites[i]->with_invocant = NULL;

if (rs->version >= 3) {
ensure_can_read(tc, cu, rs, pos, (nameds / 2) * 4);
callsites[i]->arg_name = malloc((nameds / 2) * sizeof(MVMString));

for (j = 0; j < nameds / 2; j++) {
callsites[i]->arg_name[j] = get_heap_string(tc, cu, rs, pos, 0);
printf("[%d][%d]=%d\n", i, j, callsites[i]->arg_name[j]);
pos += 4;
}
} else {
callsites[i]->arg_name = 0;
}

/* Track maximum callsite size we've seen. (Used for now, though
* in the end we probably should calculate it by frame.) */
Expand Down
9 changes: 6 additions & 3 deletions src/core/callsite.h
Expand Up @@ -13,9 +13,7 @@ typedef enum {
/* Argument is a native NFG string (MVMString REPR). */
MVM_CALLSITE_ARG_STR = 8,

/* Argument is named; in this case, there are two entries in
* the argument list, the first a MVMString naming the arg and
* after that the arg. */
/* Argument is named. The name is placed in the MVMCallsite. */
MVM_CALLSITE_ARG_NAMED = 32,

/* Argument is flattened. What this means is up to the target. */
Expand Down Expand Up @@ -53,6 +51,11 @@ struct MVMCallsite {
/* Cached version of this callsite with an extra invocant arg. */
MVMCallsite *with_invocant;

/* Names that go with the named parameters.
* The first entry to this is the first named's name.
* Potentially a null pointer */
MVMString **arg_name;

#if MVM_HLL_PROFILE_CALLS
MVMuint32 static_frame_id;
MVMuint8 *cuuid, *name;
Expand Down
1 change: 1 addition & 0 deletions src/core/frame.c
Expand Up @@ -977,6 +977,7 @@ MVMObject * MVM_frame_find_invokee(MVMThreadContext *tc, MVMObject *code, MVMCal
new->num_pos = orig->num_pos + 1;
new->has_flattening = orig->has_flattening;
new->with_invocant = NULL;
new->arg_name = NULL;
*tweak_cs = orig->with_invocant = new;
}
memmove(tc->cur_frame->args + 1, tc->cur_frame->args,
Expand Down
1 change: 1 addition & 0 deletions src/core/nativecall.c
Expand Up @@ -327,6 +327,7 @@ static void * unmarshal_callback(MVMThreadContext *tc, MVMObject *callback, MVMO
cs->num_pos = num_info - 1;
cs->has_flattening = 0;
cs->with_invocant = NULL;
cs->arg_name = NULL;

typehash = MVM_repr_at_pos_o(tc, sig_info, 0);
callback_data->types[0] = MVM_repr_at_key_o(tc, typehash,
Expand Down
11 changes: 11 additions & 0 deletions src/gc/roots.c
Expand Up @@ -329,17 +329,28 @@ static void scan_registers(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMFra

/* Scan arg buffer if needed. */
if (frame->args && frame->cur_args_callsite) {
MVMuint16 num_nameds = 0;

flag_map = frame->cur_args_callsite->arg_flags;
count = frame->cur_args_callsite->arg_count;
for (i = 0, flag = 0; i < count; i++, flag++) {
if (flag_map[flag] & MVM_CALLSITE_ARG_NAMED) {
/* Current position is name, then next is value. */
MVM_gc_worklist_add(tc, worklist, &frame->args[i].s);
i++;
num_nameds++;
}
if (flag_map[flag] & MVM_CALLSITE_ARG_STR || flag_map[flag] & MVM_CALLSITE_ARG_OBJ)
MVM_gc_worklist_add(tc, worklist, &frame->args[i].o);
}
/* Scan all the nameds stashed away in the callsite */
if (frame->cur_args_callsite->arg_name) {
for (i = 0; i < num_nameds; i++) {
/* XXX this ought to never be the case, but it is. */
if (frame->cur_args_callsite->arg_name[i])
MVM_gc_worklist_add(tc, worklist, frame->cur_args_callsite->arg_name[i]);
}
}
}

/* Scan lexicals. */
Expand Down
35 changes: 28 additions & 7 deletions src/mast/compiler.c
Expand Up @@ -3,7 +3,7 @@

/* Some constants. */
#define HEADER_SIZE 92
#define BYTECODE_VERSION 2
#define BYTECODE_VERSION 3
#define FRAME_HEADER_SIZE (9 * 4 + 2 * 2)
#define FRAME_HANDLER_SIZE (4 * 4 + 2 * 2)
#define SC_DEP_SIZE 4
Expand Down Expand Up @@ -169,7 +169,7 @@ unsigned int get_string_heap_index(VM, WriterState *ws, VMSTR *strval);
unsigned short get_frame_index(VM, WriterState *ws, MASTNode *frame);
unsigned short type_to_local_type(VM, WriterState *ws, MASTNode *type);
void compile_operand(VM, WriterState *ws, unsigned char op_flags, MASTNode *operand);
unsigned short get_callsite_id(VM, WriterState *ws, MASTNode *flags);
unsigned short get_callsite_id(VM, WriterState *ws, MASTNode *flags, MASTNode *args);
void compile_instruction(VM, WriterState *ws, MASTNode *node);
void compile_frame(VM, WriterState *ws, MASTNode *node, unsigned short idx);
char * form_string_heap(VM, WriterState *ws, unsigned int *string_heap_size);
Expand Down Expand Up @@ -519,13 +519,14 @@ void compile_operand(VM, WriterState *ws, unsigned char op_flags, MASTNode *oper

/* Takes a set of flags describing a callsite. Writes out a callsite
* descriptor and returns the index of it. */
unsigned short get_callsite_id(VM, WriterState *ws, MASTNode *flags) {
unsigned short get_callsite_id(VM, WriterState *ws, MASTNode *flags, MASTNode *args) {
/* Work out callsite size. */
unsigned short elems = (unsigned short)ELEMS(vm, flags);
unsigned short align = elems % 2;
unsigned short i;
CallsiteReuseEntry *entry = NULL;
unsigned char *identifier = (unsigned char *)malloc(elems);
unsigned int num_nameds = 0;

for (i = 0; i < elems; i++)
identifier[i] = (unsigned char)ATPOS_I_C(vm, flags, i);
Expand All @@ -543,12 +544,32 @@ unsigned short get_callsite_id(VM, WriterState *ws, MASTNode *flags) {
2 + elems + align);
write_int16(ws->callsite_seg, ws->callsite_pos, elems);
ws->callsite_pos += 2;
for (i = 0; i < elems; i++)
write_int8(ws->callsite_seg, ws->callsite_pos++,
(unsigned char)ATPOS_I_C(vm, flags, i));
for (i = 0; i < elems; i++) {
unsigned char flag = (unsigned char)ATPOS_I_C(vm, flags, i);
write_int8(ws->callsite_seg, ws->callsite_pos++, flag);
if (flag & (MVM_CALLSITE_ARG_NAMED)) { /* | MVM_CALLSITE_ARG_FLAT_NAMED)) { */
/*printf("%d %d \n", flag & MVM_CALLSITE_ARG_NAMED, flag & MVM_CALLSITE_ARG_FLAT_NAMED);*/
num_nameds++;
}
}
if (align)
write_int8(ws->callsite_seg, ws->callsite_pos++, 0);

ensure_space(vm, &ws->callsite_seg, &ws->callsite_alloc, ws->callsite_pos,
4 * num_nameds);

printf("elems: %d\n", ELEMS(vm, args));

for (i = 0; i < num_nameds; i++) {
printf(".");
MAST_SVal *argname = ATPOS(vm, args, (elems - num_nameds) + i * 2);
write_int32(ws->callsite_seg, ws->callsite_pos,
get_string_heap_index(vm, ws, argname->value));
printf("%d is the string heap index\n", get_string_heap_index(vm, ws, argname->value));
ws->callsite_pos += 4;
}
printf("\n");

return (unsigned short)ws->num_callsites++;
}

Expand Down Expand Up @@ -654,7 +675,7 @@ void compile_instruction(VM, WriterState *ws, MASTNode *node) {
unsigned short num_flags, num_args, flag_pos, arg_pos;

/* Emit callsite (may re-use existing one) and emit loading of it. */
unsigned short callsite_id = get_callsite_id(vm, ws, c->flags);
unsigned short callsite_id = get_callsite_id(vm, ws, c->flags, c->args);
ensure_space(vm, &ws->bytecode_seg, &ws->bytecode_alloc, ws->bytecode_pos, 4);
write_int16(ws->bytecode_seg, ws->bytecode_pos, MVM_OP_prepargs);
ws->bytecode_pos += 2;
Expand Down

0 comments on commit b80ddf0

Please sign in to comment.