Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[PMC] Minor cleanups and tidyings.

git-svn-id: https://svn.parrot.org/parrot/trunk@21070 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 894d4481ee5b8c98931be092dc4f092770fb7bdb 1 parent 2dc3869
@chromatic chromatic authored
View
130 src/pmc/continuation.pmc
@@ -8,9 +8,9 @@ src/pmc/continuation.pmc - Continuation PMC
=head1 DESCRIPTION
-A C<Continuation> has a copy of the interpreter's context at the location,
-where the Continuation was constructed.
-See the L<Glossary|docs/glossary.pod> for more information.
+A C<Continuation> has a copy of the interpreter's context at the location where
+the Continuation was constructed. See the L<Glossary|docs/glossary.pod> for
+more information.
=head2 Functions
@@ -40,7 +40,7 @@ See the L<Glossary|docs/glossary.pod> for more information.
/*
* A Continuation (and RetContinuation, Exception_Handler) has in its
* context a pointer to the register frame, which contains active objects.
- * Additionally ct->current_cont has he continuation of the caller.
+ * Additionally ct->current_cont has the continuation of the caller.
* To avoid deep recursion during marking of nested subroutines, we
* need the next_for_GC pointer in the pmc_ext area.
*/
@@ -82,7 +82,7 @@ Marks the continuation as live.
*/
void mark() {
- struct Parrot_cont *cc = PMC_cont(SELF);
+ Parrot_cont *cc = PMC_cont(SELF);
if (cc->to_ctx)
mark_context(INTERP, cc->to_ctx);
if (cc->dynamic_state)
@@ -100,7 +100,7 @@ Destroys the continuation.
*/
void destroy() {
- struct Parrot_cont *cc = PMC_cont(SELF);
+ Parrot_cont *cc = PMC_cont(SELF);
if (cc) {
#if CTX_LEAK_DEBUG
if (Interp_debug_TEST(interp, PARROT_CTX_DESTROY_DEBUG_FLAG)) {
@@ -126,16 +126,16 @@ Creates and returns a clone of the continuation.
*/
PMC *clone() {
- struct Parrot_cont *cc;
- struct Parrot_cont *cc_self = PMC_cont(SELF);
- PMC *ret = pmc_new_noinit(INTERP, enum_class_Continuation);
+ Parrot_cont *cc_self = PMC_cont(SELF);
+ Parrot_cont *cc = new_continuation(INTERP, cc_self);
+ PMC *ret = pmc_new_noinit(INTERP, enum_class_Continuation);
PObj_custom_mark_destroy_SETALL(ret);
- cc = new_continuation(INTERP, cc_self);
- cc->runloop_id = cc_self->runloop_id;
- cc->dynamic_state = cc_self->dynamic_state;
- PMC_struct_val(ret) = cc;
- PMC_pmc_val(ret) = PMC_pmc_val(SELF);
+ cc->runloop_id = cc_self->runloop_id;
+ cc->dynamic_state = cc_self->dynamic_state;
+ PMC_struct_val(ret) = cc;
+ PMC_pmc_val(ret) = PMC_pmc_val(SELF);
+
return ret;
}
@@ -149,8 +149,8 @@ Assign context.
*/
void set_pmc(PMC *src) {
- struct Parrot_cont * const cc_self = PMC_cont(SELF);
- struct Parrot_cont * const cc_src = PMC_cont(src);
+ Parrot_cont * const cc_self = PMC_cont(SELF);
+ Parrot_cont * const cc_src = PMC_cont(src);
STRUCT_COPY(cc_self, cc_src);
PMC_pmc_val(SELF) = PMC_pmc_val(src);
@@ -167,8 +167,8 @@ dynamic state, and the descriptor address for any returned values.
*/
void set_pointer(void *value) {
- opcode_t *pos = (opcode_t *)value;
- struct Parrot_cont *cc = PMC_cont(SELF);
+ opcode_t *pos = (opcode_t *)value;
+ Parrot_cont *cc = PMC_cont(SELF);
cc->address = (opcode_t *)value;
cc->dynamic_state = INTERP->dynamic_env;
@@ -225,18 +225,18 @@ destination to continue execution.
*/
opcode_t *invoke(void *next) {
- struct Parrot_cont *cc = PMC_cont(SELF);
- Stack_Chunk_t *stack_target = cc->dynamic_state;
- Stack_Chunk_t *corresponding_target;
- int stack_delta = 0;
- parrot_context_t *from_ctx = CONTEXT(INTERP->ctx);
- parrot_context_t *to_ctx = cc->to_ctx;
- opcode_t *pc = cc->address;
- /* [bug: these should be 'isa' tests. -- rgr, 17-Sep-06.] */
+ Parrot_cont *cc = PMC_cont(SELF);
+ Stack_Chunk_t *stack_target = cc->dynamic_state;
+ int stack_delta = 0;
+ parrot_context_t *from_ctx = CONTEXT(INTERP->ctx);
+ parrot_context_t *to_ctx = cc->to_ctx;
+ opcode_t *pc = cc->address;
+ Stack_Chunk_t *corresponding_target;
+
int exception_continuation_p
- = SELF->vtable->base_type == enum_class_Exception_Handler;
+ = VTABLE_isa(INTERP, SELF,CONST_STRING(INTERP,"Exception_Handler"));
int ret_continuation_p
- = SELF->vtable->base_type == enum_class_RetContinuation;
+ = VTABLE_isa(INTERP, SELF, CONST_STRING(INTERP, "RetContinuation"));
if (interp->current_runloop_id != cc->runloop_id
/* it's ok if we are exiting to "runloop 0"; there is no such
@@ -259,10 +259,9 @@ destination to continue execution.
(void *) SELF, (void *) to_ctx, (void *) from_ctx, (int) from_ctx->ref_count);
}
#endif
- if (! to_ctx) {
+ if (! to_ctx)
real_exception(interp, NULL, INVALID_OPERATION,
"Continuation invoked after deactivation.");
- }
/*
* Rewind the dynamic environment.
@@ -274,8 +273,8 @@ destination to continue execution.
[bug: this is not true rewinding. -- rgr, 30-Sep-06.]
*/
stack_delta
- = ((int) stack_height(interp, stack_target)
- - (int) stack_height(interp, interp->dynamic_env));
+ = ((int) stack_height(interp, stack_target) -
+ (int) stack_height(interp, interp->dynamic_env));
}
/* descend down the target stack until we get to the same depth. */
corresponding_target = stack_target;
@@ -283,17 +282,21 @@ destination to continue execution.
corresponding_target = corresponding_target->prev;
stack_delta--;
}
+
/* both stacks are now at the same depth. pop from both until we reach
their common ancestor. */
while (interp->dynamic_env != corresponding_target) {
- PMC *cleanup_sub = NULL;
+ PMC *cleanup_sub = NULL;
Stack_Entry_t *e;
if (! interp->dynamic_env)
real_exception(interp, NULL, 1, "Control stack damaged");
+
e = stack_entry(interp, interp->dynamic_env, 0);
- if (! e)
+
+ if (!e)
real_exception(interp, NULL, 1, "Control stack damaged");
+
if (e->entry_type == STACK_ENTRY_ACTION) {
/*
* Disable automatic cleanup routine execution in stack_pop so
@@ -303,27 +306,27 @@ destination to continue execution.
* an error handler.
*/
cleanup_sub = UVal_pmc(e->entry);
- e->cleanup = STACK_CLEANUP_NULL;
+ e->cleanup = STACK_CLEANUP_NULL;
}
+
(void)stack_pop(INTERP, &interp->dynamic_env,
NULL, NO_STACK_ENTRY_TYPE);
- if (cleanup_sub) {
- /* Now it's safe to run. */
+
+ /* Now it's safe to run. */
+ if (cleanup_sub)
Parrot_runops_fromc_args(interp, cleanup_sub,
"vI", exception_continuation_p);
- }
/* Keep corresponding_target in sync. If stack_delta is negative,
* then dynamic_env is still above it; otherwise, we must step
* corresponding_target backwards as well.
*/
- if (stack_delta < 0) {
+ if (stack_delta < 0)
stack_delta++;
- }
- else {
+ else
corresponding_target = corresponding_target->prev;
- }
}
+
/* run back up the target stack to our destination. [when we support
dynamic binding (e.g.), we will have to traverse back up, and will
therefore need to keep track on the way down. -- rgr, 30-Sep-06.] */
@@ -338,22 +341,21 @@ destination to continue execution.
interp->dynamic_env);
}
- /*
- * set context
- */
+ /* set context */
CONTEXT(INTERP->ctx) = to_ctx;
- INTERP->ctx.bp = to_ctx->bp;
- INTERP->ctx.bp_ps = to_ctx->bp_ps;
- if (ret_continuation_p) {
- /* RetContinuation arg passing is handled elsewhere. */
+ INTERP->ctx.bp = to_ctx->bp;
+ INTERP->ctx.bp_ps = to_ctx->bp_ps;
+
+ /* RetContinuation arg passing is handled elsewhere. */
+ if (ret_continuation_p)
return pc;
- }
/* pass args */
if (cc->current_results) {
/* where caller wants result */
to_ctx->current_results = cc->current_results;
}
+
if (to_ctx->current_results && INTERP->current_args) {
opcode_t *src_indexes, *dest_indexes;
/*
@@ -363,21 +365,22 @@ destination to continue execution.
* inside argument passing a DOD run is triggered
* therefore we have to block DOD
*/
- src_indexes = interp->current_args;
+ src_indexes = interp->current_args;
interp->current_args = NULL;
- dest_indexes = to_ctx->current_results;
+ dest_indexes = to_ctx->current_results;
Parrot_block_DOD(INTERP);
- parrot_pass_args(INTERP, from_ctx, to_ctx, src_indexes, dest_indexes,
- PARROT_PASS_PARAMS);
+ parrot_pass_args(INTERP, from_ctx, to_ctx,
+ src_indexes, dest_indexes, PARROT_PASS_PARAMS);
Parrot_unblock_DOD(INTERP);
}
/* switch segment */
INTERP->current_args = NULL;
- if (INTERP->code != cc->seg) {
+
+ if (INTERP->code != cc->seg)
Parrot_switch_to_cs(INTERP, cc->seg, 1);
- }
+
return pc;
}
@@ -406,11 +409,12 @@ Experimental: return caller PMC or Undef if none.
*/
METHOD PMC *caller() {
- struct Parrot_cont *cc = PMC_cont(SELF);
- PMC *caller = cc->to_ctx->current_sub;
- if (!caller || !PMC_sub(caller)->seg) {
+ Parrot_cont *cc = PMC_cont(SELF);
+ PMC *caller = cc->to_ctx->current_sub;
+
+ if (!caller || !PMC_sub(caller)->seg)
caller = pmc_new(INTERP, enum_class_Undef);
- }
+
return caller;
}
@@ -425,10 +429,12 @@ Experimental: return continuation PMC of this Continuation or Undef if none.
*/
METHOD PMC *continuation() {
- struct Parrot_cont *cc = PMC_cont(SELF);
- PMC *cont = cc->to_ctx->current_cont;
+ Parrot_cont *cc = PMC_cont(SELF);
+ PMC *cont = cc->to_ctx->current_cont;
+
if (cont)
return cont;
+
return pmc_new(INTERP, enum_class_Undef);
}
}
View
131 src/pmc/fixedintegerarray.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -8,8 +8,8 @@ src/pmc/fixedintegerarray.pmc - fixed size array for integers only
=head1 DESCRIPTION
-This class, FixedIntegerArray, implements an array of fixed size,
-which stored INTVALs, it uses Integer PMCs for all of the conversions
+This class, FixedIntegerArray, implements an array of fixed size which stores
+INTVALs. It uses Integer PMCs for all of the conversions.
=head2 Functions
@@ -41,7 +41,7 @@ Initializes the array.
void init() {
PMC_int_val(SELF) = 0;
- PMC_data(SELF) = NULL;
+ PMC_data(SELF) = NULL;
}
/*
@@ -57,34 +57,42 @@ in the constant PMC pool.
*/
PMC *new_from_string(STRING *rep, INTVAL flags) {
- INTVAL type, n, elem;
- char *p, *start;
- UINTVAL i, l;
- int base;
+ INTVAL type = SELF->vtable->base_type;
+ INTVAL n, elem, i, l;
+ char *p, *start;
+ int base;
- type = SELF->vtable->base_type;
if (flags & PObj_constant_FLAG)
SELF = constant_pmc_new(INTERP, type);
else
SELF = pmc_new(INTERP, type);
+
l = string_length(INTERP, rep);
+
if (!l)
return SELF;
+
if (rep->encoding != Parrot_fixed_8_encoding_ptr)
real_exception(INTERP, NULL, E_ValueError,
"unhandled string encoding in constructor");
- if (l <= 2 && ((char*)rep->strstart)[0] == '(') /* "()" - no args */
+
+ /* "()" - no args */
+ if (l <= 2 && ((char *)rep->strstart)[0] == '(')
return SELF;
+
/* count commas */
p = rep->strstart;
for (i = l, n = 0; i; --i, ++p) {
if (*p == ',')
++n;
}
+
/* presize the array */
SELF.set_integer_native(n + 1);
+
/* parse string */
p = rep->strstart;
+
for (i = l, n = 0; i; --i, ++p) {
switch (*p) {
case ' ': continue;
@@ -111,13 +119,14 @@ in the constant PMC pool.
}
}
start = p;
- elem = strtoul(p, &p, base);
+ elem = strtoul(p, &p, base);
--p;
i -= (p - start);
SELF.set_integer_keyed_int(n, elem);
break;
}
}
+
return SELF;
}
@@ -149,7 +158,8 @@ Destroys the array.
void destroy() {
if (PMC_data(SELF))
mem_sys_free(PMC_data(SELF));
- PMC_data(SELF) = NULL;
+
+ PMC_data(SELF) = NULL;
PMC_int_val(SELF) = 0;
}
@@ -165,7 +175,7 @@ Creates and returns a copy of the array.
PMC *clone() {
INTVAL size;
- PMC *dest;
+ PMC *dest;
/* a quick hack to create a clone in the constant PMC arena
* this is needed for the call signatures
*
@@ -180,12 +190,14 @@ Creates and returns a copy of the array.
if (!PMC_data(SELF))
return dest;
- size = PMC_int_val(SELF);
+
+ size = PMC_int_val(SELF);
PMC_int_val(dest) = size;
+ PMC_data(dest) = mem_sys_allocate(size * sizeof (INTVAL));
- PMC_data(dest) = mem_sys_allocate(size * sizeof (INTVAL));
- mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size*sizeof (INTVAL));
+ mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size * sizeof (INTVAL));
PObj_active_destroy_SET(dest);
+
return dest;
}
@@ -243,6 +255,7 @@ Returns the integer value of the element at index C<key>.
INTVAL get_integer_keyed_int(INTVAL key) {
INTVAL *data;
+
if (key < 0 || key >= PMC_int_val(SELF))
real_exception(interp, NULL, E_IndexError,
"FixedIntegerArray: index out of bounds!");
@@ -309,8 +322,7 @@ Returns the Parrot string value of the element at index C<key>.
*/
STRING *get_string_keyed_int(INTVAL key) {
- PMC *temp;
- temp = DYNSELF.get_pmc_keyed_int(key);
+ PMC *temp = DYNSELF.get_pmc_keyed_int(key);
return VTABLE_get_string(INTERP, temp);
}
@@ -325,18 +337,19 @@ Returns the Parrot string representation C<key>.
*/
STRING *get_repr() {
- STRING *res;
- INTVAL j, n;
- PMC *val;
+ STRING *res = string_from_literal(INTERP, "[ ");
+ INTVAL n = VTABLE_elements(INTERP, SELF);
+ INTVAL j;
+ PMC *val;
- res = string_from_literal(INTERP, "[ ");
- n = VTABLE_elements(INTERP, SELF);
for (j = 0; j < n; ++j) {
val = SELF.get_pmc_keyed_int(j);
res = string_append(INTERP, res, VTABLE_get_repr(INTERP, val));
+
if (j < n - 1)
res = string_append(INTERP, res, const_string(INTERP, ", "));
}
+
res = string_append(INTERP, res, const_string(INTERP, " ]"));
return res;
}
@@ -369,11 +382,8 @@ Returns the PMC value of the element at index C<key>.
*/
PMC *get_pmc_keyed_int(INTVAL key) {
- PMC *ret;
- INTVAL val;
-
- ret = pmc_new(INTERP, enum_class_Integer);
- val = DYNSELF.get_integer_keyed_int(key);
+ PMC *ret = pmc_new(INTERP, enum_class_Integer);
+ INTVAL val = DYNSELF.get_integer_keyed_int(key);
VTABLE_set_integer_native(INTERP, ret, val);
return ret;
}
@@ -408,7 +418,7 @@ Resizes the array to C<size> elements.
real_exception(INTERP, NULL, E_IndexError,
"FixedIntegerArray: Can't resize!");
PMC_int_val(SELF) = size;
- PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof (INTVAL));
+ PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof (INTVAL));
PObj_active_destroy_SET(SELF);
}
@@ -424,11 +434,12 @@ Sets the integer value of the element at index C<key> to C<value>.
void set_integer_keyed_int(INTVAL key, INTVAL value) {
INTVAL *data;
+
if (key < 0 || key >= PMC_int_val(SELF))
real_exception(interp, NULL, E_IndexError,
"FixedIntegerArray: index out of bounds!");
- data = (INTVAL*)PMC_data(SELF);
+ data = (INTVAL *)PMC_data(SELF);
data[key] = value;
}
@@ -443,8 +454,7 @@ Sets the integer value of the element at index C<key> to C<value>.
*/
void set_integer_keyed(PMC *key, INTVAL value) {
- INTVAL k;
- k = key_integer(INTERP, key);
+ INTVAL k = key_integer(INTERP, key);
DYNSELF.set_integer_keyed_int(k, value);
}
@@ -452,8 +462,7 @@ Sets the integer value of the element at index C<key> to C<value>.
=item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
-Sets the floating-point value of the element at index C<key> to
-C<value>.
+Sets the floating-point value of the element at index C<key> to C<value>.
=cut
@@ -467,16 +476,14 @@ C<value>.
=item C<void set_number_keyed(PMC *key, FLOATVAL value)>
-Sets the floating-point value of the element at index C<key> to
-C<value>.
+Sets the floating-point value of the element at index C<key> to C<value>.
=cut
*/
void set_number_keyed(PMC *key, FLOATVAL value) {
- INTVAL k;
- k = key_integer(INTERP, key);
+ INTVAL k = key_integer(INTERP, key);
DYNSELF.set_number_keyed_int(k, value);
}
@@ -492,11 +499,9 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
void set_string_keyed_int(INTVAL key, STRING *value) {
INTVAL tempInt;
- PMC *tempPMC;
-
- tempPMC = pmc_new(INTERP, enum_class_Integer);
+ PMC *tempPMC = pmc_new(INTERP, enum_class_Integer);
VTABLE_set_string_native(INTERP, tempPMC, value);
- tempInt = VTABLE_get_integer(INTERP, tempPMC);
+ tempInt = VTABLE_get_integer(INTERP, tempPMC);
DYNSELF.set_integer_keyed_int(key, tempInt);
}
@@ -504,16 +509,14 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
=item C<void set_string_keyed(PMC *key, STRING *value)>
-Sets the string value of the element at index C<key> to
-C<value>.
+Sets the string value of the element at index C<key> to C<value>.
=cut
*/
void set_string_keyed(PMC *key, STRING *value) {
- INTVAL k;
- k = key_integer(INTERP, key);
+ INTVAL k = key_integer(INTERP, key);
DYNSELF.set_string_keyed_int(k, value);
}
@@ -528,9 +531,7 @@ Sets the PMC value of the element at index C<key> to C<*src>.
*/
void set_pmc_keyed_int(INTVAL key, PMC *src) {
- INTVAL tempInt;
-
- tempInt = VTABLE_get_integer(INTERP, src);
+ INTVAL tempInt = VTABLE_get_integer(INTERP, src);
DYNSELF.set_integer_keyed_int(key, tempInt);
}
@@ -538,16 +539,14 @@ Sets the PMC value of the element at index C<key> to C<*src>.
=item C<void set_pmc_keyed(PMC *key, PMC *value)>
-Sets the string value of the element at index C<key> to
-C<value>.
+Sets the string value of the element at index C<key> to C<value>.
=cut
*/
void set_pmc_keyed(PMC *key, PMC *value) {
- INTVAL k;
- k = key_integer(INTERP, key);
+ INTVAL k = key_integer(INTERP, key);
DYNSELF.set_pmc_keyed_int(k, value);
}
@@ -577,34 +576,38 @@ Used to unarchive the array.
void freeze(visit_info *info) {
IMAGE_IO *io = info->image_io;
- INTVAL i, n;
- INTVAL *ar;
+ INTVAL *ar;
+ INTVAL i, n;
SUPER(info);
- n = VTABLE_elements(INTERP, SELF);
+
+ n = VTABLE_elements(INTERP, SELF);
io->vtable->push_integer(INTERP, io, n);
ar = (INTVAL *)PMC_data(SELF);
- for (i = 0; i < n; ++i) {
+
+ for (i = 0; i < n; ++i)
io->vtable->push_integer(INTERP, io, ar[i]);
- }
}
void thaw(visit_info *info) {
IMAGE_IO *io = info->image_io;
- INTVAL i, n;
- INTVAL *ar;
if (info->extra_flags == EXTRA_IS_NULL) {
+ INTVAL n = io->vtable->shift_integer(INTERP, io);
+ INTVAL i;
+ INTVAL *ar;
+
PMC_int_val(SELF) = 0;
- PMC_data(SELF) = NULL;
- n = io->vtable->shift_integer(INTERP, io);
+ PMC_data(SELF) = NULL;
+
if (!n)
return;
+
DYNSELF.set_integer_native(n);
ar = (INTVAL *)PMC_data(SELF);
- for (i = 0; i < n; ++i) {
+
+ for (i = 0; i < n; ++i)
ar[i] = io->vtable->shift_integer(INTERP, io);
- }
}
else
SUPER(info);
View
65 src/pmc/iterator.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -47,7 +47,7 @@ The C<new> can alteratively be written as:
iterator = new 'Iterator', hash
iter_loop:
unless iterator, iter_end # while (more values)
- key = shift iterator # get the key..
+ key = shift iterator # get the key..
entry = hash[key]
...
goto iter_loop
@@ -101,9 +101,10 @@ Defaults iteration mode to iterate from start.
*/
void init_pmc(PMC *aggregate) {
- PMC_pmc_val(SELF) = aggregate;
+ PMC_pmc_val(SELF) = aggregate;
PMC_struct_val(SELF) = NULL;
PObj_custom_mark_SET(SELF);
+
/* by default, iterate from start */
DYNSELF.set_integer_native(ITERATE_FROM_START);
}
@@ -121,11 +122,11 @@ Marks the current idx/key and the aggregate as live.
void mark() {
/* the KEY */
if (PMC_struct_val(SELF))
- pobject_lives(INTERP, (PObj *) PMC_struct_val(SELF));
+ pobject_lives(INTERP, (PObj *)PMC_struct_val(SELF));
/* the aggregate */
if (PMC_pmc_val(SELF))
- pobject_lives(INTERP, (PObj *) PMC_pmc_val(SELF));
+ pobject_lives(INTERP, (PObj *)PMC_pmc_val(SELF));
}
/*
@@ -139,8 +140,9 @@ Make a clone of the iterator.
*/
PMC *clone() {
- PMC * const key = (PMC *)PMC_struct_val(SELF);
- PMC * const res = pmc_new_init(INTERP, SELF->vtable->base_type, PMC_pmc_val(SELF));
+ PMC * const key = (PMC *)PMC_struct_val(SELF);
+ PMC * const res = pmc_new_init(INTERP, SELF->vtable->base_type,
+ PMC_pmc_val(SELF));
PMC_struct_val(res) = VTABLE_clone(interp, key);
return res;
}
@@ -339,8 +341,10 @@ Reset the Iterator. C<value> must be one of
if (value < ITERATE_FROM_START || value > ITERATE_FROM_END)
real_exception(INTERP, NULL, E_TypeError,
"Illegal set_integer on iterator");
+
/* reset iterator on aggregate */
- agg = (PMC*) PMC_pmc_val(SELF);
+ agg = (PMC *)PMC_pmc_val(SELF);
+
if (agg->vtable->base_type == enum_class_Slice) {
/* it's an xrange serving as its own aggregate */
PMC_struct_val(SELF) =
@@ -467,39 +471,44 @@ See F<docs/pdds/pdd03_calling_conventions.pod>.
opcode_t *invoke(void *next) {
PMC *agg;
- if (REG_INT(interp, 3) == 1) { /* iterator constructor */
- PMC *iter, *arg = REG_PMC(interp, 5);
+ /* iterator constructor */
+ if (REG_INT(interp, 3) == 1) {
+ PMC *arg = REG_PMC(interp, 5);
+ PMC *iter;
+
if (PObj_is_object_TEST(arg)) {
REG_PMC(interp, 5) = VTABLE_get_iter(INTERP, arg);
return (opcode_t *)next;
}
+
REG_PMC(interp, 5) = iter = pmc_new_init(INTERP,
enum_class_Iterator, arg);
VTABLE_set_integer_native(INTERP, iter, 0);
return (opcode_t *)next;
}
- else if (REG_INT(interp, 3) == 2) /* TODO function+sentinel */
+ /* TODO function + sentinel */
+ else if (REG_INT(interp, 3) == 2)
real_exception(INTERP, NULL, E_AssertionError,
"Iterator: invoke 2 args");
- REG_INT(interp, 1) = REG_INT(interp, 2) = REG_INT(interp, 3) = REG_INT(interp, 4) = 0;
+ REG_INT(interp, 1) =
+ REG_INT(interp, 2) =
+ REG_INT(interp, 3) =
+ REG_INT(interp, 4) = 0;
+
agg = (PMC *)PMC_pmc_val(SELF);
- switch (agg->vtable->base_type) {
- case enum_class_IntList:
- {
- const INTVAL ires = DYNSELF.shift_integer();
- REG_INT(interp, 1) = 1;
- REG_INT(interp, 5) = ires;
- return (opcode_t *)next;
- }
- default:
- {
- PMC * const res = DYNSELF.shift_pmc();
- REG_INT(interp, 3) = 1;
- REG_PMC(interp, 5) = res;
- return (opcode_t *)next;
- }
+ if (agg->vtable->base_type == enum_class_IntList) {
+ const INTVAL ires = DYNSELF.shift_integer();
+ REG_INT(interp, 1) = 1;
+ REG_INT(interp, 5) = ires;
+ return (opcode_t *)next;
+ }
+ else {
+ PMC * const res = DYNSELF.shift_pmc();
+ REG_INT(interp, 3) = 1;
+ REG_PMC(interp, 5) = res;
+ return (opcode_t *)next;
}
}
@@ -606,7 +615,7 @@ Returns whether the iterator contains an aggregate.
*/
INTVAL defined() {
- return (INTVAL) (PMC_pmc_val(SELF) != 0);
+ return (INTVAL)(PMC_pmc_val(SELF) != 0);
}
/*
View
139 src/pmc/os.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2006, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -55,7 +55,7 @@ information see F<src/pmc.c>.
}
void set_pointer(void *ptr) {
- OS_PMC = (PMC*) ptr;
+ OS_PMC = (PMC *)ptr;
}
@@ -83,8 +83,7 @@ Returns the current working directory.
# endif
#endif
if (cwd) {
- STRING *scwd;
- scwd = string_from_cstring(interp, cwd, strlen(cwd));
+ STRING *scwd = string_from_cstring(interp, cwd, strlen(cwd));
mem_sys_free(cwd);
return scwd;
}
@@ -133,7 +132,8 @@ C<path>.
METHOD void rm(STRING *path) {
struct stat info;
char *cpath = string_to_cstring(interp, path);
- int error = stat(cpath, &info);
+ int error = stat(cpath, &info);
+
if (error) {
char *errmsg = strerror(errno);
real_exception(interp, NULL, E_SystemError, errmsg);
@@ -172,7 +172,7 @@ Creates a directory specified by C<path> with mode C<mode>.
*/
METHOD void mkdir(STRING *path, INTVAL mode) {
- int error;
+ int error;
char *cpath = string_to_cstring(interp, path);
/* should we validate mode? */
#ifdef WIN32
@@ -215,10 +215,9 @@ Stats a file, and returns a 13 position array as in Perl:
METHOD PMC *stat(STRING *path) {
struct stat info;
- PMC *array;
-
- char *cpath = string_to_cstring(interp, path);
- int error = stat(cpath, &info);
+ PMC *array;
+ char *cpath = string_to_cstring(interp, path);
+ int error = stat(cpath, &info);
string_cstring_free(cpath);
if (error) {
@@ -229,33 +228,20 @@ Stats a file, and returns a 13 position array as in Perl:
array = pmc_new(interp, enum_class_FixedPMCArray);
VTABLE_set_integer_native(interp, array, 13);
- VTABLE_set_integer_keyed_int(interp, array, 0,
- info.st_dev);
- VTABLE_set_integer_keyed_int(interp, array, 1,
- info.st_ino);
- VTABLE_set_integer_keyed_int(interp, array, 2,
- info.st_mode);
- VTABLE_set_integer_keyed_int(interp, array, 3,
- info.st_nlink);
- VTABLE_set_integer_keyed_int(interp, array, 4,
- info.st_uid);
- VTABLE_set_integer_keyed_int(interp, array, 5,
- info.st_gid);
- VTABLE_set_integer_keyed_int(interp, array, 6,
- info.st_rdev);
- VTABLE_set_integer_keyed_int(interp, array, 7,
- info.st_size);
- VTABLE_set_integer_keyed_int(interp, array, 8,
- info.st_atime);
- VTABLE_set_integer_keyed_int(interp, array, 9,
- info.st_mtime);
- VTABLE_set_integer_keyed_int(interp, array,10,
- info.st_ctime);
+ VTABLE_set_integer_keyed_int(interp, array, 0, info.st_dev);
+ VTABLE_set_integer_keyed_int(interp, array, 1, info.st_ino);
+ VTABLE_set_integer_keyed_int(interp, array, 2, info.st_mode);
+ VTABLE_set_integer_keyed_int(interp, array, 3, info.st_nlink);
+ VTABLE_set_integer_keyed_int(interp, array, 4, info.st_uid);
+ VTABLE_set_integer_keyed_int(interp, array, 5, info.st_gid);
+ VTABLE_set_integer_keyed_int(interp, array, 6, info.st_rdev);
+ VTABLE_set_integer_keyed_int(interp, array, 7, info.st_size);
+ VTABLE_set_integer_keyed_int(interp, array, 8, info.st_atime);
+ VTABLE_set_integer_keyed_int(interp, array, 9, info.st_mtime);
+ VTABLE_set_integer_keyed_int(interp, array,10, info.st_ctime);
#ifndef WIN32
- VTABLE_set_integer_keyed_int(interp, array,11,
- info.st_blksize);
- VTABLE_set_integer_keyed_int(interp, array,12,
- info.st_blocks);
+ VTABLE_set_integer_keyed_int(interp, array,11, info.st_blksize);
+ VTABLE_set_integer_keyed_int(interp, array,12, info.st_blocks);
#endif
return array;
}
@@ -289,8 +275,8 @@ Stats a file, and returns a 13 position array as in Perl:
METHOD PMC *lstat(STRING *path) {
struct stat info;
- PMC *array;
+ PMC *array;
char *cpath = string_to_cstring(interp, path);
#ifdef WIN32
int error = stat(cpath, &info);
@@ -307,33 +293,20 @@ Stats a file, and returns a 13 position array as in Perl:
array = pmc_new(interp, enum_class_FixedPMCArray);
VTABLE_set_integer_native(interp, array, 13);
- VTABLE_set_integer_keyed_int(interp, array, 0,
- info.st_dev);
- VTABLE_set_integer_keyed_int(interp, array, 1,
- info.st_ino);
- VTABLE_set_integer_keyed_int(interp, array, 2,
- info.st_mode);
- VTABLE_set_integer_keyed_int(interp, array, 3,
- info.st_nlink);
- VTABLE_set_integer_keyed_int(interp, array, 4,
- info.st_uid);
- VTABLE_set_integer_keyed_int(interp, array, 5,
- info.st_gid);
- VTABLE_set_integer_keyed_int(interp, array, 6,
- info.st_rdev);
- VTABLE_set_integer_keyed_int(interp, array, 7,
- info.st_size);
- VTABLE_set_integer_keyed_int(interp, array, 8,
- info.st_atime);
- VTABLE_set_integer_keyed_int(interp, array, 9,
- info.st_mtime);
- VTABLE_set_integer_keyed_int(interp, array,10,
- info.st_ctime);
+ VTABLE_set_integer_keyed_int(interp, array, 0, info.st_dev);
+ VTABLE_set_integer_keyed_int(interp, array, 1, info.st_ino);
+ VTABLE_set_integer_keyed_int(interp, array, 2, info.st_mode);
+ VTABLE_set_integer_keyed_int(interp, array, 3, info.st_nlink);
+ VTABLE_set_integer_keyed_int(interp, array, 4, info.st_uid);
+ VTABLE_set_integer_keyed_int(interp, array, 5, info.st_gid);
+ VTABLE_set_integer_keyed_int(interp, array, 6, info.st_rdev);
+ VTABLE_set_integer_keyed_int(interp, array, 7, info.st_size);
+ VTABLE_set_integer_keyed_int(interp, array, 8, info.st_atime);
+ VTABLE_set_integer_keyed_int(interp, array, 9, info.st_mtime);
+ VTABLE_set_integer_keyed_int(interp, array,10, info.st_ctime);
#ifndef WIN32
- VTABLE_set_integer_keyed_int(interp, array,11,
- info.st_blksize);
- VTABLE_set_integer_keyed_int(interp, array,12,
- info.st_blocks);
+ VTABLE_set_integer_keyed_int(interp, array,11, info.st_blksize);
+ VTABLE_set_integer_keyed_int(interp, array,12, info.st_blocks);
#endif
return array;
}
@@ -352,10 +325,12 @@ Creates a symlink, where available
METHOD void symlink(STRING *from, STRING *to) {
#ifndef WIN32
char *cfrom = string_to_cstring(interp, from);
- char *cto = string_to_cstring(interp, to);
- int error = symlink(cfrom, cto);
+ char *cto = string_to_cstring(interp, to);
+ int error = symlink(cfrom, cto);
+
string_cstring_free(cfrom);
string_cstring_free(cto);
+
if (error) {
char *errmsg = strerror(errno);
real_exception(interp, NULL, E_SystemError, errmsg);
@@ -379,10 +354,12 @@ Creates a hard link, where available(?)
METHOD void link(STRING *from, STRING *to) {
#ifndef WIN32
char *cfrom = string_to_cstring(interp, from);
- char *cto = string_to_cstring(interp, to);
- int error = link(cfrom, cto);
+ char *cto = string_to_cstring(interp, to);
+ int error = link(cfrom, cto);
+
string_cstring_free(cfrom);
string_cstring_free(cto);
+
if (error) {
char *errmsg = strerror(errno);
real_exception(interp, NULL, E_SystemError, errmsg);
@@ -431,8 +408,10 @@ idea to do the same with parrot.
METHOD void chroot(STRING *path) {
#ifndef WIN32
char *cpath = string_to_cstring(interp, path);
- int error = chroot(cpath);
+ int error = chroot(cpath);
+
string_cstring_free(cpath);
+
if (error) {
char *errmsg = strerror(errno);
real_exception(interp, NULL, E_SystemError, errmsg);
@@ -455,23 +434,22 @@ reads entries from a directory.
*/
METHOD PMC *readdir(STRING *path) {
#ifndef _MSC_VER
- DIR *dir ;
struct dirent *dirent;
- PMC *array;
- char *cpath = string_to_cstring(interp, path);
- STRING *retval ;
+ PMC *array;
+ char *cpath = string_to_cstring(interp, path);
+ STRING *retval;
+ DIR *dir = opendir(cpath);
- dir = opendir(cpath);
string_cstring_free(cpath);
- if (dir == NULL)
- {
+
+ if (!dir) {
char *errmsg = strerror(errno);
real_exception(interp, NULL, E_SystemError, errmsg);
}
array = pmc_new(interp, enum_class_ResizableStringArray);
- while ((dirent = readdir(dir)) != NULL)
- {
+
+ while ((dirent = readdir(dir)) != NULL) {
retval = string_from_cstring(interp, dirent->d_name, 0) ;
VTABLE_push_string(interp, array, retval);
}
@@ -481,7 +459,7 @@ reads entries from a directory.
return array ;
#else
real_exception(interp, NULL, E_NotImplementedError,
- "Win32 is not POSIX. Need win32 developer!");
+ "Win32 is not POSIX. Need Win32 developer!");
#endif
}
/*
@@ -495,9 +473,7 @@ thrown.
METHOD void rename(STRING *oldpath, STRING *newpath) {
char *coldpath = string_to_cstring(interp, oldpath);
char *cnewpath = string_to_cstring(interp, newpath);
- int ret;
-
- ret = rename(coldpath, cnewpath);
+ int ret = rename(coldpath, cnewpath);
string_cstring_free(coldpath);
string_cstring_free(cnewpath);
@@ -509,6 +485,7 @@ thrown.
}
}
+
/*
=back
View
103 src/pmc/resizablestringarray.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2005, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -8,11 +8,11 @@ src/pmc/resizablestringarray.pmc - resizable array for strings only
=head1 DESCRIPTION
-ResizableStringArray implements a resizeable array which stores Parrot
-strings only. Any ints or floats assigned to elements of the array will
-first be converted to String PMCs and then to native Parrot strings.
-PMCs assigned to to elements of the array will be stringified by having
-their C<get_string> method called.
+ResizableStringArray implements a resizeable array which stores Parrot strings
+only. Any ints or floats assigned to elements of the array will first be
+converted to String PMCs and then to native Parrot strings. PMCs assigned to
+to elements of the array will be stringified by having their C<get_string>
+method called.
=head2 Functions
@@ -38,8 +38,8 @@ Returns the Parrot string value of the element at index C<key>.
STRING *get_string_keyed_int(INTVAL key) {
STRING **data;
- if (key < 0)
- {
+
+ if (key < 0) {
INTVAL size = DYNSELF.elements();
if (key < -size)
real_exception(INTERP, NULL, E_IndexError,
@@ -47,12 +47,15 @@ Returns the Parrot string value of the element at index C<key>.
else
key += size;
}
+
if (key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1);
data = (STRING**)PMC_data(SELF);
+
if (!data[key])
data[key] = string_from_cstring(interp, NULL, 0);
+
return data[key];
}
@@ -68,8 +71,8 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
void set_string_keyed_int(INTVAL key, STRING *value) {
STRING **data;
- if (key < 0)
- {
+
+ if (key < 0) {
INTVAL size = DYNSELF.elements();
if (key < -size)
real_exception(INTERP, NULL, E_IndexError,
@@ -77,10 +80,11 @@ Sets the Parrot string value of the element at index C<key> to C<value>.
else
key += size;
}
+
if (key >= PMC_int_val(SELF))
DYNSELF.set_integer_native(key+1);
- data = (STRING**)PMC_data(SELF);
+ data = (STRING **)PMC_data(SELF);
DOD_WRITE_BARRIER(INTERP, SELF, data[key], value);
data[key] = value;
}
@@ -112,15 +116,15 @@ Removes and returns the last element in the array.
*/
STRING *pop_string() {
- INTVAL size;
+ INTVAL size = PMC_int_val(SELF);
STRING *value;
- size = PMC_int_val(SELF);
if (size == 0) {
real_exception(INTERP, NULL, E_IndexError,
"ResizableStringArray: Can't pop from an empty array!");
}
- value = DYNSELF.get_string_keyed_int(size-1);
+
+ value = DYNSELF.get_string_keyed_int(size - 1);
DYNSELF.set_integer_native(size - 1);
return value;
}
@@ -155,9 +159,8 @@ Removes and returns the last element in the array.
*/
INTVAL pop_integer() {
- PMC *pmcval = DYNSELF.pop_pmc();
- INTVAL value = VTABLE_get_integer(INTERP, pmcval);
- return value;
+ PMC *pmcval = DYNSELF.pop_pmc();
+ return VTABLE_get_integer(INTERP, pmcval);
}
/*
@@ -171,9 +174,8 @@ Removes and returns the last element in the array.
*/
FLOATVAL pop_float() {
- PMC *pmcval = DYNSELF.pop_pmc();
- FLOATVAL value = VTABLE_get_number(INTERP, pmcval);
- return value;
+ PMC *pmcval = DYNSELF.pop_pmc();
+ return VTABLE_get_number(INTERP, pmcval);
}
/*
@@ -195,7 +197,7 @@ Resizes the array to C<size> elements.
/* empty - used fixed routine */
if (size < 8) {
SUPER(8);
- PMC_int_val(SELF) = size;
+ PMC_int_val(SELF) = size;
PMC_int_val2(SELF) = 8;
}
else {
@@ -219,20 +221,24 @@ Resizes the array to C<size> elements.
return;
}
else {
- INTVAL i, cur;
- i = cur = PMC_int_val2(SELF);
+ INTVAL i = PMC_int_val2(SELF);
+ INTVAL cur = i;
+
if (cur < 8192)
cur = size < 2 * cur ? 2 * cur : size;
else {
cur = size + 4096;
cur &= ~0xfff;
}
+
PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF),
cur * sizeof (STRING*));
+
for (; i < cur; i++)
- ((STRING**)PMC_data(SELF))[i] = NULL;
+ ((STRING **)PMC_data(SELF))[i] = NULL;
+
PMC_int_val2(SELF) = cur;
- PMC_int_val(SELF) = size;
+ PMC_int_val(SELF) = size;
}
}
@@ -264,10 +270,9 @@ Removes and returns an item from the start of the array.
*/
STRING *shift_string() {
- INTVAL size;
+ INTVAL size = PMC_int_val(SELF);
STRING *value;
- size = PMC_int_val(SELF);
if (size == 0)
real_exception(INTERP, NULL, E_IndexError,
"ResizableStringArray: Can't shift from an empty array!");
@@ -307,9 +312,8 @@ Removes and returns the first element in the array.
*/
INTVAL shift_integer() {
- PMC *pmcval = DYNSELF.shift_pmc();
- INTVAL value = VTABLE_get_integer(INTERP, pmcval);
- return value;
+ PMC *pmcval = DYNSELF.shift_pmc();
+ return VTABLE_get_integer(INTERP, pmcval);
}
/*
@@ -323,9 +327,8 @@ Removes and returns the first element in the array.
*/
FLOATVAL shift_float() {
- PMC *pmcval = DYNSELF.shift_pmc();
- FLOATVAL value = VTABLE_get_number(INTERP, pmcval);
- return value;
+ PMC *pmcval = DYNSELF.shift_pmc();
+ return VTABLE_get_number(INTERP, pmcval);
}
@@ -357,10 +360,9 @@ the array.
*/
void push_integer(INTVAL value) {
- PMC *ret;
+ PMC *ret = pmc_new(INTERP, enum_class_String);
STRING *val;
- ret = pmc_new(INTERP, enum_class_String);
VTABLE_set_integer_native(INTERP, ret, value);
val = VTABLE_get_string(INTERP, ret);
DYNSELF.push_string(val);
@@ -378,10 +380,9 @@ the array.
*/
void push_float(FLOATVAL value) {
- PMC *ret;
+ PMC *ret = pmc_new(INTERP, enum_class_String);
STRING *val;
- ret = pmc_new(INTERP, enum_class_String);
VTABLE_set_number_native(INTERP, ret, value);
val = VTABLE_get_string(INTERP, ret);
DYNSELF.push_string(val);
@@ -398,19 +399,20 @@ Removes and returns a String PMC from the start of the array.
*/
PMC *shift_pmc() {
- INTVAL size;
- PMC *ret;
+ INTVAL size = PMC_int_val(SELF);
+ PMC *ret;
STRING *value;
- size = PMC_int_val(SELF);
if (size == 0)
real_exception(INTERP, NULL, E_IndexError,
"ResizableStringArray: Can't shift from an empty array!");
value = DYNSELF.get_string_keyed_int(0);
- ret = pmc_new(INTERP, enum_class_String);
+ ret = pmc_new(INTERP, enum_class_String);
+
VTABLE_set_string_native(INTERP, ret, value);
DYNSELF.delete_keyed_int(0);
+
return ret;
}
@@ -470,10 +472,9 @@ the array.
*/
void unshift_integer(INTVAL value) {
- PMC *ret;
+ PMC *ret = pmc_new(INTERP, enum_class_String);
STRING *val;
- ret = pmc_new(INTERP, enum_class_String);
VTABLE_set_integer_native(INTERP, ret, value);
val = VTABLE_get_string(INTERP, ret);
DYNSELF.unshift_string(val);
@@ -491,10 +492,9 @@ the array.
*/
void unshift_float(FLOATVAL value) {
- PMC *ret;
+ PMC *ret = pmc_new(INTERP, enum_class_String);
STRING *val;
- ret = pmc_new(INTERP, enum_class_String);
VTABLE_set_number_native(INTERP, ret, value);
val = VTABLE_get_string(INTERP, ret);
DYNSELF.unshift_string(val);
@@ -574,38 +574,39 @@ everything via the VTABLE api.
/* start from end? */
if (offset < 0)
offset += length;
+
if (offset < 0)
- real_exception(INTERP, NULL, OUT_OF_BOUNDS, "illegal splice offset\n");
+ real_exception(INTERP, NULL, OUT_OF_BOUNDS,
+ "illegal splice offset\n");
/* shrink the array */
if (shift < 0) {
/* start at offset so we don't overwrite values we'll need */
- for (i=offset+count; i<length; i++)
+ for (i = offset+count; i < length; i++)
VTABLE_set_pmc_keyed_int(INTERP, SELF, i + shift,
VTABLE_get_pmc_keyed_int(INTERP, SELF, i));
DYNSELF.set_integer_native(length + shift);
}
+
/* grow the array */
else if (shift > 0) {
DYNSELF.set_integer_native(length + shift);
/* move the existing values */
/* start at length-1 so we don't overwrite values we'll need */
- for (i=length-1; i>=offset; i--)
+ for (i = length - 1; i >= offset; i--)
VTABLE_set_pmc_keyed_int(INTERP, SELF, i + shift,
VTABLE_get_pmc_keyed_int(INTERP, SELF, i));
}
/* copy the new values */
- for (i=0; i<elems; i++)
+ for (i = 0; i < elems; i++)
VTABLE_set_pmc_keyed_int(INTERP, SELF, i + offset,
VTABLE_get_pmc_keyed_int(INTERP, value, i));
}
}
-
-
/*
=back
Please sign in to comment.
Something went wrong with that request. Please try again.