[svn:parrot] r47753 - in branches/gsoc_instrument: src/dynpmc t/dynpmc

khairul at svn.parrot.org khairul at svn.parrot.org
Tue Jun 22 12:36:56 UTC 2010


Author: khairul
Date: Tue Jun 22 12:36:55 2010
New Revision: 47753
URL: https://trac.parrot.org/parrot/changeset/47753

Log:
Combined 4 methods into 1 method returning a hash of the current context information + updated test.

Modified:
   branches/gsoc_instrument/src/dynpmc/instrumentop.pmc
   branches/gsoc_instrument/t/dynpmc/instrumentop.t

Modified: branches/gsoc_instrument/src/dynpmc/instrumentop.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrumentop.pmc	Tue Jun 22 06:08:26 2010	(r47752)
+++ branches/gsoc_instrument/src/dynpmc/instrumentop.pmc	Tue Jun 22 12:36:55 2010	(r47753)
@@ -332,78 +332,36 @@
 
 /*
 
-=item C<STRING* file()>
+=item C<PMC* get_context_info()>
 
-Returns the filename where the current op resides in.
+Returns the following information in a Hash PMC gathered from the current context:
+1. sub
+2. namespace
+3. file
+4. line
 
 =cut
 
 */
 
-    METHOD file() {
+    METHOD get_context_info() {
         Parrot_InstrumentOp_attributes * const attr = PARROT_INSTRUMENTOP(SELF);
         Parrot_Context_info info;
+        PMC *ctx_hash;
 
         INTVAL ret = Parrot_Context_get_info(attr->interp, CURRENT_CONTEXT(attr->interp), &info);
-        STRING *file = info.file;
-        RETURN(STRING *file);
-    }
-
-/*
-
-=item C<INTVAL line()>
-
-Returns the line number of the file where the current op resides in.
-
-=cut
-
-*/
-
-    METHOD line() {
-        Parrot_InstrumentOp_attributes * const attr = PARROT_INSTRUMENTOP(SELF);
-        Parrot_Context_info info;
-
-        INTVAL ret = Parrot_Context_get_info(attr->interp, CURRENT_CONTEXT(attr->interp), &info);
-        INTVAL line = info.line;
-        RETURN(INTVAL line);
-    }
-
-/*
-
-=item C<STRING* sub()>
-
-Returns the name of the subroutine containing the current op.
-
-=cut
-
-*/
-
-    METHOD sub() {
-        Parrot_InstrumentOp_attributes * const attr = PARROT_INSTRUMENTOP(SELF);
-        Parrot_Context_info info;
-
-        INTVAL ret = Parrot_Context_get_info(attr->interp, CURRENT_CONTEXT(attr->interp), &info);
-        STRING *sub = info.subname;
-        RETURN(STRING *sub);
-    }
-
-/*
-
-=item C<STRING* sub()>
-
-Returns the namespace of the subroutine containing the current op.
-
-=cut
+        ctx_hash   = Parrot_pmc_new(INTERP, enum_class_Hash);
 
-*/
+        VTABLE_set_string_keyed_str(INTERP, ctx_hash,
+                                    CONST_STRING(INTERP, "sub"), info.subname);
+        VTABLE_set_string_keyed_str(INTERP, ctx_hash,
+                                    CONST_STRING(INTERP, "namespace"), info.nsname);
+        VTABLE_set_string_keyed_str(INTERP, ctx_hash,
+                                    CONST_STRING(INTERP, "file"), info.file);
+        VTABLE_set_integer_keyed_str(INTERP, ctx_hash,
+                                    CONST_STRING(INTERP, "line"), info.line);
 
-    METHOD namespace() {
-        Parrot_InstrumentOp_attributes * const attr = PARROT_INSTRUMENTOP(SELF);
-        Parrot_Context_info info;
-
-        INTVAL ret = Parrot_Context_get_info(attr->interp, CURRENT_CONTEXT(attr->interp), &info);
-        STRING *nsname = info.nsname;
-        RETURN(STRING *nsname);
+        RETURN(PMC *ctx_hash);
     }
 }
 

Modified: branches/gsoc_instrument/t/dynpmc/instrumentop.t
==============================================================================
--- branches/gsoc_instrument/t/dynpmc/instrumentop.t	Tue Jun 22 06:08:26 2010	(r47752)
+++ branches/gsoc_instrument/t/dynpmc/instrumentop.t	Tue Jun 22 12:36:55 2010	(r47753)
@@ -25,7 +25,7 @@
     # Load the Instrument library.
     load_bytecode 'Instrument/InstrumentLib.pbc'
 
-    plan(10)
+    plan(11)
 
     setup()
     test_one_op()
@@ -89,42 +89,47 @@
     # Test op name.
     $S0 = op.'name'()
     is($S0, 'say_sc', 'Op name correct.')
-    
+
     # Test op family name.
     $S0 = op.'family'()
     is($S0, 'say', 'Op family name correct.')
-    
+
     # Test op argument count.
     $I0 = op.'count'()
     is($I0, 1, 'Op argument count correct.')
-    
+
     # Test op arg type.
     $I1 = .PARROT_ARG_STRING + .PARROT_ARG_CONSTANT
     $I0 = op.'arg_type'(0)
     is($I0, $I1, 'Op argument type correct.')
-    
+
     # Test op arg value.
     $S0 = op.'get_arg'(0)
     is($S0, 'In test program', 'Op argument value correct.')
-    
+
     # Test pc. Op is the first op, so pc is 0.
     $I0 = op.'pc'()
     is($I0, 0, 'Op pc value correct.')
-    
+
+    ## Test context info.
+    $P0 = op.'get_context_info'()
+    $S0 = typeof $P0
+    is($S0, 'Hash', 'get_context_info returns a hash.')
+
     # Test file.
-    $S0 = op.'file'()
+    $S0 = $P0['file']
     is($S0, 't/dynpmc/instrumentop-test1.pir', 'Op filename correct.')
-    
+
     # Test line.
-    $I0 = op.'line'()
+    $I0 = $P0['line']
     is($I0, 3, 'Op line correct.')
-    
+
     # Test subroutine.
-    $S0 = op.'sub'()
+    $S0 = $P0['sub']
     is($S0, 'main', 'Op sub correct.')
-    
+
     # Test namespace.
-    $S0 = op.'namespace'()
+    $S0 = $P0['namespace']
     is($S0, 'TestNS', 'Op namespace correct.')
 .end
 


More information about the parrot-commits mailing list