cvsuser 04/12/18 07:08:23
Modified: classes coroutine.pmc
dynclasses pydict.pmc pygen.pmc
languages/python Makefile README
languages/python/t/pie b2.t
src sub.c
Log:
parrot/languages/python/pie/b2.t passes
Revision Changes Path
1.46 +4 -109 parrot/classes/coroutine.pmc
Index: coroutine.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/coroutine.pmc,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- coroutine.pmc 25 Nov 2004 09:27:48 -0000 1.45
+++ coroutine.pmc 18 Dec 2004 15:08:18 -0000 1.46
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: coroutine.pmc,v 1.45 2004/11/25 09:27:48 leo Exp $
+$Id: coroutine.pmc,v 1.46 2004/12/18 15:08:18 rubys Exp $
=head1 NAME
@@ -18,7 +18,7 @@
=item private0 call flip flop
-=item private3 called first time, used for python
+=item private3 restore current sub after "flop". Used by generators.
=back
@@ -64,13 +64,6 @@
pmclass Coroutine extends Sub {
- void class_init() {
- if (pass) {
- enter_nci_method(INTERP, enum_class_Coroutine,
- F2DPTR(Parrot_Coroutine_shift_pmc), "next", "PIO");
- }
- }
-
/*
=item C<void init()>
@@ -85,9 +78,6 @@
PMC_coro(SELF) = new_coroutine(INTERP);
PMC_struct_val(SELF) = NULL;
PObj_custom_mark_destroy_SETALL(SELF);
-
- if (Interp_flags_TEST(INTERP, PARROT_PYTHON_MODE))
- PObj_get_FLAGS(SELF) |= SUB_FLAG_GENERATOR;
}
/*
@@ -105,23 +95,7 @@
struct PackFile_ByteCode *wanted_seg;
void * dest = sub->address;
int argcP = REG_INT(3);
- /* python calls the coroutine initially during
- * setup
- */
- if (PObj_get_FLAGS(SELF) & SUB_FLAG_GENERATOR) {
- PMC *ret = SELF.get_iter();
- struct Parrot_coro *cor = PMC_coro(ret);
- struct Stack_Chunk *pad_stack = cor->ctx.pad_stack;
- PMC *pad = stack_peek(INTERP, pad_stack, NULL);
- INTVAL i;
-
- for (i = 0; i < argcP; ++i) {
- scratchpad_store_by_index(INTERP, pad, -1, i, REG_PMC(5+i));
- }
- REG_PMC(5) = ret;
- cor->caller_seg = interpreter->code->cur_cs;
- return next;
- }
+
sub->address = next;
/* if calling the Coro we need the segment of the Coro */
if (!(PObj_get_FLAGS(SELF) & SUB_FLAG_CORO_FF)) {
@@ -131,6 +105,7 @@
}
else {
wanted_seg = sub->caller_seg;
+ sub->caller_seg = interpreter->code->cur_cs;
}
swap_context(interpreter, SELF);
@@ -142,86 +117,6 @@
/*
-=item C<PMC* shift_pmc>)
-
-Run the coroutine until it yields a value. The call to the coroutine
-is actually done via the C<call_hook> below, a piece of code at the
-end of a coroutine:
-
-set P0, P5 # get the real coroutine
-invokecc # run that code
-end # terminate the runloop
-
-=cut
-
-*/
-
- PMC* shift_pmc() {
- PMC *res;
- struct Parrot_coro * sub = PMC_coro(SELF);
- opcode_t offset, *call_hook;
- PMC *ex;
- PMC *p5 = REG_PMC(5);
-
- REG_PMC(5) = SELF;
- assert(sub->end);
- call_hook = sub->end - 5;
- offset = call_hook - interpreter->code->byte_code;
- /*
- * running via runops creates an exception frame
- * but we should catch exceptions here to free the register
- * frame
- * XXX
- */
- runops(interpreter, offset);
- res = REG_PMC(5);
- REG_PMC(5) = p5;
- /*
- * the generator returned None, when it's finished
- */
- if (REG_INT(3) == 1 &&
- res == Parrot_base_vtables[enum_class_None]->data) {
- real_exception(interpreter, NULL, E_StopIteration,
"StopIteration");
- }
- return res;
- }
-
-/*
-
-Iterator interface
-
-=item C<INTVAL elements ()>
-
-Return much, we don't know.
-
-*/
-
- INTVAL elements () {
- return (2^31) - 1;
- }
-
- PMC* get_iter () {
- if (PObj_get_FLAGS(SELF) & SUB_FLAG_GENERATOR) {
- struct Parrot_coro * sub = PMC_coro(SELF);
- PMC *ret = pmc_new(INTERP, enum_class_Coroutine);
- struct Parrot_coro * coro = PMC_coro(ret);
- coro->end = sub->end;
- coro->address = sub->address;
-
- PObj_get_FLAGS(ret) |= SUB_FLAG_FIXUP_DONE; /* fixup done */
- PObj_get_FLAGS(ret) &= ~SUB_FLAG_GENERATOR;
- PObj_flag_CLEAR(custom_mark, SELF);
- return ret;
- }
- return SELF;
- }
-
- INTVAL get_bool () {
- return 1;
- }
-
-/*
-
=item C<void mark()>
Marks the coroutine as live.
1.11 +51 -1 parrot/dynclasses/pydict.pmc
Index: pydict.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pydict.pmc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- pydict.pmc 18 Dec 2004 03:51:47 -0000 1.10
+++ pydict.pmc 18 Dec 2004 15:08:20 -0000 1.11
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pydict.pmc,v 1.10 2004/12/18 03:51:47 rubys Exp $
+$Id: pydict.pmc,v 1.11 2004/12/18 15:08:20 rubys Exp $
=head1 NAME
@@ -446,6 +446,56 @@
/*
+=item C<INTVAL is_equal(PMC *value)>
+
+The C<==> operation.
+
+Check if two dictionaries hold the same keys and values.
+
+=cut
+
+*/
+
+ INTVAL is_equal (PMC* value) {
+ PMC *iter = VTABLE_get_iter(INTERP, SELF);
+ INTVAL j, n;
+
+ if (value->vtable->base_type != SELF->vtable->base_type)
+ return 0;
+ n = SELF.elements();
+ if (VTABLE_elements(INTERP, value) != n)
+ return 0;
+ for (j = 0; j < n; ++j) {
+ STRING *key = VTABLE_shift_string(INTERP, iter);
+ PMC *item1, *item2;
+ if (!VTABLE_exists_keyed_str(INTERP, value, key))
+ return 0;
+ item1 = SELF.get_pmc_keyed_str(key);
+ item2 = VTABLE_get_pmc_keyed_str(INTERP, value, key);
+ if (item1 == item2)
+ continue;
+ if (!mmd_dispatch_i_pp(INTERP, item1, item2, MMD_EQ))
+ return 0;
+ }
+ return 1;
+ }
+
+/*
+
+=item C<INTVAL exists_keyed_str(STRING *key)>
+
+=cut
+
+*/
+
+ INTVAL exists_keyed_str(STRING* key) {
+ HashBucket *b = hash_get_bucket(INTERP, (Hash*) PMC_struct_val(SELF),
+ key);
+ return b != NULL;
+ }
+
+/*
+
=item C<void set_pmc_keyed(PMC *key, PMC *value)>
=cut
1.4 +2 -1 parrot/dynclasses/pygen.pmc
Index: pygen.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pygen.pmc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pygen.pmc 13 Dec 2004 21:50:58 -0000 1.3
+++ pygen.pmc 18 Dec 2004 15:08:20 -0000 1.4
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pygen.pmc,v 1.3 2004/12/13 21:50:58 rubys Exp $
+$Id: pygen.pmc,v 1.4 2004/12/18 15:08:20 rubys Exp $
=head1 NAME
@@ -158,6 +158,7 @@
void set_pmc (PMC* value) {
PMC_pmc_val(SELF) = value;
+ PObj_get_FLAGS(value) |= SUB_FLAG_GENERATOR;
}
/*
1.8 +1 -1 parrot/languages/python/Makefile
Index: Makefile
===================================================================
RCS file: /cvs/public/parrot/languages/python/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile 13 Dec 2004 21:50:59 -0000 1.7
+++ Makefile 18 Dec 2004 15:08:20 -0000 1.8
@@ -4,6 +4,6 @@
perl t/harness t/basic/*.t
testbench:
- perl t/harness t/pie/b1.t
+ perl t/harness t/pie/b[12].t
clean:
1.7 +1 -2 parrot/languages/python/README
Index: README
===================================================================
RCS file: /cvs/public/parrot/languages/python/README,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- README 15 Dec 2004 22:07:29 -0000 1.6
+++ README 18 Dec 2004 15:08:21 -0000 1.7
@@ -22,8 +22,7 @@
Benchmark status/issues:
b1: passes. Would perform better if xranges were implemented as an iter.
- b2: co-routine issue. main calls izip which calls PI which
- yields to izip which yields to... PI? WTF?
+ b2: passes.
b3: need to implement __new__
b4: there is no b4!
b5: awaiting completion of float, complex, ...
1.8 +2 -1 parrot/languages/python/t/pie/b2.t
Index: b2.t
===================================================================
RCS file: /cvs/public/parrot/languages/python/t/pie/b2.t,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- b2.t 8 Dec 2004 02:15:46 -0000 1.7
+++ b2.t 18 Dec 2004 15:08:22 -0000 1.8
@@ -1,4 +1,4 @@
-# $Id: b2.t,v 1.7 2004/12/08 02:15:46 rubys Exp $
+# $Id: b2.t,v 1.8 2004/12/18 15:08:22 rubys Exp $
use strict;
use lib '../../lib';
@@ -164,6 +164,7 @@
print y,
if x in tests:
checks[x] = pi.a1
+ print
if tests != checks:
raise RuntimeError
1.83 +2 -2 parrot/src/sub.c
Index: sub.c
===================================================================
RCS file: /cvs/public/parrot/src/sub.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- sub.c 25 Nov 2004 09:28:05 -0000 1.82
+++ sub.c 18 Dec 2004 15:08:22 -0000 1.83
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: sub.c,v 1.82 2004/11/25 09:28:05 leo Exp $
+$Id: sub.c,v 1.83 2004/12/18 15:08:22 rubys Exp $
=head1 NAME
@@ -182,7 +182,7 @@
*/
if (!interpreter->ctx.current_sub) {
copy_regs(interpreter, ctx->bp);
- ctx->current_sub = interpreter->ctx.current_sub = sub;
+ interpreter->ctx.current_sub = sub;
interpreter->ctx.current_cont = BP_REG_PMC(ctx->bp,1);
REG_PMC(0) = sub;
REG_PMC(1) = interpreter->ctx.current_cont;