Author: chromatic
Date: Tue Mar 25 11:24:56 2008
New Revision: 26542

Modified:
   trunk/examples/sdl/tetris/app.pir
   trunk/examples/sdl/tetris/block.pir
   trunk/examples/sdl/tetris/blockdata.pir
   trunk/examples/sdl/tetris/blocks.pir
   trunk/examples/sdl/tetris/boarddata.pir
   trunk/examples/sdl/tetris/eventhandler.pir

Log:
[examples] Removed deprecated classoffset opcode from Tetris example.

Modified: trunk/examples/sdl/tetris/app.pir
==============================================================================
--- trunk/examples/sdl/tetris/app.pir   (original)
+++ trunk/examples/sdl/tetris/app.pir   Tue Mar 25 11:24:56 2008
@@ -29,16 +29,6 @@
 .include "timer.pasm"
 .namespace ["Tetris::App"]
 
-.const int tSDL               = 0
-.const int tEventHandler      = 1
-.const int tDebugFlags        = 2
-.const int tTimer             = 3
-.const int tTimerDisableCount = 4
-.const int tInTimer           = 5
-.const int tPlayers           = 6
-.const int tPalette           = 7
-.const int tBoards            = 8
-
 .sub __onload :load
     $P0 = get_class "Tetris::App"
     unless null $P0 goto END
@@ -89,10 +79,8 @@
     # create the app object
     store_global "Tetris::App", "app", self
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tDebugFlags
     $P0 = new 'Hash'
-    setattribute self, $I0, $P0
+    setattribute self, 'DebugFlags', $P0
 
     # prepare SDL's constructor arguments
     $P0           = new 'Hash'
@@ -105,9 +93,7 @@
     $P0 = new "SDL::App", $P0
 
     # store the SDL object
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tSDL
-    setattribute self, $I0, $P0
+    setattribute self, 'SDL', $P0
 
     # generate some data structures
     self."genPalette"()
@@ -117,15 +103,11 @@
 
     # init the SDL event handler
     $P0 = new "Tetris::EventHandler", self
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tEventHandler
-    setattribute self, $I0, $P0
+    setattribute self, 'EventHandler', $P0
 
     # create the debug flags hash
     $P0 = new 'Hash'
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tDebugFlags
-    setattribute self, $I0, $P0
+    setattribute self, 'DebugFlags', $P0
 
     # start a new single player game
     self."newGame"( 1 )
@@ -144,10 +126,7 @@
 =cut
 
 .sub SDL :method
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tSDL
-
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'SDL'
 
     .return ($P0)
 .end
@@ -194,9 +173,7 @@
     .local pmc eh
     .local pmc loop
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tEventHandler
-    getattribute eh, self, $I0
+    getattribute eh, self, 'EventHandler'
 
     loop = new "SDL::Event"
 
@@ -224,22 +201,15 @@
     $P0[7] = 1
 
     $P1 = new 'Timer', $P0
-
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tTimer
-    setattribute self, $I0, $P1
-    sub $I0, tTimer
+    setattribute self, 'Timer', $P1
 
     $P0 = new 'Integer'
     $P0 = 1
-    add $I0, tTimerDisableCount
-    setattribute self, $I0, $P0
-    sub $I0, tTimerDisableCount
+    setattribute self, 'TimerDisableCount', $P0
 
     $P0 = new 'Integer'
     $P0 = 0
-    add $I0, tInTimer
-    setattribute self, $I0, $P0
+    setattribute self, 'InTimer', $P0
 .end
 
 =item app."setTimerStatus"( status )
@@ -249,9 +219,7 @@
 .sub setTimerStatus :method
     .param int status
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tTimer
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'Timer'
     set $P0[.PARROT_TIMER_RUNNING], status
 .end
 
@@ -260,9 +228,7 @@
 =cut
 
 .sub enableTimer :method
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tTimerDisableCount
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'TimerDisableCount'
     dec $P0
     if $P0 != 0 goto END
     self."setTimerStatus"( 1 )
@@ -274,9 +240,7 @@
 =cut
 
 .sub disableTimer :method
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tTimerDisableCount
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'TimerDisableCount'
     inc $P0
     self."setTimerStatus"( 0 )
 .end
@@ -307,9 +271,7 @@
 .sub palette :method
     .local pmc palette
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tPalette
-    getattribute palette, self, $I0
+    getattribute palette, self, 'Palette'
     if_null palette, CREATE
     branch RET
 CREATE:
@@ -371,9 +333,7 @@
     inc i
     if i < 16 goto GENLOOP
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tPalette
-    setattribute self, $I0, palette
+    setattribute self, 'Palette', palette
 
     .return (palette)
 .end
@@ -399,9 +359,7 @@
     .param int boardID
     .local pmc board
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tBoards
-    getattribute board, self, $I0
+    getattribute board, self, 'Boards'
 
     $I0 = board
     if boardID < $I0 goto OK
@@ -783,14 +741,10 @@
 
     # check the timer disable count
     # do nothing if the timer is disabled
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tTimerDisableCount
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'TimerDisableCount'
     if $P0 > 0 goto END
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tInTimer
-    getattribute inTimer, self, $I0
+    getattribute inTimer, self, 'InTimer'
 
     i = inTimer
     if i goto END
@@ -941,9 +895,7 @@
     .local pmc boards
     .local int count
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tBoards
-    getattribute boards, self, $I0
+    getattribute boards, self, 'Boards'
     count = 0
     if_null boards, END
     count = boards
@@ -1000,9 +952,7 @@
     .local int ret
 
     # get the flags hash
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tDebugFlags
-    getattribute flag, self, $I0
+    getattribute flag, self, 'DebugFlags'
 
     # check the number of INT args
     unless got_value goto FLAG_GET
@@ -1044,9 +994,7 @@
     # check the number of INT args
     if got_players goto SET
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tPlayers
-    getattribute temp, self, $I0
+    getattribute temp, self, 'Players'
     players = 1
     if_null temp, SET
     players = temp
@@ -1057,9 +1005,7 @@
     new temp, 'Integer'
     set temp, players
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tPlayers
-    setattribute self, $I0, temp
+    setattribute self, 'Players', temp
 END_SET:
 
     print "starting a "
@@ -1069,9 +1015,7 @@
     # create the boards array
     new temp, 'ResizablePMCArray'
 
-    classoffset $I0, self, "Tetris::App"
-    add $I0, tBoards
-    setattribute self, $I0, temp
+    setattribute self, 'Boards', temp
 
 NEWGAME_NEW_BOARD:
     if players <= 0 goto NEWGAME_END

Modified: trunk/examples/sdl/tetris/block.pir
==============================================================================
--- trunk/examples/sdl/tetris/block.pir (original)
+++ trunk/examples/sdl/tetris/block.pir Tue Mar 25 11:24:56 2008
@@ -20,12 +20,6 @@
 
 .namespace ["Tetris::Block"]
 
-.const int xPos      = 0
-.const int xPosDiff  = 1
-.const int yPos      = 2
-.const int Fall      = 3
-.const int Board     = 4
-
 .sub __onload :load
     $P0 = get_class "Tetris::Block"
     unless null $P0 goto END
@@ -67,40 +61,27 @@
 .sub BUILD :method
     .param pmc board
     .local pmc prop
-    .local int id
-
-    classoffset id, self, "Tetris::Block"
 
-    #
     # set some properties
-    #
 
-    # xpos
     new prop, 'Integer'
     set prop, 0
-    setattribute self, id, prop
-    inc id
+    setattribute self, 'xpos', prop
 
-    # xposdiff
     new prop, 'Integer'
     set prop, 0
-    setattribute self, id, prop
-    inc id
+    setattribute self, 'xposdiff', prop
 
-    # ypos
     new prop, 'Integer'
     set prop, 0
-    setattribute self, id, prop
-    inc id
+    setattribute self, 'ypos', prop
 
-    # fall
     new prop, 'Integer'
     set prop, 0
-    setattribute self, id, prop
-    inc id
+    setattribute self, 'fall', prop
 
     # set the board the block blongs to
-    setattribute self, id, board
+    setattribute self, 'board', board
 
     # return the block
     .return (self)
@@ -115,9 +96,7 @@
 =cut
 
 .sub fall :method
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, Fall
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'fall'
     $P0 = 1
 .end
 
@@ -128,9 +107,7 @@
 =cut
 
 .sub falling :method
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, Fall
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'fall'
     $I0 = $P0
 
     .return ($I0)
@@ -150,27 +127,18 @@
     .local pmc xposdiffP
     .local pmc yposP
 
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, xPos
-    getattribute xposP, self, $I0
-    sub $I0, xPos
-
-    add $I0, xPosDiff
-    getattribute xposdiffP, self, $I0
-    sub $I0, xPosDiff
-
-    add $I0, yPos
-    getattribute yposP, self, $I0
-    sub $I0, yPos
+    getattribute xposP,     self, 'xpos'
+    getattribute xposdiffP, self, 'xposdiff'
+    getattribute yposP,     self, 'ypos'
 
     # calculate the ypos
-    $I0 = self."vfree"()
+    $I0  = self."vfree"()
     ypos = yposP
     sub ypos, $I0
 
     # calculate the xpos
     xpos = xposP
-    $I0 = xposdiffP
+    $I0  = xposdiffP
     add xpos, $I0
 
     .return (xpos, ypos)
@@ -221,9 +189,7 @@
 
     # no => can i move the block?
     i = self."hfree"()
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, xPosDiff
-    getattribute temp, self, $I0
+    getattribute temp, self, 'xposdiff'
     set temp, i
 
     # is the position of the rotated block still valid?
@@ -248,9 +214,7 @@
 
 .sub board :method
     # get the board
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, Board
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'board'
 
     .return ($P0)
 .end
@@ -265,9 +229,7 @@
     .param pmc board
 
     # get the board
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, Board
-    setattribute self, $I0, board
+    setattribute self, 'board', board
 .end
 
 =item valid = block."validPosition"()
@@ -367,13 +329,8 @@
     .local int yold
     .local int valid
 
-    classoffset $I0, self, "Tetris::Block"
-    add $I0, xPos
-    getattribute xpos, self, $I0
-    sub $I0, xPos
-
-    add $I0, yPos
-    getattribute ypos, self, $I0
+    getattribute xpos, self, 'xpos'
+    getattribute ypos, self, 'ypos'
 
     set xold, xpos
     set yold, ypos

Modified: trunk/examples/sdl/tetris/blockdata.pir
==============================================================================
--- trunk/examples/sdl/tetris/blockdata.pir     (original)
+++ trunk/examples/sdl/tetris/blockdata.pir     Tue Mar 25 11:24:56 2008
@@ -55,8 +55,7 @@
     .local int v
     .local pmc olddata
 
-    classoffset $I0, self, "Tetris::BlockData"
-    getattribute olddata, self, $I0
+    getattribute olddata, self, 'data'
     olddata = clone olddata
 
     size = self."size"()
@@ -209,8 +208,7 @@
 =cut
 
 .sub size :method
-    classoffset $I0, self, "Tetris::BlockData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     $I0 = 0
     if_null $P0, END
     $I0 = $P0
@@ -224,8 +222,7 @@
 .sub __set_pmc :method
     .param pmc data
 
-    classoffset $I0, self, "Tetris::BlockData"
-    setattribute self, $I0, data
+    setattribute self, 'data', data
 .end
 
 .sub __get_integer_keyed :method
@@ -234,8 +231,7 @@
 
     index = key
 
-    classoffset $I0, self, "Tetris::BlockData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     if_null $P0, ERR
     $I0 = $P0
     if index >= $I0 goto ERR
@@ -260,8 +256,7 @@
 
     index = key
 
-    classoffset $I0, self, "Tetris::BlockData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     if_null $P0, ERR
     $I0 = $P0
     if index >= $I0 goto ERR

Modified: trunk/examples/sdl/tetris/blocks.pir
==============================================================================
--- trunk/examples/sdl/tetris/blocks.pir        (original)
+++ trunk/examples/sdl/tetris/blocks.pir        Tue Mar 25 11:24:56 2008
@@ -41,7 +41,7 @@
     .local pmc blocks
     .local pmc block
 
-    blocks = new IntList
+    blocks = new 'ResizablePMCArray'
 
     $P0 = get_class "Tetris::Block::0"
     push blocks, $P0
@@ -69,7 +69,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 1
@@ -89,7 +89,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 1
@@ -114,7 +114,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 1
@@ -139,7 +139,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 0
@@ -164,7 +164,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 0
     push block, 1
     push block, 1
@@ -189,7 +189,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 1
@@ -215,7 +215,7 @@
 .sub __init :method
     .local pmc block
 
-    block = new IntList
+    block = new 'ResizablePMCArray'
     push block, 1
     push block, 1
     push block, 1

Modified: trunk/examples/sdl/tetris/boarddata.pir
==============================================================================
--- trunk/examples/sdl/tetris/boarddata.pir     (original)
+++ trunk/examples/sdl/tetris/boarddata.pir     Tue Mar 25 11:24:56 2008
@@ -19,10 +19,6 @@
 
 .namespace ["Tetris::BoardData"]
 
-.const int bData   = 0
-.const int bWidth  = 1
-.const int bHeight = 2
-
 .sub __onload :load
     $P0 = get_class "Tetris::BoardData"
     unless null $P0 goto END
@@ -63,13 +59,10 @@
     .local pmc data
     .local pmc temp
     .local int i
-    .local int id
-
-    classoffset id, self, "Tetris::BoardData"
 
     # create the data array
     new data, 'ResizablePMCArray'
-    setattribute self, id, data
+    setattribute self, 'data', data
 
     # calculate the array size
     set i, w
@@ -80,14 +73,12 @@
     # store the width
     new temp, 'Integer'
     set temp, w
-    inc id
-    setattribute self, id, temp
+    setattribute self, 'width', temp
 
     # store the height
     new temp, 'Integer'
     set temp, h
-    inc id
-    setattribute self, id, temp
+    setattribute self, 'height', temp
 .end
 
 =back
@@ -117,8 +108,7 @@
     .local pmc data
     .local int i
 
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute data, self, $I0
+    getattribute data, self, 'data'
 
     # get data size
     set i, data
@@ -132,8 +122,7 @@
 .end
 
 .sub __get_integer :method
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     $I0 = $P0
     .return ($I0)
 .end
@@ -141,8 +130,7 @@
 .sub __get_integer_keyed :method
     .param pmc key
 
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     $I0 = key
     $I1 = $P0
     if $I0 < $I1 goto OK
@@ -162,24 +150,21 @@
     .param pmc key
     .param int val
 
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     $P0[key] = val
 .end
 
 .sub __set_integer_native :method
     .param int val
 
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     $P0 = val
 .end
 
 .sub __push_integer :method
     .param int val
 
-    classoffset $I0, self, "Tetris::BoardData"
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'data'
     push $P0, val
 .end
 
@@ -190,9 +175,7 @@
 =cut
 
 .sub width :method
-    classoffset $I0, self, "Tetris::BoardData"
-    add $I0, bWidth
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'width'
     $I0 = $P0
     .return ($I0)
 .end
@@ -204,9 +187,7 @@
 =cut
 
 .sub height :method
-    classoffset $I0, self, "Tetris::BoardData"
-    add $I0, bHeight
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'height'
     $I0 = $P0
     .return ($I0)
 .end
@@ -222,14 +203,10 @@
     .local int h
     .local pmc temp
 
-    classoffset $I0, self, "Tetris::BoardData"
-    add $I0, bWidth
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'width'
     w = $P0
-    sub $I0, bWidth
 
-    add $I0, bHeight
-    getattribute $P0, self, $I0
+    getattribute $P0, self, 'height'
     h = $P0
 
     .return (w, h)

Modified: trunk/examples/sdl/tetris/eventhandler.pir
==============================================================================
--- trunk/examples/sdl/tetris/eventhandler.pir  (original)
+++ trunk/examples/sdl/tetris/eventhandler.pir  Tue Mar 25 11:24:56 2008
@@ -23,15 +23,13 @@
 .sub BUILD :method
     .param pmc app
 
-    classoffset $I0, self, "Tetris::EventHandler"
-    setattribute self, $I0, app
+    setattribute self, 'app', app
 .end
 
 .sub app :method
     .local pmc app
 
-    classoffset $I0, self, "Tetris::EventHandler"
-    getattribute app, self, $I0
+    getattribute app, self, 'app'
     .return (app)
 .end
 

Reply via email to