Skip to content
Browse files

[PMC] Minor cleanups and tidyings.

git-svn-id: https://svn.parrot.org/parrot/trunk@20925 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent c0d00f8 commit 82c7cf6593cefa8df71c74320a924fea63520396 @chromatic chromatic committed Aug 30, 2007
Showing with 110 additions and 84 deletions.
  1. +18 −20 src/pmc/bound_nci.pmc
  2. +17 −10 src/pmc/delegate.pmc
  3. +14 −14 src/pmc/exception_handler.pmc
  4. +17 −16 src/pmc/multiarray.pmc
  5. +14 −7 src/pmc/nci.pmc
  6. +11 −8 src/pmc/parrotthread.pmc
  7. +19 −9 src/pmc/tqueue.pmc
View
38 src/pmc/bound_nci.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -66,29 +66,27 @@ Set the bound object live.
}
else {
/* Locate register holding invocant. */
- int sig_const = interp->current_args[1];
- PMC *sig = CONTEXT(interp->ctx)->constants[sig_const]->u.key;
- if (!PMC_IS_NULL(sig)) {
- /* Ensure it's a signature. */
- ASSERT_SIG_PMC(sig);
-
- /* Get invocant register. */
- if (SIG_ELEMS(sig) > 0 && SIG_ITEM(sig, 0) & PARROT_ARG_PMC) {
- int invocant_reg = interp->current_args[2];
- PMC *p2 = REG_PMC(interp, invocant_reg);
- INTERP->current_object = REG_PMC(interp, invocant_reg)
+ int sig_const = interp->current_args[1];
+ PMC *sig = CONTEXT(interp->ctx)->constants[sig_const]->u.key;
+
+ if (PMC_IS_NULL(sig))
+ real_exception(interp, NULL, INVALID_OPERATION,
+ "Bound NCI call made, but no current signature found.");
+
+ ASSERT_SIG_PMC(sig);
+
+ /* Get invocant register. */
+ if (SIG_ELEMS(sig) > 0 && SIG_ITEM(sig, 0) & PARROT_ARG_PMC) {
+ int invocant_reg = interp->current_args[2];
+ PMC *p2 = REG_PMC(interp, invocant_reg);
+ INTERP->current_object = REG_PMC(interp, invocant_reg)
= PMC_pmc_val(SELF);
- SUPER(next);
- REG_PMC(interp, invocant_reg) = p2;
- }
- else {
- real_exception(interp, NULL, INVALID_OPERATION,
- "Bound NCI call made, but the current call has no invocant.");
- }
+ SUPER(next);
+ REG_PMC(interp, invocant_reg) = p2;
}
else {
real_exception(interp, NULL, INVALID_OPERATION,
- "Bound NCI call made, but no current signature found.");
+ "Bound NCI call made, but the current call has no invocant.");
}
}
View
27 src/pmc/delegate.pmc
@@ -77,25 +77,30 @@ useful defaults and don't throw exceptions.
void init() {
- STRING *const meth = CONST_STRING(interp, "init");
- PMC *const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+ STRING * const meth = CONST_STRING(interp, "init");
+ PMC * const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+
if (!PMC_IS_NULL(sub))
Parrot_run_meth_fromc(interp, sub, SELF, meth);
}
void init_pmc(PMC *initializer) {
- STRING *const meth = CONST_STRING(interp, "init_pmc");
- PMC *const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+ STRING * const meth = CONST_STRING(interp, "init_pmc");
+ PMC * const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+
if (!PMC_IS_NULL(sub))
- Parrot_run_meth_fromc_args(interp, sub, pmc, meth, "vP", initializer);
+ Parrot_run_meth_fromc_args(interp, sub, pmc, meth,
+ "vP", initializer);
}
PMC *instantiate(PMC *sig) {
- STRING *const meth = CONST_STRING(interp, "instantiate");
- PMC *const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+ STRING * const meth = CONST_STRING(interp, "instantiate");
+ PMC * const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+
if (PMC_IS_NULL(sub))
return SUPER(sig);
- return (PMC*) Parrot_run_meth_fromc(INTERP, sub, SELF, meth);
+
+ return (PMC *)Parrot_run_meth_fromc(INTERP, sub, SELF, meth);
}
void destroy() {
@@ -140,10 +145,12 @@ Invokes a subroutine.
*/
opcode_t *invoke(void *next) {
- STRING *const meth = CONST_STRING(interp, "invoke");
- PMC *const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+ STRING * const meth = CONST_STRING(interp, "invoke");
+ PMC * const sub = Parrot_find_vtable_meth(INTERP, SELF, meth);
+
if (PMC_IS_NULL(sub))
vtable_meth_not_found(INTERP, SELF, "invoke");
+
INTERP->current_object = SELF;
return VTABLE_invoke(interp, sub, next);
}
View
28 src/pmc/exception_handler.pmc
@@ -27,11 +27,13 @@ static opcode_t *
pass_exception_args(PARROT_INTERP, const char *sig,
opcode_t *dest, parrot_context_t * old_ctx, ...)
{
- va_list ap;
+ va_list ap;
opcode_t *next;
+
va_start(ap, old_ctx);
next = parrot_pass_args_fromc(interp, sig, dest, old_ctx, ap);
va_end(ap);
+
return next;
}
@@ -50,13 +52,11 @@ Initializes the exception handler.
void init() {
PMC_struct_val(SELF) = new_continuation(INTERP, NULL);
PMC_pmc_val(SELF) = PMCNULL;
- /*
- * an exception handler has no separate context, its
- * only a snapshot of an "earlier" context, which is
- * contained in the interpreter's context - the stacks
- * can only be deeper in the interpreter - so no
- * mark of context is needed
- */
+
+ /* an exception handler has no separate context; it's only a snapshot
+ * of an "earlier" context, which is contained in the interpreter's
+ * context - the stacks can only be deeper in the interpreter - so no
+ * mark of context is needed */
PObj_active_destroy_SET(SELF);
}
@@ -65,12 +65,13 @@ Initializes the exception handler.
* XXX fix ref_count handling for exception_handlers first
*
* An Exception_Handler is kind of a limited Continuation
- * (can only call 'up the stack') Therefore we probably don't
+ * (can only call 'up the stack'). Therefore we probably don't
* have to convert all RetContinuations to real Continuations
*/
void destroy() {
- struct Parrot_cont *cc = PMC_cont(SELF);
+ Parrot_cont *cc = PMC_cont(SELF);
+
if (cc) {
mem_sys_free(cc);
PMC_struct_val(SELF) = NULL;
@@ -84,7 +85,7 @@ Initializes the exception handler.
}
opcode_t *invoke(void *ex) {
- struct Parrot_cont *cc = PMC_cont(SELF);
+ Parrot_cont *cc = PMC_cont(SELF);
PMC *exception = (PMC *)ex;
opcode_t *next = NULL;
parrot_context_t *ex_ctx;
@@ -96,9 +97,8 @@ Initializes the exception handler.
results = cc->current_results;
/* clear all results, so that continuation.invoke
- * doesn't pass any args #'
- */
- cc->to_ctx->current_results = cc->current_results= NULL;
+ * doesn't pass any args #' */
+ cc->to_ctx->current_results = cc->current_results = NULL;
ex_ctx = CONTEXT(INTERP->ctx);
next = SUPER(next);
View
33 src/pmc/multiarray.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -18,8 +18,8 @@ Algorithm:
i + j*Ni + k*Ni*Nj + l*Ni*Nj*Nk ...
-where i,j,k,l... are coordinates in a multidimensional space and
-Ni,Nj,Nk... are the lengths of the dimensions.
+where i, j, k, l... are coordinates in a multidimensional space and
+Ni, Nj, Nk... are the lengths of the dimensions.
Limitations: the array can only expand in the last dimension The first
(n-1) dimensions of a n-dimensional array are fixed and layed out at
@@ -47,19 +47,20 @@ Calculates the offset for C<*key>.
static INTVAL calc_offset(PARROT_INTERP, List*list, PMC *key)
{
- INTVAL l;
- INTVAL ninj;
- PMC *dim = VTABLE_get_pmc_keyed_int(interp, list->user_data, 1);
+ PMC *dim = VTABLE_get_pmc_keyed_int(interp, list->user_data, 1);
+ INTVAL l = key_integer(interp, key);
+ INTVAL ninj = 1;
- l = key_integer(interp, key);
- ninj = 1;
for (; dim ; dim = key_next(interp, dim)) {
key = key_next(interp, key);
+
if (!key)
break;
+
ninj *= key_integer(interp, dim);
- l += key_integer(interp, key) * ninj;
+ l += key_integer(interp, key) * ninj;
}
+
return l;
}
@@ -90,7 +91,7 @@ Returns the integer value for C<*key>.
*/
INTVAL get_integer_keyed(PMC *key) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
return DYNSELF.get_integer_keyed_int(ix);
}
@@ -105,7 +106,7 @@ Returns the floating-point number value for C<*key>.
*/
FLOATVAL get_number_keyed(PMC *key) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
return DYNSELF.get_number_keyed_int(ix);
}
@@ -120,7 +121,7 @@ Returns the Parrot string value for C<*key>.
*/
STRING *get_string_keyed(PMC *key) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
return DYNSELF.get_string_keyed_int(ix);
}
@@ -135,7 +136,7 @@ Returns the PMC value for C<*key>.
*/
PMC *get_pmc_keyed(PMC *key) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
return DYNSELF.get_pmc_keyed_int(ix);
}
@@ -150,7 +151,7 @@ Sets the integer value C<value> at C<*key>.
*/
void set_integer_keyed(PMC *key, INTVAL value) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
DYNSELF.set_integer_keyed_int(ix, value);
}
@@ -165,7 +166,7 @@ Sets the floating-point number value C<value> at C<*key>.
*/
void set_number_keyed(PMC *key, FLOATVAL value) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
DYNSELF.set_number_keyed_int(ix, value);
}
@@ -180,7 +181,7 @@ Sets the Parrot string value C<value> at C<*key>.
*/
void set_string_keyed(PMC *key, STRING *value) {
- INTVAL ix = calc_offset(INTERP, (List*) PMC_data(SELF), key);
+ INTVAL ix = calc_offset(INTERP, (List *)PMC_data(SELF), key);
DYNSELF.set_string_keyed_int(ix, value);
}
View
21 src/pmc/nci.pmc
@@ -66,7 +66,7 @@ Initializes the NCI with a C<NULL> function pointer.
void init() {
PMC_struct_val(SELF) = NULL;
- PMC_pmc_val(SELF) = NULL;
+ PMC_pmc_val(SELF) = PMCNULL;
PObj_flag_CLEAR(private2, SELF);
}
@@ -83,7 +83,7 @@ Sets the specified function pointer and signature (C<*key>).
void set_pointer_keyed_str(STRING *key, void *func) {
/* key = signature */
PMC_struct_val(SELF) = func;
- PMC_data(SELF) = build_call_func(INTERP, SELF, key);
+ PMC_data(SELF) = build_call_func(INTERP, SELF, key);
}
/*
@@ -112,15 +112,17 @@ Creates and returns a clone of the NCI.
*/
PMC *clone() {
- PMC * const ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+ PMC * const ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PMC_struct_val(ret) = PMC_struct_val(SELF);
- PMC_pmc_val(ret) = NULL;
+ PMC_pmc_val(ret) = PMCNULL;
+
/* FIXME if data is malloced (JIT/i386!) then we need
* the length of data here, to memcpy it
* ManagedStruct or Buffer?
*/
- PMC_data(ret) = PMC_data(SELF);
+ PMC_data(ret) = PMC_data(SELF);
PObj_get_FLAGS(ret) |= (PObj_get_FLAGS(SELF) & 0x7);
+
return ret;
}
@@ -135,7 +137,7 @@ Returns whether the NCI is defined.
*/
INTVAL defined() {
- return PMC_data(SELF) != NULL;
+ return PMC_data(SELF) ? !PMC_IS_NULL(PMC_data(SELF)) : 0;
}
/*
@@ -152,16 +154,20 @@ shifted down.
opcode_t *invoke(void *next) {
typedef INTVAL(*nci_sub_t)(PARROT_INTERP, PMC *);
+
nci_sub_t func = PObj_flag_TEST(private2, SELF)
? (nci_sub_t) PMC_struct_val(SELF)
: PMC_data_typed(SELF, nci_sub_t);
+
PMC *cont;
if (!func)
real_exception(INTERP, NULL, INVALID_OPERATION,
"attempt to call NULL function");
+
func(INTERP, SELF);
cont = INTERP->current_cont;
+
/*
* If the NCI function was tailcalled, the return result
* is already passed back to the caller of this frame
@@ -174,6 +180,7 @@ shifted down.
cont = CONTEXT(interp->ctx)->current_cont;
next = VTABLE_invoke(INTERP, cont, next);
}
+
return (opcode_t *)next;
}
@@ -188,7 +195,7 @@ Returns the function pointer as an integer.
*/
INTVAL get_integer() {
- return ((INTVAL)PMC_data(SELF));
+ return (INTVAL)PMC_data(SELF);
}
/*
View
19 src/pmc/parrotthread.pmc
@@ -11,12 +11,12 @@ src/pmc/parrotthread.pmc - Threaded Interpreter
ParrotThread extends ParrotInterpreter to provide a threaded interpreter
which supports:
- new P2, .ParrotThread # create new threaded interp
- find_method P0, P2, "thread3" # thread-run function
- find_global P5, "_th1" # locate thread function
- invoke # run thread
+ new P2, "ParrotThread" # create new threaded interp
+ find_method P0, P2, "thread3" # thread-run function
+ find_global P5, "_th1" # locate thread function
+ invoke # run thread
- set I0, P2 # get thread id
+ set I0, P2 # get thread id
and these methods:
@@ -60,18 +60,20 @@ stop_GC(Interp *parent, Interp *thread)
static INTVAL do_thread_run(PARROT_INTERP, PMC *thread,
INTVAL clone_flags, PMC *sub, PMC *args) {
- INTVAL tid;
+ INTVAL tid = VTABLE_get_integer(interp, thread);
- tid = VTABLE_get_integer(interp, thread);
clone_interpreter(PMC_data_typed(thread, Parrot_Interp),
interp, clone_flags);
+
interp->flags &= ~PARROT_THR_COPY_INTERP; /* XXX */
pt_thread_run(interp, thread, sub, args);
pmc_reuse(interp, thread, enum_class_ParrotRunningThread, 0);
+
PObj_active_destroy_CLEAR(thread);
PObj_custom_mark_CLEAR(thread);
PMC_int_val(thread) = tid;
+
return tid;
}
@@ -105,6 +107,7 @@ Equivalent to calling run with PARROT_CLONE_DEFAULT.
if (pass) {
register_nci_method(INTERP, typ,
F2DPTR(do_thread_run), "run", "IJOIP@");
+
/* XXX appropriate name given that this won't clone globals? */
register_nci_method(INTERP, typ,
F2DPTR(do_thread_run_clone_default), "run_clone", "IJOP@");
@@ -149,7 +152,7 @@ Create a new thread by cloning the passed interpreter.
SUPER(parent);
pt_add_to_interpreters(PMC_data_typed(parent, Parrot_Interp),
- PMC_data_typed(SELF, Parrot_Interp));
+ PMC_data_typed(SELF, Parrot_Interp));
UNLOCK(interpreter_array_mutex);
View
28 src/pmc/tqueue.pmc
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2003, The Perl Foundation.
+Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -9,11 +9,11 @@ src/pmc/tqueue.pmc - Threadsafe Queue
=head1 DESCRIPTION
Threadsafe queue class for inter thread communication. If you have an
-unthreaded program then please use a PerlArray.
+unthreaded program then please use an Array-like PMC.
- new P0, .TQueue
+ new P0, 'TQueue'
push P0, some
- new P2, .ParrotThread
+ new P2, 'ParrotThread'
...
and in other thread (at least, when shared PMCs work :)
@@ -46,7 +46,7 @@ Initializes the queue.
void init() {
PMC_int_val(SELF) = 0;
- PMC_data(SELF) = queue_init(0);
+ PMC_data(SELF) = queue_init(0);
PObj_custom_mark_destroy_SETALL(SELF);
}
@@ -83,9 +83,11 @@ Marks all the threads in the queue as live.
entry = queue->head;
while (entry) {
- pobject_lives(INTERP, (PObj*) entry->data);
+ pobject_lives(INTERP, (PObj *)entry->data);
+
if (entry == queue->tail)
break;
+
entry = entry->next;
}
@@ -185,21 +187,26 @@ Adds the thread C<*item> to the end of the queue.
VTABLE_share(INTERP, item);
DOD_WRITE_BARRIER(INTERP, SELF, NULL, item);
+
entry->data = item;
entry->type = QUEUE_ENTRY_TYPE_NONE;
+
/* s. tsq.c:queue_push */
queue_lock(queue);
++PMC_int_val(SELF);
+
/* Is there something in the queue? */
if (queue->tail) {
queue->tail->next = entry;
- queue->tail = entry;
+ queue->tail = entry;
}
else {
queue->head = entry;
queue->tail = entry;
}
- queue_broadcast(queue); /* signal all waiters */
+
+ /* signal all waiters */
+ queue_broadcast(queue);
queue_unlock(queue);
}
@@ -214,18 +221,21 @@ Removes the first thread from the start of the queue.
*/
PMC *shift_pmc() {
- QUEUE_ENTRY *entry;
QUEUE *queue = PMC_data_typed(SELF, QUEUE *);
+ QUEUE_ENTRY *entry;
PMC *ret;
queue_lock(queue);
+
while (queue->head == NULL) {
queue_wait(queue);
}
entry = nosync_pop_entry(queue);
--PMC_int_val(SELF);
+
queue_unlock(queue);
+
ret = (PMC *)entry->data;
mem_sys_free(entry);

0 comments on commit 82c7cf6

Please sign in to comment.
Something went wrong with that request. Please try again.