cvsuser 05/01/03 08:16:14
Modified: dynclasses pybuiltin.pmc pyconsts.h pylist.pmc pyobject.pmc
pystring.pmc pytuple.pmc pytype.pmc
languages/python README
Log:
More progress towards t/pie/b0.t
Revision Changes Path
1.40 +30 -1 parrot/dynclasses/pybuiltin.pmc
Index: pybuiltin.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pybuiltin.pmc,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- pybuiltin.pmc 3 Jan 2005 00:20:08 -0000 1.39
+++ pybuiltin.pmc 3 Jan 2005 16:16:02 -0000 1.40
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pybuiltin.pmc,v 1.39 2005/01/03 00:20:08 rubys Exp $
+$Id: pybuiltin.pmc,v 1.40 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -108,6 +108,7 @@
PyString_class = const_string(INTERP, "__class__");
PyString_call = const_string(INTERP, "__call__");
PyString_cmp = const_string(INTERP, "__cmp__");
+ PyString_dict = const_string(INTERP, "__dict__");
PyString_hex = const_string(INTERP, "__hex__");
PyString_hash = const_string(INTERP, "__hash__");
PyString_init = const_string(INTERP, "__init__");
@@ -506,6 +507,34 @@
/*
+=item C<PMC* "hasattr"(PMC *object, PMC *name)>
+
+Return whether the object has an attribute with the given name.
+
+=cut
+
+*/
+
+ METHOD PMC* hasattr(PMC *object, PMC *value) {
+ PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
+ new_internal_exception(INTERP);
+ push_new_c_exception_handler(INTERP, INTERP->exceptions);
+ if (!setjmp(INTERP->exceptions->destination)) {
+ VTABLE_get_attr_str(INTERP, object,
+ VTABLE_get_string(INTERP, value));
+ VTABLE_set_integer_native(INTERP, ret, 1);
+ } else {
+ Parrot_exception *exception = INTERP->exceptions;
+ if (exception->error != E_AttributeError) {
+ rethrow_c_exception(INTERP);
+ }
+ VTABLE_set_integer_native(INTERP, ret, 0);
+ }
+ return ret;
+ }
+
+/*
+
=item C<PMC* "hex"(PMC *value)>
Returns the hex representation of C<value>.
1.7 +1 -0 parrot/dynclasses/pyconsts.h
Index: pyconsts.h
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pyconsts.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- pyconsts.h 3 Jan 2005 00:20:08 -0000 1.6
+++ pyconsts.h 3 Jan 2005 16:16:02 -0000 1.7
@@ -50,6 +50,7 @@
PYVAR_SCOPE STRING *PyString_call;
PYVAR_SCOPE STRING *PyString_class;
PYVAR_SCOPE STRING *PyString_cmp;
+PYVAR_SCOPE STRING *PyString_dict;
PYVAR_SCOPE STRING *PyString_hex;
PYVAR_SCOPE STRING *PyString_hash;
PYVAR_SCOPE STRING *PyString_init;
1.20 +8 -3 parrot/dynclasses/pylist.pmc
Index: pylist.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pylist.pmc,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- pylist.pmc 3 Jan 2005 00:20:08 -0000 1.19
+++ pylist.pmc 3 Jan 2005 16:16:02 -0000 1.20
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pylist.pmc,v 1.19 2005/01/03 00:20:08 rubys Exp $
+$Id: pylist.pmc,v 1.20 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -211,9 +211,14 @@
list_delete(INTERP, list, start, end-start);
}
+ else if (key->vtable->base_type == PyBuiltin_PyInt) {
+ List *list = (List *)PMC_data(SELF);
+ INTVAL index = VTABLE_get_integer(INTERP, key);
+ if (index<0) index = VTABLE_elements(INTERP, SELF) + index;
+ list_delete(INTERP, list, index, 1);
+ }
else
- internal_exception(OUT_OF_BOUNDS,
- "PyList: unimplemented delete!");
+ SUPER(key);
}
/*
1.17 +15 -1 parrot/dynclasses/pyobject.pmc
Index: pyobject.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pyobject.pmc,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- pyobject.pmc 3 Jan 2005 00:20:08 -0000 1.16
+++ pyobject.pmc 3 Jan 2005 16:16:02 -0000 1.17
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pyobject.pmc,v 1.16 2005/01/03 00:20:08 rubys Exp $
+$Id: pyobject.pmc,v 1.17 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -656,6 +656,20 @@
/*
+=item C<void logical_not(PMC *dest)>
+
+Returns in C<*dest> the result of the logical not of the scalar.
+
+=cut
+
+*/
+
+ void logical_not (PMC* dest) {
+ VTABLE_set_integer_native(INTERP, dest, !DYNSELF.get_bool());
+ }
+
+/*
+
=item C<void logical_or(PMC *value, PMC *dest)>
Returns in C<*dest> the result of the logical C<OR> of the scalar and
1.16 +121 -1 parrot/dynclasses/pystring.pmc
Index: pystring.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pystring.pmc,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- pystring.pmc 30 Dec 2004 11:46:38 -0000 1.15
+++ pystring.pmc 3 Jan 2005 16:16:02 -0000 1.16
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pystring.pmc,v 1.15 2004/12/30 11:46:38 rubys Exp $
+$Id: pystring.pmc,v 1.16 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -363,6 +363,126 @@
/*
+=item C<PMC* "isalpha"()>
+
+Return True if all characters in S are alphabetic and there is at least one
+character in S, False otherwise.
+
+=cut
+
+*/
+
+ METHOD PMC* isalpha () {
+ STRING *s = PMC_str_val(SELF);
+ UINTVAL length = string_length(INTERP, s);
+ UINTVAL idx ;
+ PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
+
+ VTABLE_set_integer_native(INTERP, ret, 0);
+
+ if (!length) return ret;
+
+ for (idx=0; idx<length; idx++) {
+ UINTVAL c = string_index(interpreter, s, idx);
+ if (!Parrot_char_is_alpha(INTERP, c)) return ret;
+ }
+
+ VTABLE_set_integer_native(INTERP, ret, 1);
+ return ret;
+ }
+
+/*
+
+=item C<PMC* "isalnum"()>
+
+Return True if all characters in S are alphabetic or numeric and there is at
+least one character in S, False otherwise.
+
+=cut
+
+*/
+
+ METHOD PMC* isalnum () {
+ STRING *s = PMC_str_val(SELF);
+ UINTVAL length = string_length(INTERP, s);
+ UINTVAL idx ;
+ PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
+
+ VTABLE_set_integer_native(INTERP, ret, 0);
+
+ if (!length) return ret;
+
+ for (idx=0; idx<length; idx++) {
+ UINTVAL c = string_index(interpreter, s, idx);
+ if (!Parrot_char_is_alnum(INTERP, c)) return ret;
+ }
+
+ VTABLE_set_integer_native(INTERP, ret, 1);
+ return ret;
+ }
+
+/*
+
+=item C<PMC* "isdigit"()>
+
+Return True if all characters in S are numeric and there is at
+least one character in S, False otherwise.
+
+=cut
+
+*/
+
+ METHOD PMC* isdigit () {
+ STRING *s = PMC_str_val(SELF);
+ UINTVAL length = string_length(INTERP, s);
+ UINTVAL idx ;
+ PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
+
+ VTABLE_set_integer_native(INTERP, ret, 0);
+
+ if (!length) return ret;
+
+ for (idx=0; idx<length; idx++) {
+ UINTVAL c = string_index(interpreter, s, idx);
+ if (!Parrot_char_is_digit(INTERP, c)) return ret;
+ }
+
+ VTABLE_set_integer_native(INTERP, ret, 1);
+ return ret;
+ }
+
+/*
+
+=item C<PMC* "isspace"()>
+
+Return True if all characters in S are whitespace and there is at least one
+character in S, False otherwise.
+
+=cut
+
+*/
+
+ METHOD PMC* isspace () {
+ STRING *s = PMC_str_val(SELF);
+ UINTVAL length = string_length(INTERP, s);
+ UINTVAL idx ;
+ PMC *ret = pmc_new(INTERP, PyBuiltin_PyBoolean);
+
+ VTABLE_set_integer_native(INTERP, ret, 0);
+
+ if (!length) return ret;
+
+ for (idx=0; idx<length; idx++) {
+ UINTVAL c = string_index(interpreter, s, idx);
+ if (!Parrot_char_is_space(INTERP, c)) return ret;
+ }
+
+ VTABLE_set_integer_native(INTERP, ret, 1);
+ return ret;
+ }
+
+/*
+
=item C<PMC* "lower"()>
downcase this string
1.11 +28 -1 parrot/dynclasses/pytuple.pmc
Index: pytuple.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pytuple.pmc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- pytuple.pmc 27 Dec 2004 16:21:18 -0000 1.10
+++ pytuple.pmc 3 Jan 2005 16:16:02 -0000 1.11
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pytuple.pmc,v 1.10 2004/12/27 16:21:18 rubys Exp $
+$Id: pytuple.pmc,v 1.11 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -270,6 +270,33 @@
/*
+=item C<INTVAL exists_keyed (PMC* value)>
+
+The C<==> operation. Compares two array to hold equal elements.
+
+=cut
+
+TODO: is this kosher? In Python the same operator is used to determine
+ if a key is in a dictionary or to determine if a value is in a
+ tuple.
+*/
+
+ INTVAL exists_keyed (PMC* value) {
+ INTVAL j, n;
+
+ n = SELF.elements();
+ for (j = 0; j < n; ++j) {
+ PMC *item = SELF.get_pmc_keyed_int(j);
+ if (item == value)
+ return 1;
+ if (mmd_dispatch_i_pp(INTERP, item, value, MMD_EQ))
+ return 1;
+ }
+ return 0;
+ }
+
+/*
+
=item C<void set_integer_keyed(PMC *key, INTVAL value)>
Sets the integer value of the element at index C<key> to C<value>.
1.13 +3 -1 parrot/dynclasses/pytype.pmc
Index: pytype.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/pytype.pmc,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- pytype.pmc 27 Dec 2004 16:21:18 -0000 1.12
+++ pytype.pmc 3 Jan 2005 16:16:02 -0000 1.13
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: pytype.pmc,v 1.12 2004/12/27 16:21:18 rubys Exp $
+$Id: pytype.pmc,v 1.13 2005/01/03 16:16:02 rubys Exp $
=head1 NAME
@@ -189,6 +189,8 @@
VTABLE_set_string_native(INTERP, nameprop, name);
VTABLE_setprop(INTERP, ret, PyString_name, nameprop);
VTABLE_setprop(INTERP, ret, PyString_bases, SELF);
+ VTABLE_setprop(INTERP, ret, PyString_dict,
+ VTABLE_getprops(INTERP, ret));
return ret;
}
1.13 +1 -0 parrot/languages/python/README
Index: README
===================================================================
RCS file: /cvs/public/parrot/languages/python/README,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- README 29 Dec 2004 14:12:20 -0000 1.12
+++ README 3 Jan 2005 16:16:14 -0000 1.13
@@ -26,6 +26,7 @@
isinstance VTABLE entry?
DOES for dynclasses
bounds checking
+ "in" dict vs "in" tuple vs exists_key
- Sam Ruby