Skip to content

Commit

Permalink
implement op execname which returns ARGV[0]
Browse files Browse the repository at this point in the history
This will only get useful when we provide a proper binary for nqp-m and perl6-m
  • Loading branch information
FROGGS committed Apr 3, 2014
1 parent 28cac54 commit bcc2cf4
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 7 deletions.
15 changes: 10 additions & 5 deletions lib/MAST/Ops.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ BEGIN {
1363,
1364,
1365,
1367);
1367,
1371);
MAST::Ops.WHO<@counts> := nqp::list_i(0,
2,
2,
Expand Down Expand Up @@ -1166,7 +1167,8 @@ BEGIN {
1,
1,
2,
4);
4,
1);
MAST::Ops.WHO<@values> := nqp::list_i(10,
8,
18,
Expand Down Expand Up @@ -2537,7 +2539,8 @@ BEGIN {
65,
65,
57,
57);
57,
58);
MAST::Ops.WHO<%codes> := nqp::hash('no_op', 0,
'const_i8', 1,
'const_i16', 2,
Expand Down Expand Up @@ -3119,7 +3122,8 @@ BEGIN {
'condsignalone', 578,
'condsignalall', 579,
'queuepoll', 580,
'setmultispec', 581);
'setmultispec', 581,
'execname', 582);
MAST::Ops.WHO<@names> := nqp::list('no_op',
'const_i8',
'const_i16',
Expand Down Expand Up @@ -3701,5 +3705,6 @@ BEGIN {
'condsignalone',
'condsignalall',
'queuepoll',
'setmultispec');
'setmultispec',
'execname');
}
2 changes: 2 additions & 0 deletions src/core/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ struct MVMInstance {
MVMint64 num_clargs;
/* raw command line args from APR */
char **raw_clargs;
/* executable name */
const char *exec_name;
/* program name; becomes first clargs entry */
const char *prog_name;
/* cached parsed command line args */
Expand Down
4 changes: 4 additions & 0 deletions src/core/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,10 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
cur_op += 8;
goto NEXT;
}
OP(execname):
GET_REG(cur_op, 0).s = MVM_executable_name(tc);
cur_op += 2;
goto NEXT;
#if MVM_CGOTO
OP_CALL_EXTOP: {
/* Bounds checking? Never heard of that. */
Expand Down
2 changes: 1 addition & 1 deletion src/core/oplabels.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static const void * const LABELS[] = {
&&OP_condsignalall,
&&OP_queuepoll,
&&OP_setmultispec,
NULL,
&&OP_execname,
NULL,
NULL,
NULL,
Expand Down
1 change: 1 addition & 0 deletions src/core/oplist
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,4 @@ condsignalone r(obj)
condsignalall r(obj)
queuepoll w(obj) r(obj)
setmultispec r(obj) r(obj) r(str) r(str)
execname w(str)
9 changes: 8 additions & 1 deletion src/core/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -4076,9 +4076,16 @@ static MVMOpInfo MVM_op_infos[] = {
4,
{ MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_str, MVM_operand_read_reg | MVM_operand_str }
},
{
MVM_OP_execname,
"execname",
" ",
1,
{ MVM_operand_write_reg | MVM_operand_str }
},
};

static unsigned short MVM_op_counts = 582;
static unsigned short MVM_op_counts = 583;

MVMOpInfo * MVM_op_get_op(unsigned short op) {
if (op >= MVM_op_counts)
Expand Down
1 change: 1 addition & 0 deletions src/core/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@
#define MVM_OP_condsignalall 579
#define MVM_OP_queuepoll 580
#define MVM_OP_setmultispec 581
#define MVM_OP_execname 582

#define MVM_OP_EXT_BASE 1024
#define MVM_OP_EXT_CU_LIMIT 1024
Expand Down
7 changes: 7 additions & 0 deletions src/io/procops.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ MVMnum64 MVM_proc_time_n(MVMThreadContext *tc) {
return (MVMnum64)MVM_platform_now() / 1000000000.0;
}

MVMString * MVM_executable_name(MVMThreadContext *tc) {
MVMInstance * const instance = tc->instance;
return MVM_string_utf8_decode(tc,
instance->VMString,
instance->exec_name, strlen(instance->exec_name));
}

MVMObject * MVM_proc_clargs(MVMThreadContext *tc) {
MVMInstance * const instance = tc->instance;
MVMObject *clargs = instance->clargs;
Expand Down
1 change: 1 addition & 0 deletions src/io/procops.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ MVMint64 MVM_proc_rand_i(MVMThreadContext *tc);
MVMnum64 MVM_proc_rand_n(MVMThreadContext *tc);
void MVM_proc_seed(MVMThreadContext *tc, MVMint64 seed);
MVMint64 MVM_proc_time_i(MVMThreadContext *tc);
MVMString * MVM_executable_name(MVMThreadContext *tc);
MVMObject * MVM_proc_clargs(MVMThreadContext *tc);
MVMnum64 MVM_proc_time_n(MVMThreadContext *tc);
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ int main(int argc, char *argv[])
/* stash the rest of the raw command line args in the instance */
instance->num_clargs = argc - argi;
instance->raw_clargs = argv + argi;
instance->exec_name = argv[0];
instance->prog_name = input_file;
for( argi = 0; argi < lib_path_i; argi++)
instance->lib_path[argi] = lib_path[argi];
Expand Down

0 comments on commit bcc2cf4

Please sign in to comment.