Skip to content

Commit

Permalink
New callsite flag for native unsigned ints MVM_CALLSITE_ARG_UINT
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 8, 2022
1 parent e313f50 commit fc55490
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/MAST/Nodes.nqp
Expand Up @@ -399,6 +399,7 @@ module Arg {
our $literal := 16;
our $named := 32;
our $flat := 64;
our $uint := 128;
}

# Labels (used directly in the instruction stream indicates where the
Expand Down
5 changes: 3 additions & 2 deletions src/6model/reprs/MVMCapture.c
Expand Up @@ -207,7 +207,8 @@ MVMObject * MVM_capture_arg_pos_o(MVMThreadContext *tc, MVMObject *capture_obj,
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_OBJ)
MVM_exception_throw_adhoc(tc, "Capture argument is not an object argument for captureposarg");
MVM_exception_throw_adhoc(tc, "Capture argument is not an object argument for captureposarg. Got %d instead",
(capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK));
return capture->body.args[idx].o;
}

Expand Down Expand Up @@ -236,7 +237,7 @@ MVMint64 MVM_capture_arg_pos_i(MVMThreadContext *tc, MVMObject *capture_obj, MVM
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg_i", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_INT)
if (!(capture->body.callsite->arg_flags[idx] & (MVM_CALLSITE_ARG_INT | MVM_CALLSITE_ARG_UINT)))
MVM_exception_throw_adhoc(tc, "Capture argument is not an integer argument for captureposarg_i");
return capture->body.args[idx].i64;
}
Expand Down
2 changes: 1 addition & 1 deletion src/6model/reprs/MVMCapture.h
Expand Up @@ -47,4 +47,4 @@ MVMObject * MVM_capture_drop_args(MVMThreadContext *tc, MVMObject *capture, MVMu
MVMObject * MVM_capture_insert_arg(MVMThreadContext *tc, MVMObject *capture, MVMuint32 idx,
MVMCallsiteFlags kind, MVMRegister value);
MVMObject * MVM_capture_replace_arg(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx,
MVMCallsiteEntry kind, MVMRegister value);
MVMCallsiteEntry kind, MVMRegister value);
2 changes: 1 addition & 1 deletion src/6model/reprs/NativeRef.c
Expand Up @@ -192,7 +192,7 @@ void MVM_nativeref_ensure(MVMThreadContext *tc, MVMObject *type, MVMuint16 wantp
if (!repr_data)
MVM_exception_throw_adhoc(tc, "%s set to NativeRef that is not yet composed", guilty);
if (repr_data->primitive_type != wantprim)
MVM_exception_throw_adhoc(tc, "%s set to NativeRef of wrong primitive type", guilty);
MVM_exception_throw_adhoc(tc, "%s set to NativeRef of wrong primitive type, got %d, expected %d", guilty, repr_data->primitive_type, wantprim);
if (repr_data->ref_kind != wantkind)
MVM_exception_throw_adhoc(tc, "%s set to NativeRef of wrong reference kind", guilty);
}
Expand Down
22 changes: 22 additions & 0 deletions src/core/args.c
Expand Up @@ -351,6 +351,10 @@ static MVMObject * decont_arg(MVMThreadContext *tc, MVMObject *arg) {
result.arg.i64 = MVM_repr_get_int(tc, obj); \
result.flags = MVM_CALLSITE_ARG_INT; \
break; \
case MVM_CALLSITE_ARG_UINT: \
result.arg.u64 = MVM_repr_get_uint(tc, obj); \
result.flags = MVM_CALLSITE_ARG_UINT; \
break; \
case MVM_CALLSITE_ARG_NUM: \
result.arg.n64 = MVM_repr_get_num(tc, obj); \
result.flags = MVM_CALLSITE_ARG_NUM; \
Expand All @@ -366,6 +370,7 @@ static MVMObject * decont_arg(MVMThreadContext *tc, MVMObject *arg) {
if (!(result.flags & type_flag)) { \
switch (type_flag) { \
case MVM_CALLSITE_ARG_INT: \
case MVM_CALLSITE_ARG_UINT: \
switch (result.flags & MVM_CALLSITE_ARG_TYPE_MASK) { \
case MVM_CALLSITE_ARG_NUM: \
MVM_exception_throw_adhoc(tc, "Expected native int argument, but got num"); \
Expand All @@ -378,6 +383,7 @@ static MVMObject * decont_arg(MVMThreadContext *tc, MVMObject *arg) {
case MVM_CALLSITE_ARG_NUM: \
switch (result.flags & MVM_CALLSITE_ARG_TYPE_MASK) { \
case MVM_CALLSITE_ARG_INT: \
case MVM_CALLSITE_ARG_UINT: \
MVM_exception_throw_adhoc(tc, "Expected native num argument, but got int"); \
case MVM_CALLSITE_ARG_STR: \
MVM_exception_throw_adhoc(tc, "Expected native num argument, but got str"); \
Expand All @@ -388,6 +394,7 @@ static MVMObject * decont_arg(MVMThreadContext *tc, MVMObject *arg) {
case MVM_CALLSITE_ARG_STR: \
switch (result.flags & MVM_CALLSITE_ARG_TYPE_MASK) { \
case MVM_CALLSITE_ARG_INT: \
case MVM_CALLSITE_ARG_UINT: \
MVM_exception_throw_adhoc(tc, "Expected native str argument, but got int"); \
case MVM_CALLSITE_ARG_NUM: \
MVM_exception_throw_adhoc(tc, "Expected native str argument, but got num"); \
Expand Down Expand Up @@ -451,6 +458,9 @@ static MVMObject * decont_arg(MVMThreadContext *tc, MVMObject *arg) {
case MVM_CALLSITE_ARG_INT: \
autobox_int(tc, tc->cur_frame, result.arg.i64, result.arg.o); \
break; \
case MVM_CALLSITE_ARG_UINT: \
autobox_int(tc, tc->cur_frame, result.arg.u64, result.arg.o); /* FIXME need autobox_uint */ \
break; \
case MVM_CALLSITE_ARG_NUM: \
autobox(tc, tc->cur_frame, result.arg.n64, num_box_type, 0, set_num, result.arg.o); \
break; \
Expand Down Expand Up @@ -962,6 +972,10 @@ MVMObject * MVM_args_slurpy_positional(MVMThreadContext *tc, MVMArgProcContext *
box_slurpy_pos_int(tc, type, result, box, arg_info.arg.i64, reg, int_box_type, "int", set_int);
break;
}
case MVM_CALLSITE_ARG_UINT:{
box_slurpy_pos_int(tc, type, result, box, arg_info.arg.u64, reg, int_box_type, "int", set_int); //FIXME need box_slurpy_pos_uint
break;
}
case MVM_CALLSITE_ARG_NUM: {
box_slurpy_pos(tc, type, result, box, arg_info.arg.n64, reg, num_box_type, "num", set_num);
break;
Expand Down Expand Up @@ -1071,6 +1085,14 @@ MVMObject * MVM_args_slurpy_named(MVMThreadContext *tc, MVMArgProcContext *ctx)
ctx = &(tc->cur_frame->params);
break;
}
case MVM_CALLSITE_ARG_UINT: {
MVM_gc_root_temp_push(tc, (MVMCollectable **)&key);
box_slurpy_named_int(tc, type, result, box, arg_info.arg.u64, reg, key); // FIXME need box_slurpy_named_uint
MVM_gc_root_temp_pop(tc);
if (reset_ctx)
ctx = &(tc->cur_frame->params);
break;
}
case MVM_CALLSITE_ARG_NUM: {
MVM_gc_root_temp_push(tc, (MVMCollectable **)&key);
box_slurpy_named(tc, type, result, box, arg_info.arg.n64, reg, num_box_type, "num", set_num, key);
Expand Down
1 change: 1 addition & 0 deletions src/core/bytecodedump.c
Expand Up @@ -452,6 +452,7 @@ char * MVM_bytecode_dump(MVMThreadContext *tc, MVMCompUnit *cu) {
else a(" positional");
if (csitee & MVM_CALLSITE_ARG_OBJ) a(" obj");
else if (csitee & MVM_CALLSITE_ARG_INT) a(" int");
else if (csitee & MVM_CALLSITE_ARG_UINT) a(" uint");
else if (csitee & MVM_CALLSITE_ARG_NUM) a(" num");
else if (csitee & MVM_CALLSITE_ARG_STR) a(" str");
if (csitee & MVM_CALLSITE_ARG_FLAT) a(" flat");
Expand Down
9 changes: 7 additions & 2 deletions src/core/callsite.h
@@ -1,6 +1,6 @@
/* Callsite argument flags. */
#define MVM_CALLSITE_ARG_TYPE_MASK 15
#define MVM_CALLSITE_ARG_NAMED_FLAT_MASK 31
#define MVM_CALLSITE_ARG_TYPE_MASK 143
#define MVM_CALLSITE_ARG_NAMED_FLAT_MASK 159
typedef enum {
/* Argument is an object. */
MVM_CALLSITE_ARG_OBJ = 1,
Expand All @@ -22,6 +22,9 @@ typedef enum {

/* Argument is flattened. What this means is up to the target. */
MVM_CALLSITE_ARG_FLAT = 64,

/* Argument is a native integer, unsigned. */
MVM_CALLSITE_ARG_UINT = 128,
} MVMCallsiteFlags;

/* Callsites that are used within the VM. */
Expand Down Expand Up @@ -145,6 +148,8 @@ MVM_STATIC_INLINE const char * MVM_callsite_arg_type_name(MVMCallsiteFlags f) {
return "str";
case MVM_CALLSITE_ARG_INT:
return "int";
case MVM_CALLSITE_ARG_UINT:
return "uint";
case MVM_CALLSITE_ARG_NUM:
return "num";
default:
Expand Down
5 changes: 2 additions & 3 deletions src/core/nativecall_dyncall.c
Expand Up @@ -166,8 +166,7 @@ static void * unmarshal_callback(MVMThreadContext *tc, MVMCode *callback, MVMObj
case MVM_NATIVECALL_ARG_UINT:
case MVM_NATIVECALL_ARG_ULONG:
case MVM_NATIVECALL_ARG_ULONGLONG:
/* TODO: should probably be UINT, when we can support that. */
cs->arg_flags[i - 1] = MVM_CALLSITE_ARG_INT;
cs->arg_flags[i - 1] = MVM_CALLSITE_ARG_UINT;
break;
case MVM_NATIVECALL_ARG_FLOAT:
case MVM_NATIVECALL_ARG_DOUBLE:
Expand Down Expand Up @@ -1016,7 +1015,7 @@ void MVM_nativecall_dispatch(MVMThreadContext *tc, MVMObject *res_type,
arg_types[i] & MVM_NATIVECALL_ARG_TYPE_MASK, i);
}
}
else if (args.callsite->arg_flags[i + 1] & MVM_CALLSITE_ARG_INT) {
else if (args.callsite->arg_flags[i + 1] & (MVM_CALLSITE_ARG_INT | MVM_CALLSITE_ARG_UINT)) {
if ((arg_types[i] & MVM_NATIVECALL_ARG_RW_MASK) == MVM_NATIVECALL_ARG_RW) {
dcArgPointer(vm, &args.source[args.map[i + 1]].i64);
}
Expand Down
5 changes: 2 additions & 3 deletions src/core/nativecall_libffi.c
Expand Up @@ -158,8 +158,7 @@ static void * unmarshal_callback(MVMThreadContext *tc, MVMCode *callback, MVMObj
case MVM_NATIVECALL_ARG_UINT:
case MVM_NATIVECALL_ARG_ULONG:
case MVM_NATIVECALL_ARG_ULONGLONG:
/* TODO: should probably be UINT, when we can support that. */
cs->arg_flags[i - 1] = MVM_CALLSITE_ARG_INT;
cs->arg_flags[i - 1] = MVM_CALLSITE_ARG_UINT;
break;
case MVM_NATIVECALL_ARG_FLOAT:
case MVM_NATIVECALL_ARG_DOUBLE:
Expand Down Expand Up @@ -987,7 +986,7 @@ void MVM_nativecall_dispatch(MVMThreadContext *tc, MVMObject *res_type,
arg_types[i] & MVM_NATIVECALL_ARG_TYPE_MASK, i);
}
}
else if (args.callsite->arg_flags[i + 1] & MVM_CALLSITE_ARG_INT) {
else if (args.callsite->arg_flags[i + 1] & (MVM_CALLSITE_ARG_INT | MVM_CALLSITE_ARG_UINT)) {
if ((arg_types[i] & MVM_NATIVECALL_ARG_RW_MASK) == MVM_NATIVECALL_ARG_RW) {
values[i] = alloca(sizeof(void *));
*(void **)values[i] = &args.source[args.map[i + 1]].i64;
Expand Down
3 changes: 3 additions & 0 deletions src/core/validation.c
Expand Up @@ -385,6 +385,9 @@ static void validate_dispatch_args(Validator *val, MVMCallsite *cs) {
case MVM_CALLSITE_ARG_INT:
validate_reg_operand(val, MVM_operand_int64);
break;
case MVM_CALLSITE_ARG_UINT:
validate_reg_operand(val, MVM_operand_uint64);
break;
case MVM_CALLSITE_ARG_NUM:
validate_reg_operand(val, MVM_operand_num64);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/debug/debugserver.c
Expand Up @@ -1634,6 +1634,10 @@ static MVMuint64 request_invoke_code(MVMThreadContext *dtc, cmp_ctx_t *ctx, requ
cs->arg_flags[index] = MVM_CALLSITE_ARG_INT;
arguments_to_pass[index].i64 = argument->arguments[index].arg_u.i;
}
else if (argument->arguments[index].arg_kind == MVM_reg_uint64) {
cs->arg_flags[index] = MVM_CALLSITE_ARG_UINT;
arguments_to_pass[index].u64 = argument->arguments[index].arg_u.i;
}
else if (argument->arguments[index].arg_kind == MVM_reg_num64) {
cs->arg_flags[index] = MVM_CALLSITE_ARG_NUM;
arguments_to_pass[index].n64 = argument->arguments[index].arg_u.n;
Expand Down Expand Up @@ -2383,6 +2387,7 @@ static MVMint32 request_object_metadata(MVMThreadContext *dtc, cmp_ctx_t *ctx, r
MVMuint8 entry_count =
!!(entry & MVM_CALLSITE_ARG_OBJ)
+ !!(entry & MVM_CALLSITE_ARG_INT)
+ !!(entry & MVM_CALLSITE_ARG_UINT)
+ !!(entry & MVM_CALLSITE_ARG_NUM)
+ !!(entry & MVM_CALLSITE_ARG_STR)
+ !!(entry & MVM_CALLSITE_ARG_NAMED)
Expand All @@ -2392,6 +2397,8 @@ static MVMint32 request_object_metadata(MVMThreadContext *dtc, cmp_ctx_t *ctx, r
cmp_write_str(ctx, "obj", 3);
if (entry & MVM_CALLSITE_ARG_INT)
cmp_write_str(ctx, "int", 3);
if (entry & MVM_CALLSITE_ARG_UINT)
cmp_write_str(ctx, "int", 3);
if (entry & MVM_CALLSITE_ARG_NUM)
cmp_write_str(ctx, "num", 3);
if (entry & MVM_CALLSITE_ARG_STR)
Expand Down
19 changes: 19 additions & 0 deletions src/disp/program.c
Expand Up @@ -69,6 +69,10 @@ static void dump_recording_values(MVMThreadContext *tc, MVMDispProgramRecording
fprintf(stderr, " %d Literal int value %"PRId64"\n", i,
v->literal.value.i64);
break;
case MVM_CALLSITE_ARG_UINT:
fprintf(stderr, " %d Literal uint value %"PRIu64"\n", i,
v->literal.value.u64);
break;
case MVM_CALLSITE_ARG_NUM:
fprintf(stderr, " %d Literal num value %g\n", i,
v->literal.value.n64);
Expand Down Expand Up @@ -708,6 +712,10 @@ static MVMuint32 value_index_constant(MVMThreadContext *tc, MVMDispProgramRecord
if (v->literal.value.i64 == value.i64)
return i;
break;
case MVM_CALLSITE_ARG_UINT:
if (v->literal.value.u64 == value.u64)
return i;
break;
case MVM_CALLSITE_ARG_NUM:
if (v->literal.value.n64 == value.n64)
return i;
Expand Down Expand Up @@ -1062,6 +1070,7 @@ MVMObject * MVM_disp_program_record_track_attr(MVMThreadContext *tc, MVMObject *
attr_value.o = tc->instance->VMNull;
break;
case MVM_CALLSITE_ARG_INT:
case MVM_CALLSITE_ARG_UINT:
attr_value.i64 = MVM_p6opaque_read_int64(tc, read_from, offset);
break;
case MVM_CALLSITE_ARG_NUM:
Expand Down Expand Up @@ -1871,6 +1880,7 @@ void MVM_disp_program_record_result_constant(MVMThreadContext *tc, MVMCallsiteFl
switch (kind) {
case MVM_CALLSITE_ARG_OBJ: record->outcome.result_kind = MVM_reg_obj; break;
case MVM_CALLSITE_ARG_INT: record->outcome.result_kind = MVM_reg_int64; break;
case MVM_CALLSITE_ARG_UINT: record->outcome.result_kind = MVM_reg_uint64; break;
case MVM_CALLSITE_ARG_NUM: record->outcome.result_kind = MVM_reg_num64; break;
case MVM_CALLSITE_ARG_STR: record->outcome.result_kind = MVM_reg_str; break;
default: MVM_oops(tc, "Unknown capture value type in boot-constant dispatch");
Expand All @@ -1890,6 +1900,7 @@ void MVM_disp_program_record_result_tracked_value(MVMThreadContext *tc, MVMObjec
switch (((MVMTracked *)tracked)->body.kind) {
case MVM_CALLSITE_ARG_OBJ: record->outcome.result_kind = MVM_reg_obj; break;
case MVM_CALLSITE_ARG_INT: record->outcome.result_kind = MVM_reg_int64; break;
case MVM_CALLSITE_ARG_UINT: record->outcome.result_kind = MVM_reg_uint64; break;
case MVM_CALLSITE_ARG_NUM: record->outcome.result_kind = MVM_reg_num64; break;
case MVM_CALLSITE_ARG_STR: record->outcome.result_kind = MVM_reg_str; break;
default: MVM_oops(tc, "Unknown capture value type in boot-value dispatch");
Expand Down Expand Up @@ -2127,6 +2138,10 @@ static MVMuint32 get_temp_holding_value(MVMThreadContext *tc, compile_state *cs,
op.code = MVMDispOpcodeLoadConstantInt;
op.load.idx = add_program_constant_int(tc, cs, v->literal.value.i64);
break;
case MVM_CALLSITE_ARG_UINT:
op.code = MVMDispOpcodeLoadConstantInt;
op.load.idx = add_program_constant_int(tc, cs, v->literal.value.u64);
break;
case MVM_CALLSITE_ARG_NUM:
op.code = MVMDispOpcodeLoadConstantNum;
op.load.idx = add_program_constant_num(tc, cs, v->literal.value.n64);
Expand Down Expand Up @@ -2155,6 +2170,7 @@ static MVMuint32 get_temp_holding_value(MVMThreadContext *tc, compile_state *cs,
op.code = MVMDispOpcodeLoadAttributeStr;
break;
case MVM_CALLSITE_ARG_INT:
case MVM_CALLSITE_ARG_UINT:
op.code = MVMDispOpcodeLoadAttributeInt;
break;
case MVM_CALLSITE_ARG_NUM:
Expand Down Expand Up @@ -2303,6 +2319,7 @@ static void emit_capture_guards(MVMThreadContext *tc, compile_state *cs,
}
break;
case MVM_CALLSITE_ARG_INT:
case MVM_CALLSITE_ARG_UINT:
if (v->guard_literal) {
MVMDispProgramOp op;
op.code = MVMDispOpcodeGuardArgLiteralInt;
Expand Down Expand Up @@ -2394,6 +2411,7 @@ static void emit_loaded_value_guards(MVMThreadContext *tc, compile_state *cs,
}
break;
case MVM_CALLSITE_ARG_INT:
case MVM_CALLSITE_ARG_UINT:
if (v->guard_literal) {
MVMDispProgramOp op;
op.code = MVMDispOpcodeGuardTempLiteralInt;
Expand Down Expand Up @@ -2753,6 +2771,7 @@ static void produce_resumption_init_values(MVMThreadContext *tc, compile_state *
(MVMCollectable *)value->literal.value.o);
break;
case MVM_CALLSITE_ARG_INT:
case MVM_CALLSITE_ARG_UINT:
init->source = MVM_DISP_RESUME_INIT_CONSTANT_INT;
init->index = add_program_constant_int(tc, cs,
value->literal.value.i64);
Expand Down
3 changes: 3 additions & 0 deletions src/disp/syscall.c
Expand Up @@ -846,6 +846,9 @@ static void capture_arg_value_impl(MVMThreadContext *tc, MVMArgs arg_info) {
case MVM_CALLSITE_ARG_INT:
MVM_args_set_result_int(tc, value.i64, MVM_RETURN_CURRENT_FRAME);
break;
case MVM_CALLSITE_ARG_UINT:
MVM_args_set_result_int(tc, value.u64, MVM_RETURN_CURRENT_FRAME);
break;
case MVM_CALLSITE_ARG_NUM:
MVM_args_set_result_num(tc, value.n64, MVM_RETURN_CURRENT_FRAME);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/jit/graph.c
Expand Up @@ -3796,7 +3796,7 @@ static MVMint32 consume_ins(MVMThreadContext *tc, MVMJitGraph *jg,
args[i - 1].v.reg = ins->operands[start + 2 + i].reg.orig;
}
else {
if (callsite->arg_flags[i] & MVM_CALLSITE_ARG_INT) {
if (callsite->arg_flags[i] & (MVM_CALLSITE_ARG_INT | MVM_CALLSITE_ARG_UINT)) {
args[i - 1].type = MVM_JIT_REG_VAL;
args[i - 1].v.reg = ins->operands[start + 2 + i].reg.orig;
}
Expand Down

0 comments on commit fc55490

Please sign in to comment.