Author: jonathan
Date: Fri Jul 18 03:30:13 2008
New Revision: 29579

Modified:
   trunk/runtime/parrot/library/P6object.pir
   trunk/t/library/p6object.t

Log:
[p6object] Support registration of anonymous classes. Add a few tests. Also 
eliminate an unused .local in the test file.

Modified: trunk/runtime/parrot/library/P6object.pir
==============================================================================
--- trunk/runtime/parrot/library/P6object.pir   (original)
+++ trunk/runtime/parrot/library/P6object.pir   Fri Jul 18 03:30:13 2008
@@ -359,8 +359,10 @@
     ##  save the protoobject
     setattribute how, 'protoobject', protoobject
 
-    ##  store the long and short names in the protoobject
+    ##  store the long and short names in the protoobject; skip if anonymous
     .local pmc longname, shortname
+    $I0 = elements ns
+    if $I0 == 0 goto anonymous_class
     $S0 = join '::', ns
     longname = new 'String'
     longname = $S0
@@ -371,6 +373,14 @@
     ##  store the protoobject in appropriate namespace
     $S0 = pop ns
     set_hll_global ns, $S0, protoobject
+    goto have_how
+
+    ##  anonymous classes have empty strings for shortname and longname
+  anonymous_class:
+    longname = new 'String'
+    shortname = new 'String'
+    setattribute how, 'longname', longname
+    setattribute how, 'shortname', shortname
 
   have_how:
     ##  map parrotclass to the metaobject

Modified: trunk/t/library/p6object.t
==============================================================================
--- trunk/t/library/p6object.t  (original)
+++ trunk/t/library/p6object.t  Fri Jul 18 03:30:13 2008
@@ -25,8 +25,7 @@
     test_namespace.'export_to'(curr_namespace, exports)
 
     ##  set our plan
-    .local int plan_tests
-    plan(107)
+    plan(110)
 
     ##  make sure we can load the P6object library
     push_eh load_failed
@@ -122,6 +121,14 @@
     $I0 = defined metaproto
     nok($I0, 'ABC proto undefined')
 
+    ##  create an anonymous class
+    $P0 = new 'Class'
+    $P1 = metaproto.'register'($P0)
+    isa_ok($P1, 'P6object', 'anonymous proto')
+    isa_ok($P1, 'P6protoobject', 'anonymous proto')
+    $S0 = $P1.'WHAT'()
+    is($S0, '', 'anonymous proto stringifies to empty string')
+
     ##  try the default .new method on ABC protoobject
     .local pmc abc
     abc = abcproto.'new'()

Reply via email to