cvsuser 04/07/14 07:50:15
Modified: languages/python mdis.py pie-thon.pl
languages/python/t/basic oo_class.t
languages/python/t/pie b5.t
src objects.c
Log:
Pie-thon 66 - isinstance checks; some object hacks
Revision Changes Path
1.3 +6 -1 parrot/languages/python/mdis.py
Index: mdis.py
===================================================================
RCS file: /cvs/public/parrot/languages/python/mdis.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- mdis.py 14 Jul 2004 12:18:08 -0000 1.2
+++ mdis.py 14 Jul 2004 14:49:57 -0000 1.3
@@ -4,6 +4,7 @@
import sys
import types
+import inspect
from opcode import *
from opcode import __all__ as _opcodes_all
@@ -151,7 +152,11 @@
i = 'Build::' + i
break
print "Disassembly of %s" % i
- print "#dir %s" % dir(c)
+ print "# varnames ", c.co_varnames
+ print "# locals ", c.co_nlocals
+ print "# names ", c.co_names
+ print "# consts ", c.co_consts
+ print "# getargs ", inspect.getargs(c)
disassemble(c)
def disassemble_string(code, lasti=-1, varnames=None, names=None,
1.44 +4 -2 parrot/languages/python/pie-thon.pl
Index: pie-thon.pl
===================================================================
RCS file: /cvs/public/parrot/languages/python/pie-thon.pl,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -w -r1.43 -r1.44
--- pie-thon.pl 14 Jul 2004 12:18:08 -0000 1.43
+++ pie-thon.pl 14 Jul 2004 14:49:57 -0000 1.44
@@ -944,17 +944,19 @@
my ($n, $c, $cmt) = @_;
my $i = temp('I');
my $cl = pop @stack;
- my $ob = pop @stack;
+ my $ob = promote(pop @stack);
+ pop @stack; # functions
my $s = temp('S');
my $b = temp('P');
# TODO make op or function
print <<EOC;
$s = classname $cl->[1]
- $i = isa $ob->[1], $s
+ $i = isa $ob, $s
$b = new Boolean
$b = $i
EOC
push @stack, [-1, $b, 'P'];
+ print_stack();
}
sub CALL_FUNCTION
1.2 +14 -2 parrot/languages/python/t/basic/oo_class.t
Index: oo_class.t
===================================================================
RCS file: /cvs/public/parrot/languages/python/t/basic/oo_class.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- oo_class.t 14 Jul 2004 12:18:06 -0000 1.1
+++ oo_class.t 14 Jul 2004 14:50:01 -0000 1.2
@@ -1,9 +1,9 @@
-# $Id: oo_class.t,v 1.1 2004/07/14 12:18:06 leo Exp $
+# $Id: oo_class.t,v 1.2 2004/07/14 14:50:01 leo Exp $
use strict;
use lib '../../lib';
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 2;
sub test {
language_output_is('python', $_[0], '', $_[1]);
@@ -24,3 +24,15 @@
main()
CODE
+
+test(<<'CODE', 'object init from int parent class');
+class C(int):
+ pass
+
+def main():
+ i = C(2)
+ print i
+
+if __name__ == '__main__':
+ main()
+CODE
1.11 +29 -2 parrot/languages/python/t/pie/b5.t
Index: b5.t
===================================================================
RCS file: /cvs/public/parrot/languages/python/t/pie/b5.t,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- b5.t 13 Jul 2004 06:15:31 -0000 1.10
+++ b5.t 14 Jul 2004 14:50:11 -0000 1.11
@@ -1,9 +1,9 @@
-# $Id: b5.t,v 1.10 2004/07/13 06:15:31 leo Exp $
+# $Id: b5.t,v 1.11 2004/07/14 14:50:11 leo Exp $
use strict;
use lib '../../lib';
-use Parrot::Test tests => 14;
+use Parrot::Test tests => 15;
sub test {
language_output_is('python', $_[0], '', $_[1]);
@@ -375,4 +375,31 @@
main()
CODE
+test(<<'CODE', 'check isinstance');
+show = True
+
+def check(a, b):
+ if __debug__:
+ if show:
+ print `a`, "==", `b`
+ if not a == b:
+ raise AssertionError("%.30r != %.30r" % (a, b))
+
+def main():
+ check(isinstance(42, int), True)
+ check(isinstance(42, long), False)
+ check(isinstance(42L, int), False)
+ check(isinstance(42L, long), True)
+ check(isinstance(12345678910, int), False)
+ check(isinstance(12345678910, long), True)
+ check(isinstance(3.14, int), False)
+ check(isinstance(3.14, float), True)
+ # check(isinstance(int, type), True)
+ # check(isinstance(int, object), True)
+ # check(isinstance(type, object), True)
+
+if __name__ == '__main__':
+ main()
+
+CODE
1.103 +46 -3 parrot/src/objects.c
Index: objects.c
===================================================================
RCS file: /cvs/public/parrot/src/objects.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -w -r1.102 -r1.103
--- objects.c 14 Jul 2004 09:42:28 -0000 1.102
+++ objects.c 14 Jul 2004 14:50:15 -0000 1.103
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: objects.c,v 1.102 2004/07/14 09:42:28 leo Exp $
+$Id: objects.c,v 1.103 2004/07/14 14:50:15 leo Exp $
=head1 NAME
@@ -525,6 +525,41 @@
}
static void
+do_py_initcall(Parrot_Interp interpreter, PMC* class, PMC *object)
+{
+ SLOTTYPE *class_data = PMC_data(class);
+ PMC *classsearch_array = get_attrib_num(class_data, PCD_ALL_PARENTS);
+ PMC *parent_class;
+ INTVAL nparents;
+ STRING *meth_str;
+ PMC *meth;
+ PMC *arg = REG_PMC(5); /* TODO more args */
+
+ nparents = VTABLE_elements(interpreter, classsearch_array);
+ if (nparents) {
+ parent_class = VTABLE_get_pmc_keyed_int(interpreter,
+ classsearch_array, nparents - 1);
+ /* if its a PMC, we put one PMC of that type into
+ * the attribute slot #0.
+ */
+ if (!PObj_is_class_TEST(parent_class)) {
+ PMC *attr;
+ SLOTTYPE *obj_data = PMC_data(object);
+ VTABLE_invoke(interpreter, parent_class, NULL);
+ attr = REG_PMC(5);
+ set_attrib_num(obj_data, POD_FIRST_ATTRIB, attr);
+ }
+ }
+ meth_str = CONST_STRING(interpreter, "__init__");
+ meth = Parrot_find_method_with_cache(interpreter,
+ class, meth_str);
+ if (meth) {
+ Parrot_runops_fromc_args_save(interpreter, meth,
+ "vPP", object, arg);
+ }
+}
+
+static void
do_initcall(Parrot_Interp interpreter, PMC* class, PMC *object, PMC *init)
{
SLOTTYPE *class_data = PMC_data(class);
@@ -655,7 +690,7 @@
{
INTVAL type = class->vtable->base_type;
PMC *object = pmc_new_noinit(interpreter, type);
- VTABLE_init(interpreter, object);
+ instantiate_object(interpreter, object, (void*)-1);
REG_PMC(5) = object;
return next;
}
@@ -705,6 +740,14 @@
/* We really ought to call the class init routines here...
* this assumes that an object isa delegate
*/
+ if (init == (void*)-1) {
+ /*
+ * we are coming from Python
+ */
+ do_py_initcall(interpreter, class, object);
+
+ }
+ else
do_initcall(interpreter, class, object, init);
}