[svn:parrot] r41316 - in trunk: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Thu Sep 17 09:04:27 UTC 2009


Author: bacek
Date: Thu Sep 17 09:04:26 2009
New Revision: 41316
URL: https://trac.parrot.org/parrot/changeset/41316

Log:
[core] Implement initialisation of Sub.arg_info in Sub.init_pmc

Modified:
   trunk/src/pmc/sub.pmc
   trunk/t/pmc/sub.t

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc	Thu Sep 17 09:03:57 2009	(r41315)
+++ trunk/src/pmc/sub.pmc	Thu Sep 17 09:04:26 2009	(r41316)
@@ -178,12 +178,30 @@
                 attrs->n_regs_used[i] = VTABLE_get_integer_keyed_int(INTERP, tmp, i);
         }
 
+        field = CONST_STRING(INTERP, "arg_info");
+        if (VTABLE_exists_keyed_str(INTERP, init, field)) {
+            PMC   *tmp = VTABLE_get_pmc_keyed_str(INTERP, init, field);
+            /* Allocate structure to store argument information in. */
+            attrs->arg_info = mem_allocate_zeroed_typed(Parrot_sub_arginfo);
+            /*
+            Hash.get_integer_keyed_str return 0 if key doesn't exists.
+            So, don't check existence of key, just use it.
+            NB: Don't split line. CONST_STRING b0rked.
+            */
+            attrs->arg_info->pos_required = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "pos_required"));
+            attrs->arg_info->pos_optional = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "pos_optional"));
+            attrs->arg_info->pos_slurpy = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "pos_slurpy"));
+            attrs->arg_info->named_required = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "named_required"));
+            attrs->arg_info->named_optional = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "named_optional"));
+            attrs->arg_info->named_slurpy = VTABLE_get_integer_keyed_str(INTERP, tmp, CONST_STRING(INTERP, "named_slurpy"));
+        }
+
+
         /*
         C<eval_pmc> and C<ctx> are not handled here. And shouldn't be handled
         here at all because of run-time nature.
         */
         
-        /* TODO Implement initialisation of arg_info via nested Hash */
         PObj_custom_mark_destroy_SETALL(SELF);
     }
 

Modified: trunk/t/pmc/sub.t
==============================================================================
--- trunk/t/pmc/sub.t	Thu Sep 17 09:03:57 2009	(r41315)
+++ trunk/t/pmc/sub.t	Thu Sep 17 09:04:26 2009	(r41316)
@@ -1636,7 +1636,7 @@
 
 pir_output_is( <<'CODE', <<'OUTPUT', 'init_pmc' );
 .sub 'main'
-    .local pmc init, s, regs
+    .local pmc init, s, regs, arg_info
     
     init = new ['Hash']
     init['start_offs']  = 42
@@ -1650,6 +1650,15 @@
     regs[3] = 24
     init['n_regs_used'] = regs
 
+    arg_info = new ['Hash']
+    arg_info['pos_required']    = 1
+    arg_info['pos_optional']    = 1
+    arg_info['pos_slurpy']      = 2
+    arg_info['named_required']  = 3
+    arg_info['named_optional']  = 5
+    arg_info['named_slurpy']    = 8
+    init['arg_info'] = arg_info
+
     s = new ['Sub'], init
 
     $I0 = s.'start_offs'()
@@ -1660,6 +1669,7 @@
     $I0 = s.'end_offs'()
     say $I0
 
+    # Check n_regs_used
     $I0 = s.'__get_regs_used'('I')
     print 'I regs '
     say $I0
@@ -1676,6 +1686,31 @@
     print 'P regs '
     say $I0
 
+    # Check arg_info
+    $P0 = inspect s, 'pos_required'
+    print 'pos_required '
+    say $P0
+
+    $P0 = inspect s, 'pos_optional'
+    print 'pos_optional '
+    say $P0
+    
+    $P0 = inspect s, 'pos_slurpy'
+    print 'pos_slurpy '
+    say $P0
+
+    $P0 = inspect s, 'named_required'
+    print 'named_required '
+    say $P0
+
+    $P0 = inspect s, 'named_optional'
+    print 'named_optional '
+    say $P0
+
+    $P0 = inspect s, 'named_slurpy'
+    print 'named_slurpy '
+    say $P0
+
     # We need more tests for other fields. And more accessors obviously.
 .end
 CODE
@@ -1685,6 +1720,12 @@
 N regs 2
 S regs 6
 P regs 24
+pos_required 1
+pos_optional 1
+pos_slurpy 2
+named_required 3
+named_optional 5
+named_slurpy 8
 OUTPUT
 
 # Local Variables:


More information about the parrot-commits mailing list