cvsuser     04/11/29 02:02:26

  Modified:    .        MANIFEST
               t/library pge.t
  Added:       runtime/parrot/library/PGE RegCounter.pir
  Log:
  Added the PGE::RegCounter class, to be used shortly.
  
  Revision  Changes    Path
  1.794     +1 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.793
  retrieving revision 1.794
  diff -u -r1.793 -r1.794
  --- MANIFEST  28 Nov 2004 04:30:09 -0000      1.793
  +++ MANIFEST  29 Nov 2004 10:02:21 -0000      1.794
  @@ -2651,6 +2651,7 @@
   runtime/parrot/library/Data/Dumper/Base.imc       [library]
   runtime/parrot/library/Data/Dumper/Default.imc    [library]
   runtime/parrot/library/PGE/Class.pir              [library]
  +runtime/parrot/library/PGE/RegCounter.pir         [library]
   runtime/parrot/library/PGE.pir                    [library]
   runtime/parrot/library/SDL.imc                    [library]
   runtime/parrot/library/SDL/App.imc                [library]
  
  
  
  1.1                  parrot/runtime/parrot/library/PGE/RegCounter.pir
  
  Index: RegCounter.pir
  ===================================================================
  =head1 NAME
  
      PGE::RegCounter - A register naming manager
  
  =head1 SYNOPSIS
  
      # creation (only once; you usually call "next")
      .local pmc new_rc
      .local pmc rc
      find_global new_rc, "PGE::RegCounter", "new"
      rc = new_rc()
      
      # declare the registers you're going to use
      rc.declare("answer", "$I")
  
      # and use them
      print rc["answer"]
      print " = 41\n"
      print "inc "
      print rc["answer"]
      print "\n"
  
      # and pass on a child counter to a subroutine
      $P0 = rc.next()
      generate_foo($P0)
      # generate_foo() now has a clean lexical space to work with
  
  =cut
  
  .sub __onload @ANON, @LOAD
      newclass $P0, "PGE::RegCounter"
      addattribute $P0, ".counter"
      addattribute $P0, ".map"
  .end
  
  .namespace [ "PGE::RegCounter" ]
  
  .sub "new"
      .local pmc me
      
      $I0 = find_type "PGE::RegCounter"
      me = new $I0
  
      .local int offset
      offset = classoffset me, "PGE::RegCounter"
  
      $P0 = new Integer
      setattribute me, offset, $P0
  
      inc offset
      $P0 = new PerlHash    # XXX: There should be a non-perl hash
      setattribute me, offset, $P0
  
      .return(me)
  .end
  
  .sub "next" method
      .local int self_offset
      self_offset = classoffset self, "PGE::RegCounter"
  
      .local pmc me
      $I0 = find_type "PGE::RegCounter"
      me = new $I0
  
      .local int me_offset
      me_offset = classoffset me, "PGE::RegCounter"
  
      $P0 = getattribute self, self_offset
      setattribute me, me_offset, $P0
  
      inc me_offset
  
      $P0 = new PerlHash
      setattribute me, me_offset, $P0
  
      .return(me)
  .end
  
  .sub "set" method
      .param string key 
      .param string name
  
      .local int offset
      offset = classoffset self, "PGE::RegCounter"
  
      inc offset
  
      $P0 = getattribute self, offset
      $P0[key] = name
  
      .return()
  .end
  
  .sub "declare" method
      .param string key
      .param string prefix
  
      .local int offset
      offset = classoffset self, "PGE::RegCounter"
  
      $P0 = getattribute self, offset
      $S0 = $P0
      prefix .= $S0
      inc $P0
  
      inc offset
  
      $P0 = getattribute self, offset
      $P0[key] = prefix
  
      .return(prefix)
  .end
  
  .sub "__get_string_keyed" method
      .param pmc key
  
      .local int offset
      offset = classoffset self, "PGE::RegCounter"
  
      .local pmc counter
      .local pmc map
  
      counter = getattribute self, offset
      inc offset
      map = getattribute self, offset
      
  AGAIN:
      $I0 = exists map[key]
      if $I0 goto FETCH
  
      $P0 = new Exception
      $S0 = "Use of undeclared register name: "
      $S1 = key
      $S0 .= $S1
      $P0["_message"] = $S0
      
      throw $P0
  
  FETCH:
      $S0 = map[key]
      .return($S0)
  .end
  
  
  
  1.3       +76 -2     parrot/t/library/pge.t
  
  Index: pge.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/library/pge.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pge.t     27 Nov 2004 05:49:22 -0000      1.2
  +++ pge.t     29 Nov 2004 10:02:25 -0000      1.3
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: pge.t,v 1.2 2004/11/27 05:49:22 luqui Exp $
  +# $Id: pge.t,v 1.3 2004/11/29 10:02:25 luqui Exp $
   
   =head1 NAME
   
  @@ -14,7 +14,7 @@
   
   use strict;
   
  -use Parrot::Test tests => 2;
  +use Parrot::Test tests => 3;
   
   # 1
   output_is(<<'CODE', <<'OUT', "character class membership");
  @@ -77,4 +77,78 @@
   ok 2
   OUT
   
  +# 3
  +output_is(<<'CODE', <<'OUT', "RegCounter");
  +##PIR##
  +.sub _main
  +    load_bytecode "library/PGE/RegCounter.pir"
  +    
  +    .local pmc rc
  +    $P0 = find_global "PGE::RegCounter", "new"
  +    rc = $P0()
  +
  +    rc.declare("foo", "$I")
  +    rc.declare("bar", "$P")
  +    rc.declare("baz", "$I")
  +
  +    $S0 = rc["foo"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = rc["bar"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = rc["baz"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = rc["bar"]
  +    print $S0
  +    print "\n"
  +
  +    .local pmc ch
  +    ch = rc.next()
  +
  +    ch.declare("bar", "$P")
  +    ch.declare("baz", "$P")
  +    ch.declare("quux", "_L")
  +
  +    $S0 = ch["bar"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = ch["baz"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = ch["quux"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = ch["bar"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = rc["bar"]
  +    print $S0
  +    print "\n"
  +
  +    $S0 = rc["baz"]
  +    print $S0
  +    print "\n"
  +.end
  +CODE
  +$I0
  +$P1
  +$I2
  +$P1
  +$P3
  +$P4
  +_L5
  +$P3
  +$P1
  +$I2
  +OUT
  +
   # vim: ft=imc :
  
  
  

Reply via email to