Skip to content

Commit

Permalink
Addresses #280
Browse files Browse the repository at this point in the history
Copy over all attributes from sysinfo into interpinfo core op.
Currently, this is duplicated between sysinfo and interpinfo. We may
move these in favour of interpinfo sometime in future deprecating
sysinfo.
  • Loading branch information
s-h-r-i committed May 15, 2012
1 parent d6dfa2e commit e439c14
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 22 deletions.
12 changes: 11 additions & 1 deletion include/parrot/gc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ typedef enum {
GC_LAZY_MARK_RUNS,
EXTENDED_PMCS,
CURRENT_RUNCORE,
PARROT_INTSIZE,
PARROT_FLOATSIZE,
PARROT_POINTERSIZE,
PARROT_INTMAX,
PARROT_INTMIN,

/* interpinfo_p constants */
CURRENT_CTX,
Expand All @@ -106,7 +111,12 @@ typedef enum {
EXECUTABLE_FULLNAME,
EXECUTABLE_BASENAME,
RUNTIME_PREFIX,
GC_SYS_NAME
GC_SYS_NAME,
PARROT_OS,
PARROT_OS_VERSION,
PARROT_OS_VERSION_NUMBER,
CPU_ARCH,
CPU_TYPE
} Interpinfo_enum;

/* &end_gen */
Expand Down
28 changes: 16 additions & 12 deletions include/parrot/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,23 @@ PARROT_DATA PMC *PMCNULL; /* Holds single null PMC */

#define STRING_IS_EMPTY(s) ((s)->strlen == 0)

/**
* WARN:
* Remove all of these attributes when we wipe out sysinfo.
* I have kept these here for consistency in parameters between
* sysinfo and interpinfo.
*/
/* &gen_from_def(sysinfo.pasm) prefix(SYSINFO_) */

#define PARROT_INTSIZE 1
#define PARROT_FLOATSIZE 2
#define PARROT_POINTERSIZE 3
#define PARROT_OS 4
#define PARROT_OS_VERSION 5
#define PARROT_OS_VERSION_NUMBER 6
#define CPU_ARCH 7
#define CPU_TYPE 8
#define PARROT_INTMAX 9
#define PARROT_INTMIN 10

#define PARROT_INTSIZE 16
#define PARROT_FLOATSIZE 17
#define PARROT_POINTERSIZE 18
#define PARROT_OS 30
#define PARROT_OS_VERSION 31
#define PARROT_OS_VERSION_NUMBER 32
#define CPU_ARCH 33
#define CPU_TYPE 34
#define PARROT_INTMAX 19
#define PARROT_INTMIN 20
/* &end_gen */

typedef opcode_t *(*native_func_t)(PARROT_INTERP,
Expand Down
4 changes: 2 additions & 2 deletions src/dynoplibs/sys.ops
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ op decodelocaltime(out PMC, in INT) {

########################################

=item B<sysinfo>(out STR, in INT)
=item B<sysinfo>(out INT, in INT)

Return system information. The values it returns depends on what you
ask. They are:
Expand All @@ -144,7 +144,7 @@ ask. They are:

=back

=item B<sysinfo>(out INT, in INT)
=item B<sysinfo>(out STR, in INT)

Return system information. The values it returns depends on what you
ask. They are:
Expand Down
55 changes: 55 additions & 0 deletions src/interp/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Functions related to managing the Parrot interpreter
#include "parrot/has_header.h"
#include "imcc/embed.h"

#ifdef PARROT_HAS_HEADER_SYSUTSNAME
# include <sys/utsname.h>
#endif

static Interp* emergency_interp = NULL;

/* HEADERIZER HFILE: include/parrot/interpreter.h */
Expand Down Expand Up @@ -821,6 +825,26 @@ Parrot_interp_info(PARROT_INTERP, INTVAL what)
case CURRENT_RUNCORE:
ret = interp->run_core->id;
break;
/*
* sysinfo attributes go here.
* We may deprecate sysinfo dynop in favour of interpinfo in future,
* or retain both.
*/
case PARROT_INTSIZE:
ret = sizeof (INTVAL);
break;
case PARROT_FLOATSIZE:
ret = sizeof (FLOATVAL);
break;
case PARROT_POINTERSIZE:
ret = sizeof (void *);
break;
case PARROT_INTMIN:
ret = PARROT_INTVAL_MIN;
break;
case PARROT_INTMAX:
ret = PARROT_INTVAL_MAX;
break;
default: /* or a warning only? */
ret = -1;
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
Expand Down Expand Up @@ -938,6 +962,37 @@ Parrot_interp_info_s(PARROT_INTERP, INTVAL what)
}
case CURRENT_RUNCORE:
return interp->run_core->name;
/*
* sysinfo attributes go here. we may deprecate these in favour of interpinfo ops
* in future.
*/
case PARROT_OS:
return Parrot_str_new_constant(interp, BUILD_OS_NAME);
case CPU_ARCH:
return Parrot_str_new_init(interp, PARROT_CPU_ARCH,
sizeof (PARROT_CPU_ARCH) - 1, Parrot_ascii_encoding_ptr, 0);
case CPU_TYPE:
return string_from_literal(interp, "");
#ifdef PARROT_HAS_HEADER_SYSUTSNAME
case PARROT_OS_VERSION:
{
struct utsname info;
if (uname(&info) == 0) {
return Parrot_str_new_init(interp, info.version,
strlen(info.version), Parrot_ascii_encoding_ptr, 0);
}
}
break;
case PARROT_OS_VERSION_NUMBER:
{
struct utsname info;
if (uname(&info) == 0) {
return Parrot_str_new_init(interp, info.release,
strlen(info.release), Parrot_ascii_encoding_ptr, 0);
}
}
break;
#endif
default:
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
"illegal argument in Parrot_interp_info");
Expand Down
6 changes: 4 additions & 2 deletions src/ops/core.ops
Original file line number Diff line number Diff line change
Expand Up @@ -1007,15 +1007,17 @@ prefix):
TOTAL_MEM_ALLOC, TOTAL_MEM_USED, GC_MARK_RUNS, GC_COLLECT_RUNS, ACTIVE_PMCS,
ACTIVE_BUFFERS, TOTAL_PMCS, TOTAL_BUFFERS, HEADER_ALLOCS_SINCE_COLLECT,
MEM_ALLOCS_SINCE_COLLECT, TOTAL_COPIED, IMPATIENT_PMCS, GC_LAZY_MARK_RUNS,
EXTENDED_PMCS, CURRENT_RUNCORE
EXTENDED_PMCS, CURRENT_RUNCORE, PARROT_INTSIZE, PARROT_FLOATSIZE, PARROT_POINTERSIZE,
PARROT_INTMAX, PARROT_INTMIN

=item B<interpinfo>(out PMC, in INT)

CURRENT_SUB, CURRENT_CONT, CURRENT_OBJECT, CURRENT_LEXPAD

=item B<interpinfo>(out STR, in INT)

EXECUTABLE_FULLNAME, EXECUTABLE_BASENAME, RUNTIME_PREFIX, CURRENT_RUNCORE
EXECUTABLE_FULLNAME, EXECUTABLE_BASENAME, RUNTIME_PREFIX, CURRENT_RUNCORE, PARROT_OS,
PARROT_OS_VERSION, PARROT_OS_VERSION_NUMBER, CPU_ARCH, CPU_TYPE

=back

Expand Down
20 changes: 15 additions & 5 deletions t/dynoplibs/sysinfo.t
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,44 @@ Tests for basic system information.
=cut

#define PARROT_INTSIZE 16
#define PARROT_FLOATSIZE 17
#define PARROT_POINTERSIZE 18
#define PARROT_OS 30
#define PARROT_OS_VERSION 31
#define PARROT_OS_VERSION_NUMBER 32
#define CPU_ARCH 33
#define CPU_TYPE 34
#define PARROT_INTMAX 19
#define PARROT_INTMIN 20

my @setup = (
{ pconfig_key => 'intvalsize',
pasm_key => 1,
pasm_key => 16,
pir_key => 'SYSINFO_PARROT_INTSIZE',
desc => 'integer size',
reg_type => 'I',
},
{ pconfig_key => 'doublesize',
pasm_key => 2,
pasm_key => 17,
pir_key => 'SYSINFO_PARROT_FLOATSIZE',
desc => 'float size',
reg_type => 'I',
},
{ pconfig_key => 'ptrsize',
pasm_key => 3,
pasm_key => 18,
pir_key => 'SYSINFO_PARROT_POINTERSIZE',
desc => 'pointer size',
reg_type => 'I',
},
{ pconfig_key => 'osname',
pasm_key => 4,
pasm_key => 30,
pir_key => 'SYSINFO_PARROT_OS',
desc => 'osname',
reg_type => 'S',
},
{ pconfig_key => 'cpuarch',
pasm_key => 7,
pasm_key => 33,
pir_key => 'SYSINFO_CPU_ARCH',
desc => 'CPU Arch Family',
reg_type => 'S',
Expand Down

0 comments on commit e439c14

Please sign in to comment.