[svn:parrot] r39408 - trunk/src
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Fri Jun 5 23:04:41 UTC 2009
Author: chromatic
Date: Fri Jun 5 23:04:39 2009
New Revision: 39408
URL: https://trac.parrot.org/parrot/changeset/39408
Log:
[src] Tidied code; no functional changes.
Modified:
trunk/src/embed.c
Modified: trunk/src/embed.c
==============================================================================
--- trunk/src/embed.c Fri Jun 5 20:43:10 2009 (r39407)
+++ trunk/src/embed.c Fri Jun 5 23:04:39 2009 (r39408)
@@ -106,6 +106,7 @@
return make_interpreter(parent, PARROT_NO_FLAGS);
}
+
/*
=item C<void Parrot_init_stacktop(PARROT_INTERP, void *stack_top)>
@@ -388,17 +389,17 @@
PackFile *
Parrot_pbc_read(PARROT_INTERP, ARGIN_NULLOK(const char *fullname), const int debug)
{
+ PackFile *pf;
+ char *program_code;
FILE *io = NULL;
INTVAL is_mapped = 0;
- char *program_code;
- PackFile *pf;
INTVAL program_size;
#ifdef PARROT_HAS_HEADER_SYSMMAN
int fd = -1;
#endif
- if (fullname == NULL || STREQ(fullname, "-")) {
+ if (!fullname || STREQ(fullname, "-")) {
/* read from STDIN */
io = stdin;
@@ -418,8 +419,9 @@
/* we may need to relax this if we want to read bytecode from pipes */
if (!Parrot_stat_info_intval(interp, fs, STAT_ISREG)) {
- Parrot_io_eprintf(interp, "Parrot VM: '%s', is not a regular file %i.\n",
- fullname, errno);
+ Parrot_io_eprintf(interp,
+ "Parrot VM: '%s', is not a regular file %i.\n",
+ fullname, errno);
return NULL;
}
@@ -446,17 +448,19 @@
INTVAL wanted = program_size;
size_t read_result;
- program_code = (char *)mem_sys_allocate(chunk_size);
+ program_code = mem_allocate_n_typed(chunk_size, char);
+ cursor = program_code;
program_size = 0;
- cursor = (char *)program_code;
while ((read_result = fread(cursor, 1, chunk_size, io)) > 0) {
program_size += read_result;
+
if (program_size == wanted)
break;
+
chunk_size = 1024;
- program_code =
- (char *)mem_sys_realloc(program_code, program_size + chunk_size);
+ program_code = mem_realloc_n_typed(program_code,
+ program_size + chunk_size, char);
if (!program_code) {
Parrot_io_eprintf(interp,
@@ -466,15 +470,17 @@
return NULL;
}
- cursor = (char *)program_code + program_size;
+ cursor = (char *)(program_code + program_size);
}
if (ferror(io)) {
- Parrot_io_eprintf(interp, "Parrot VM: Problem reading packfile from PIO: code %d.\n",
+ Parrot_io_eprintf(interp,
+ "Parrot VM: Problem reading packfile from PIO: code %d.\n",
ferror(io));
mem_sys_free(program_code);
return NULL;
}
+
fclose(io);
}
else {
@@ -507,12 +513,13 @@
/* try again, now with IO reading the file */
io = fopen(fullname, "rb");
if (!io) {
- Parrot_io_eprintf(interp, "Parrot VM: Can't open %s, code %i.\n",
- fullname, errno);
+ Parrot_io_eprintf(interp,
+ "Parrot VM: Can't open %s, code %i.\n", fullname, errno);
return NULL;
}
goto again;
}
+
is_mapped = 1;
#else /* PARROT_HAS_HEADER_SYSMMAN */
@@ -539,8 +546,8 @@
return NULL;
}
+ /* Set :main routine */
if (!(pf->options & PFOPT_HEADERONLY))
- /* Set :main routine */
do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
/* JITting and/or prederefing the sub/the bytecode is done
@@ -573,7 +580,7 @@
void
Parrot_pbc_load(PARROT_INTERP, NOTNULL(PackFile *pf))
{
- if (pf == NULL) {
+ if (!pf) {
Parrot_io_eprintf(interp, "Invalid packfile\n");
return;
}
@@ -582,6 +589,7 @@
interp->code = pf->cur_cs;
}
+
/*
=item C<void Parrot_pbc_fixup_loaded(PARROT_INTERP)>
@@ -599,6 +607,7 @@
PackFile_fixup_subs(interp, PBC_LOADED, NULL);
}
+
/*
=item C<static PMC* setup_argv(PARROT_INTERP, int argc, char **argv)>
@@ -614,9 +623,8 @@
setup_argv(PARROT_INTERP, int argc, ARGIN(char **argv))
{
ASSERT_ARGS(setup_argv)
+ PMC *userargv = pmc_new(interp, enum_class_ResizableStringArray);
INTVAL i;
- PMC *userargv;
-
if (Interp_debug_TEST(interp, PARROT_START_DEBUG_FLAG)) {
Parrot_io_eprintf(interp,
@@ -624,14 +632,10 @@
argc);
}
- userargv = pmc_new_noinit(interp, enum_class_ResizableStringArray);
-
/* immediately anchor pmc to root set */
VTABLE_set_pmc_keyed_int(interp, interp->iglobals,
(INTVAL)IGLOBALS_ARGV_LIST, userargv);
- VTABLE_init(interp, userargv);
-
for (i = 0; i < argc; i++) {
/* Run through argv, adding everything to @ARGS. */
STRING * const arg =
@@ -726,10 +730,10 @@
calibrate(PARROT_INTERP)
{
ASSERT_ARGS(calibrate)
- size_t count = 1000000;
- size_t n = count;
opcode_t code[] = { 1 }; /* noop */
opcode_t *pc = code;
+ size_t count = 1000000;
+ size_t n = count;
FLOATVAL start = Parrot_floatval_time();
FLOATVAL now = start;
@@ -869,7 +873,6 @@
set_current_sub(PARROT_INTERP)
{
ASSERT_ARGS(set_current_sub)
- opcode_t i;
Parrot_sub *sub_pmc_sub;
PMC *sub_pmc;
@@ -877,6 +880,8 @@
PackFile_FixupTable * const ft = cur_cs->fixups;
PackFile_ConstTable * const ct = cur_cs->const_table;
+ opcode_t i;
+
/*
* Walk the fixup table. The first Sub-like entry should be our
* entry point with the address at our resume_offset.
@@ -903,7 +908,7 @@
}
}
- /* if we didn't find anything put a dummy PMC into current_sub */
+ /* if we didn't find anything, put a dummy PMC into current_sub */
sub_pmc = pmc_new(interp, enum_class_Sub);
PMC_get_sub(interp, sub_pmc, sub_pmc_sub);
@@ -971,7 +976,8 @@
Parrot_io_eprintf(interp, "EXEC core");
break;
default:
- Parrot_ex_throw_from_c_args(interp, NULL, 1, "Unknown run core");
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "Unknown run core");
}
Parrot_io_eprintf(interp, " ***\n");
@@ -1051,11 +1057,12 @@
return NULL;
}
+
/*
=item C<static void print_constant_table(PARROT_INTERP)>
-Print the contents of the constants table.
+Prints the contents of the constants table.
=cut
@@ -1087,17 +1094,20 @@
break;
case PFC_PMC: {
Parrot_io_printf(interp, "PMC_CONST(%d): ", i);
+
switch (c->u.key->vtable->base_type) {
- /* each PBC file has a ParrotInterpreter, but it can't stringify by itself */
+ /* each PBC file has a ParrotInterpreter, but it can't
+ * stringify by itself */
case enum_class_ParrotInterpreter:
Parrot_io_printf(interp, "'ParrotInterpreter'");
break;
- /* FixedIntegerArrays are used for signatures, handy to print */
+ /* FixedIntegerArrays used for signatures, handy to print */
case enum_class_FixedIntegerArray: {
INTVAL n = VTABLE_elements(interp, c->u.key);
INTVAL i;
Parrot_io_printf(interp, "[");
+
for (i = 0; i < n; ++i) {
INTVAL val = VTABLE_get_integer_keyed_int(interp, c->u.key, i);
Parrot_io_printf(interp, "%d", val);
@@ -1237,9 +1247,8 @@
=item C<void Parrot_run_native(PARROT_INTERP, native_func_t func)>
-Run the C function C<func> through the program C<[enternative, end]>.
-This ensures that the function is run with the same setup as in other
-run loops.
+Runs the C function C<func> through the program C<[enternative, end]>. This
+ensures that the function runs with the same setup as in other run loops.
This function is used in some of the source tests in F<t/src> which use
the interpreter outside a runloop.
@@ -1273,12 +1282,13 @@
runops(interp, interp->resume_offset);
}
+
/*
=item C<Parrot_PMC Parrot_compile_string(PARROT_INTERP, Parrot_String type,
const char *code, Parrot_String *error)>
-Compile code string.
+Compiles a code string.
=cut
@@ -1289,16 +1299,14 @@
Parrot_compile_string(PARROT_INTERP, Parrot_String type,
const char *code, Parrot_String *error)
{
+ /* For the benefit of embedders that do not load any pbc
+ * before compiling a string */
- /* For the benefit of embedders that does not load any pbc
- * before compiling a string
- */
- if (! interp->initial_pf) {
+ if (!interp->initial_pf) {
PackFile *pf = PackFile_new_dummy(interp, "compile_string");
/* Assumption: there is no valid reason to fail to create it.
- * If the assumption changes, replace the assertio with a
- * runtime check
- */
+ * If the assumption changes, replace the assertion with a
+ * runtime check */
PARROT_ASSERT(interp->initial_pf);
}
@@ -1312,6 +1320,7 @@
return NULL;
}
+
/*
=back
More information about the parrot-commits
mailing list