Skip to content
Browse files

[pdd15oo] Merging the pdd15oo branch at r22176 back into trunk.

git-svn-id: https://svn.parrot.org/parrot/trunk@22180 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent a193d5f commit 8e57fe83e3ffce343c52aa171ca0e522165df450 @allisonrandal allisonrandal committed
Showing with 4,541 additions and 4,774 deletions.
  1. +8 −10 MANIFEST
  2. +1 −2 apps/p3/p3p.html
  3. +1 −1 compilers/imcc/imcc.l
  4. +1,910 −1,910 compilers/imcc/imclexer.c
  5. +1 −1 compilers/imcc/imcparser.c
  6. +1 −1 compilers/imcc/imcparser.h
  7. +1 −2 compilers/past-pm/PAST/Node.pir
  8. +1 −2 compilers/pct/src/HLLCompiler.pir
  9. +30 −27 compilers/pge/PGE/Exp.pir
  10. +1 −0 compilers/pge/PGE/Match.pir
  11. +8 −9 compilers/pge/PGE/OPTable.pir
  12. +2 −6 compilers/pge/PGE/P5Regex.pir
  13. +3 −7 compilers/pge/PGE/P6Regex.pir
  14. +1 −4 compilers/pge/PGE/Perl6Regex.pir
  15. +53 −74 compilers/pge/PGE/Regex.pir
  16. +14 −7 compilers/tge/TGE.pir
  17. +10 −5 config/gen/core_pmcs.pm
  18. +2 −0 config/gen/makefiles/root.in
  19. +1 −2 docs/book/ch04_pir_subroutines.pod
  20. +13 −5 docs/compiler_faq.pod
  21. +1 −2 docs/imcc/calling_conventions.pod
  22. +75 −32 docs/pdds/pdd15_objects.pod
  23. +1 −1 docs/pdds/pdd17_pmc.pod
  24. +2 −3 examples/benchmarks/oo1.pasm
  25. +2 −3 examples/benchmarks/oo2.pasm
  26. +1 −2 examples/benchmarks/oo3.pasm
  27. +1 −2 examples/benchmarks/oo4.pasm
  28. +1 −2 examples/benchmarks/oo5.pir
  29. +1 −2 examples/benchmarks/oo6.pir
  30. +1 −2 examples/benchmarks/oofib.pir
  31. +1 −2 examples/io/httpd2.pir
  32. +3 −2 examples/japh/japh4.pasm
  33. +2 −1 examples/japh/japh5.pasm
  34. +2 −1 examples/japh/japh6.pasm
  35. +1 −2 examples/pge/simple.pir
  36. +2 −2 examples/pir/sudoku.pir
  37. +71 −86 examples/sdl/anim_image.pir
  38. +69 −85 examples/sdl/anim_image_dblbuf.pir
  39. +49 −61 examples/sdl/blue_font.pir
  40. +37 −47 examples/sdl/blue_rect.pir
  41. +185 −203 examples/sdl/bounce_parrot_logo.pir
  42. +4 −8 examples/sdl/lcd/clock.pir
  43. +2 −3 examples/sdl/mandel.pir
  44. +4 −6 examples/sdl/minesweeper/eventhandler.pir
  45. +10 −15 examples/sdl/minesweeper/field.pir
  46. +4 −8 examples/sdl/minesweeper/mines.pir
  47. +6 −12 examples/sdl/move_parrot_logo.pir
  48. +4 −9 examples/sdl/raw_pixels.pir
  49. +10 −19 examples/sdl/tetris/app.pir
  50. +6 −10 examples/sdl/tetris/block.pir
  51. +2 −2 examples/sdl/tetris/blockdata.pir
  52. +16 −16 examples/sdl/tetris/blocks.pir
  53. +12 −17 examples/sdl/tetris/board.pir
  54. +3 −4 examples/sdl/tetris/boarddata.pir
  55. +2 −2 examples/sdl/tetris/eventhandler.pir
  56. +1 −2 examples/sdl/tetris/tetris.pir
  57. +2 −4 examples/streams/Bytes.pir
  58. +3 −6 examples/streams/Combiner.pir
  59. +1 −2 examples/streams/Coroutine.pir
  60. +4 −8 examples/streams/FileLines.pir
  61. +2 −4 examples/streams/Filter.pir
  62. +3 −6 examples/streams/Include.pir
  63. +2 −4 examples/streams/Lines.pir
  64. +1 −2 examples/streams/ParrotIO.pir
  65. +2 −4 examples/streams/Replay.pir
  66. +1 −2 examples/streams/SubCounter.pir
  67. +1 −2 examples/streams/SubHello.pir
  68. +1 −2 examples/streams/Writer.pir
  69. +0 −8 include/parrot/objects.h
  70. +76 −0 include/parrot/oo.h
  71. +89 −0 include/parrot/oo_private.h
  72. +1 −0 include/parrot/parrot.h
  73. +0 −18 include/parrot/pmc.h
  74. +5 −10 languages/WMLScript/t/pmc/boolean.t
  75. +5 −10 languages/WMLScript/t/pmc/float.t
  76. +5 −10 languages/WMLScript/t/pmc/integer.t
  77. +5 −10 languages/WMLScript/t/pmc/invalid.t
  78. +6 −12 languages/WMLScript/t/pmc/string.t
  79. +1 −2 languages/c99/src/CPP_PASTNodes.pir
  80. +2 −3 languages/c99/src/CPP_PGE2AST.pir
  81. +1 −1 languages/cardinal/cardinal.pir
  82. +2 −3 languages/cardinal/src/AST2OST.pir
  83. +2 −3 languages/cardinal/src/OST2PIR.pir
  84. +1 −2 languages/cardinal/src/PAST.pir
  85. +2 −3 languages/cardinal/src/PGE2AST.pir
  86. +2 −4 languages/dotnet/src/method.pir
  87. +25 −24 languages/dotnet/src/translator.pir
  88. +2 −4 languages/forth/forth.pir
  89. +4 −8 languages/lua/t/pmc/boolean.t
  90. +7 −14 languages/lua/t/pmc/closure.t
  91. +7 −14 languages/lua/t/pmc/function.t
  92. +7 −14 languages/lua/t/pmc/nil.t
  93. +7 −14 languages/lua/t/pmc/number.t
  94. +7 −14 languages/lua/t/pmc/string.t
  95. +15 −30 languages/lua/t/pmc/table.t
  96. +5 −10 languages/lua/t/pmc/thread.t
  97. +7 −14 languages/lua/t/pmc/userdata.t
  98. +4 −8 languages/perl5/t/sparse_perlarray.t
  99. +3 −12 languages/pheme/lib/PhemeSymbols.pir
  100. +23 −19 lib/Parrot/Pmc2c/PMC/Object.pm
  101. +2 −1 lib/Parrot/Pmc2c/PMC/delegate.pm
  102. +0 −2 lib/Parrot/Pmc2c/PMCEmitter.pm
  103. +8 −8 lib/Parrot/Test.pm
  104. +15 −7 runtime/parrot/library/Data/Dumper.pir
  105. +25 −30 runtime/parrot/library/Data/Dumper/Base.pir
  106. +16 −10 runtime/parrot/library/Data/Dumper/Default.pir
  107. +24 −24 runtime/parrot/library/Data/Replace.pir
  108. +1 −2 runtime/parrot/library/File/Spec.pir
  109. +25 −25 runtime/parrot/library/File/Spec/Unix.pir
  110. +1 −1 runtime/parrot/library/File/Spec/Win32.pir
  111. +2 −2 runtime/parrot/library/Getopt/Obj.pir
  112. +4 −8 runtime/parrot/library/HTTP/Daemon.pir
  113. +1 −1 runtime/parrot/library/Iter.pir
  114. +3 −3 runtime/parrot/library/PGE/Dumper.pir
  115. +4 −1 runtime/parrot/library/PGE/Hs.pir
  116. +19 −27 runtime/parrot/library/Parrot/Coroutine.pir
  117. +5 −5 runtime/parrot/library/Pg.pir
  118. +558 −555 runtime/parrot/library/SDL.pir
  119. +12 −37 runtime/parrot/library/SDL/App.pir
  120. +32 −35 runtime/parrot/library/SDL/Button.pir
  121. +8 −12 runtime/parrot/library/SDL/Color.pir
  122. +1 −1 runtime/parrot/library/SDL/Constants.pir
  123. +146 −150 runtime/parrot/library/SDL/Event.pir
  124. +99 −106 runtime/parrot/library/SDL/EventHandler.pir
  125. +77 −84 runtime/parrot/library/SDL/Font.pir
  126. +28 −32 runtime/parrot/library/SDL/Image.pir
  127. +32 −31 runtime/parrot/library/SDL/LCD.pir
  128. +87 −100 runtime/parrot/library/SDL/Rect.pir
  129. +13 −43 runtime/parrot/library/SDL/Sprite.pir
  130. +13 −11 runtime/parrot/library/SDL/StopWatch.pir
  131. +237 −256 runtime/parrot/library/SDL/Surface.pir
  132. +20 −49 runtime/parrot/library/Stream/Base.pir
  133. +6 −8 runtime/parrot/library/Stream/Combiner.pir
  134. +5 −6 runtime/parrot/library/Stream/Coroutine.pir
  135. +5 −6 runtime/parrot/library/Stream/Filter.pir
Sorry, we could not display the entire diff because it was too big.
View
18 MANIFEST
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Tue Oct 16 16:30:39 2007 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 17 17:00:27 2007 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -819,6 +819,8 @@ include/parrot/misc.h [main]include
include/parrot/mmd.h [main]include
include/parrot/nci.h [main]include
include/parrot/objects.h [main]include
+include/parrot/oo.h [main]include
+include/parrot/oo_private.h [main]include
include/parrot/op.h [main]include
include/parrot/oplib.h [main]include
include/parrot/packfile.h [main]include
@@ -2674,6 +2676,7 @@ src/misc.c []
src/mmd.c []
src/nci_test.c []
src/objects.c []
+src/oo.c []
src/ops/bit.ops []
src/ops/cmp.ops []
src/ops/core.ops []
@@ -2712,7 +2715,6 @@ src/pmc/boolean.pmc []
src/pmc/bound_nci.pmc []
src/pmc/capture.pmc []
src/pmc/class.pmc []
-src/pmc/classobject.h []
src/pmc/closure.pmc []
src/pmc/codestring.pmc []
src/pmc/compiler.pmc []
@@ -3057,11 +3059,15 @@ t/native_pbc/string.t []
t/native_pbc/string_1.pbc []
t/native_pbc/string_2.pbc []
t/oo/composition.t []
+t/oo/isa.t []
t/oo/metamodel.t []
+t/oo/methods.t []
t/oo/mro-c3.t []
t/oo/names.t []
t/oo/new.t []
t/oo/ops.t []
+t/oo/proxy.t []
+t/oo/subclass.t []
t/op/00ff-dos.t []
t/op/00ff-unix.t []
t/op/01-parse_ops.t []
@@ -3101,26 +3107,18 @@ t/op/stringu.t []
t/op/time.t []
t/op/trans.t []
t/op/types.t []
-t/pdd15oo/calling.t []
t/pdd15oo/dumper.t []
t/pdd15oo/exception.t []
t/pdd15oo/freeze.t []
-t/pdd15oo/gc.t []
t/pdd15oo/grammar.t []
t/pdd15oo/llqueue.t []
-t/pdd15oo/mmd.t []
t/pdd15oo/namespace.t []
-t/pdd15oo/object-meths.t []
-t/pdd15oo/object-mro.t []
-t/pdd15oo/objects.t []
t/pdd15oo/parrotobject.t []
t/pdd15oo/queue.t []
t/pdd15oo/ro.t []
t/pdd15oo/runtime.t []
-t/pdd15oo/spill.t []
t/pdd15oo/string.t []
t/pdd15oo/sub.t []
-t/pdd15oo/tail.t []
t/pdd15oo/test_more.t []
t/pdd15oo/threads.t []
t/perl/Parrot_Distribution.t []
View
3 apps/p3/p3p.html
@@ -47,8 +47,7 @@
<p>Starting it with some options is as simple as this:</p>
<pre>
.local pmc d, opts
- $I0 = find_type ['HTTP'; 'Daemon']
- d = new $I0, opts
+ d = new ['HTTP'; 'Daemon'], opts
d.'run'()
</pre>
<h1>CGI</h1>
View
2 compilers/imcc/imcc.l
@@ -296,7 +296,7 @@ SP [ ]
".pcc_begin_yield" return PCC_BEGIN_YIELD;
".pcc_end_yield" return PCC_END_YIELD;
-":method" return METHOD;
+<emit,INITIAL>":method" return METHOD;
<emit,INITIAL>":multi" return MULTI;
<emit,INITIAL>":main" return MAIN;
<emit,INITIAL>":load" return LOAD;
View
3,820 compilers/imcc/imclexer.c
1,910 additions, 1,910 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 compilers/imcc/imcparser.c
@@ -859,7 +859,7 @@ typedef union YYSTYPE
SymReg * sr;
Instruction *i;
}
-/* Line 187 of yacc.c. */
+/* Line 193 of yacc.c. */
#line 853 "compilers/imcc/imcparser.c"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
View
2 compilers/imcc/imcparser.h
@@ -297,7 +297,7 @@ typedef union YYSTYPE
SymReg * sr;
Instruction *i;
}
-/* Line 1489 of yacc.c. */
+/* Line 1529 of yacc.c. */
#line 291 "compilers/imcc/imcparser.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
View
3 compilers/past-pm/PAST/Node.pir
@@ -124,8 +124,7 @@ Create and returns a clone of a PAST node.
.sub 'clone' :vtable :method
.local pmc res
$S0 = classname self
- $I0 = find_type $S0
- res = new $I0
+ res = new $S0
.local pmc iter
iter = self.'iterator'()
iter_child_loop:
View
3 compilers/pct/src/HLLCompiler.pir
@@ -630,8 +630,7 @@ resulting ost.
.local pmc ostgrammar, ostbuilder
ostgrammar_name = self.'ostgrammar'()
unless ostgrammar_name goto default_ostgrammar
- $I0 = find_type ostgrammar_name
- ostgrammar = new $I0
+ ostgrammar = new ostgrammar_name
ostbuilder = ostgrammar.'apply'(source)
.return ostbuilder.'get'('post')
View
57 compilers/pge/PGE/Exp.pir
@@ -21,7 +21,7 @@ PGE::Exp - base class for expressions
.local pmc optable
.local pmc term
- $P0 = getclass "PGE::Match"
+ $P0 = get_class "PGE::Match"
$P0 = subclass $P0, "PGE::Exp"
$P1 = subclass $P0, "PGE::Exp::Literal"
$P1 = subclass $P0, "PGE::Exp::Scalar"
@@ -45,15 +45,14 @@ PGE::Exp - base class for expressions
=over 4
-=item C<compile(PMC source, PMC adverbs :slurpy :named)>
+=item C<compile(PMC adverbs :slurpy :named)>
-Compile the C<source> expression into PIR or a subroutine,
-according to the C<target> adverb.
+Compile C<self> into PIR or a subroutine, according to the
+C<target> adverbs.
=cut
-.sub 'compile'
- .param pmc source
+.sub 'compile' :method
.param pmc adverbs :slurpy :named
.local string target
@@ -72,7 +71,7 @@ according to the C<target> adverb.
.local pmc code
code = new 'CodeString'
code.'emit'(nsformat, grammar)
- $P0 = source.'root_pir'(adverbs :flat :named)
+ $P0 = self.'root_pir'(adverbs :flat :named)
code .= $P0
if target != 'pir' goto bytecode
.return (code)
@@ -88,7 +87,7 @@ according to the C<target> adverb.
.return ($P1)
return_exp:
- .return (source)
+ .return (self)
.end
@@ -102,11 +101,18 @@ tree as a PIR code object that can be compiled.
.sub 'root_pir' :method
.param pmc adverbs :slurpy :named
- .local string name
+ .local pmc code
+ code = new 'CodeString'
+
+ .local string name, namecorou
name = adverbs['name']
- if name > '' goto adverbs_1
- name = 'exp'
- adverbs_1:
+ namecorou = concat name, '_corou'
+ if name > '' goto have_name
+ name = code.'unique'('_regex')
+ namecorou = concat name, '_corou'
+ have_name:
+ name = code.'escape'(name)
+ namecorou = code.'escape'(namecorou)
## Perform reduction/optimization on the
## expression tree before generating PIR.
@@ -127,31 +133,29 @@ tree as a PIR code object that can be compiled.
explabel = 'R'
exp.pir(expcode, explabel, 'succeed')
- .local pmc code
- code = new 'CodeString'
if cutrule goto code_cutrule
## Generate the initial PIR code for a backtracking (uncut) rule.
.local string returnop
returnop = '.yield'
- code.emit(<<" CODE", name, .INTERPINFO_CURRENT_SUB)
- .sub '%0'
- .param pmc mob
+ code.emit(<<" CODE", name, namecorou, .INTERPINFO_CURRENT_SUB)
+ .sub %0 :method
.param pmc adverbs :slurpy :named
- .const .Sub corou = '%0_corou'
+ .const .Sub corou = %1
+ .local pmc mob
$P0 = corou
$P0 = clone $P0
- mob = $P0(mob, adverbs)
+ mob = $P0(self, adverbs)
.return (mob)
.end
- .sub '%0_corou'
+ .sub %1
.param pmc mob :unique_reg
.param pmc adverbs :unique_reg
.local string target :unique_reg
.local pmc mfrom, mpos :unique_reg
.local int cpos, iscont :unique_reg
- $P0 = getclass 'PGE::Match'
+ $P0 = get_hll_global ['PGE'], 'Match'
(mob, cpos, target, mfrom, mpos, iscont) = $P0.'new'(mob, adverbs :flat :named)
- $P0 = interpinfo %1
+ $P0 = interpinfo %2
setattribute mob, '&!corou', $P0
CODE
goto code_body
@@ -160,14 +164,13 @@ tree as a PIR code object that can be compiled.
## Initial code for a rule that cannot be backtracked into.
returnop = '.return'
code.emit(<<" CODE", name)
- .sub '%0'
- .param pmc mob :unique_reg
+ .sub %0 :method
.param pmc adverbs :unique_reg :slurpy :named
.local string target :unique_reg
- .local pmc mfrom, mpos :unique_reg
+ .local pmc mob, mfrom, mpos :unique_reg
.local int cpos, iscont :unique_reg
- $P0 = getclass 'PGE::Match'
- (mob, cpos, target, mfrom, mpos, iscont) = $P0.'new'(mob, adverbs :flat :named)
+ $P0 = get_hll_global ['PGE'], 'Match'
+ (mob, cpos, target, mfrom, mpos, iscont) = $P0.'new'(self, adverbs :flat :named)
CODE
code_body:
View
1 compilers/pge/PGE/Match.pir
@@ -12,6 +12,7 @@ This file implements match objects returned by the Parrot Grammar Engine.
.sub '__onload' :load
.local pmc base
+ load_bytecode 'PGE/Dumper.pir' # FIXME, XXX, etc.
base = subclass 'Hash', 'PGE::Match'
addattribute base, '$.target' # target
addattribute base, '$.from' # start of match
View
17 compilers/pge/PGE/OPTable.pir
@@ -34,8 +34,7 @@ PGE::OPTable - PGE operator precedence table and parser
.sub '__onload' :load
.local pmc base
.local pmc sctable
- $P0 = getclass 'Hash'
- base = subclass $P0, 'PGE::OPTable'
+ base = subclass 'Hash', 'PGE::OPTable'
addattribute base, '%!key'
addattribute base, '%!klen'
addattribute base, '&!ws'
@@ -77,8 +76,8 @@ Adds (or replaces) a syntactic category's defaults.
tokentable = self
keytable = new 'Hash'
klentable = new 'Hash'
- setattribute self, "PGE::OPTable\x0%!key", keytable
- setattribute self, "PGE::OPTable\x0%!klen", klentable
+ setattribute self, '%!key', keytable
+ setattribute self, '%!klen', klentable
.end
@@ -173,8 +172,8 @@ Adds (or replaces) a syntactic category's defaults.
add_key:
.local pmc keytable, klentable
- keytable = getattribute self, "PGE::OPTable\x0%!key"
- klentable = getattribute self, "PGE::OPTable\x0%!klen"
+ keytable = getattribute self, '%!key'
+ klentable = getattribute self, '%!klen'
$I1 = length key
$S0 = substr key, 0, 1
$I0 = klentable[$S0]
@@ -226,8 +225,8 @@ Adds (or replaces) a syntactic category's defaults.
.local int circumnest
tokentable = self
- keytable = getattribute self, "PGE::OPTable\x0%!key"
- klentable = getattribute self, "PGE::OPTable\x0%!klen"
+ keytable = getattribute self, '%!key'
+ klentable = getattribute self, '%!klen'
unless null adverbs goto with_adverbs
adverbs = new 'Hash'
@@ -279,7 +278,7 @@ Adds (or replaces) a syntactic category's defaults.
tighter = token['precedence']
with_tighter:
- ws = getattribute self, "PGE::OPTable\x0&!ws"
+ ws = getattribute self, '&!ws'
tokenstack = new 'ResizablePMCArray'
operstack = new 'ResizablePMCArray'
termstack = new 'ResizablePMCArray'
View
8 compilers/pge/PGE/P5Regex.pir
@@ -6,14 +6,10 @@
.param pmc source
.param pmc adverbs :slurpy :named
- $I0 = exists adverbs['name']
- if $I0 goto adverbs_1
- adverbs['name'] = '_p5regex'
- adverbs_1:
$I0 = exists adverbs['grammar']
- if $I0 goto adverbs_2
+ if $I0 goto have_grammar
adverbs['grammar'] = 'PGE::Grammar'
- adverbs_2:
+ have_grammar:
.local string target
target = adverbs['target']
View
10 compilers/pge/PGE/P6Regex.pir
@@ -40,12 +40,9 @@ or the resulting PIR code (target='PIR').
with_grammar:
$I0 = exists adverbs['name']
if $I0 goto with_name
- unless args goto adverb_name_1
+ unless args goto with_name
$S0 = shift args
adverbs['name'] = $S0
- goto with_name
- adverb_name_1:
- adverbs['name'] = '_regex'
with_name:
$I0 = exists adverbs['lang']
if $I0 goto with_lang
@@ -133,8 +130,7 @@ parse valid Perl 6 regular expressions.
.namespace [ 'PGE::Grammar' ]
-.sub 'regex'
- .param pmc mob
+.sub 'regex' :method
.param pmc adverbs :slurpy :named
.local string stop
@@ -145,7 +141,7 @@ parse valid Perl 6 regular expressions.
stop = adverbs['stop']
push stopstack, stop
- match = optable.'parse'(mob, 'stop'=>stop)
+ match = optable.'parse'(self, 'stop'=>stop)
$S0 = pop stopstack
.return (match)
View
5 compilers/pge/PGE/Perl6Regex.pir
@@ -40,12 +40,9 @@ or the resulting PIR code (target='PIR').
with_grammar:
$I0 = exists adverbs['name']
if $I0 goto with_name
- unless args goto adverb_name_1
+ unless args goto with_name
$S0 = shift args
adverbs['name'] = $S0
- goto with_name
- adverb_name_1:
- adverbs['name'] = '_regex'
with_name:
$I0 = exists adverbs['lang']
if $I0 goto with_lang
View
127 compilers/pge/PGE/Regex.pir
@@ -33,15 +33,14 @@ Match an identifier.
=cut
-.sub 'ident'
- .param pmc mob
+.sub 'ident' :method
.param pmc adverbs :slurpy :named
.local string target
- .local pmc mfrom, mpos
+ .local pmc mob, mfrom, mpos
.local int pos, lastpos
$P0 = get_hll_global ['PGE'], 'Match'
- (mob, pos, target) = $P0.'new'(mob)
+ (mob, pos, target) = $P0.'new'(self)
lastpos = length target
$S0 = substr target, pos, 1
@@ -62,11 +61,11 @@ Match a null string (always returns true on first match).
=cut
-.sub "null"
- .param pmc mob
+.sub "null" :method
+ .local pmc mob
.local int pos
$P0 = get_hll_global ['PGE'], 'Match'
- (mob, pos) = $P0.'new'(mob)
+ (mob, pos) = $P0.'new'(self)
mob.'to'(pos)
.return (mob)
.end
@@ -77,10 +76,9 @@ Force a backtrack. (Taken from A05.)
=cut
-.sub "fail"
- .param pmc mob
+.sub "fail" :method
$P0 = get_hll_global ['PGE'], 'Match'
- .return $P0.'new'(mob)
+ .return $P0.'new'(self)
.end
@@ -90,9 +88,8 @@ Match a single uppercase character.
=cut
-.sub 'upper'
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_UPPERCASE)
+.sub 'upper' :method
+ .return '!cclass'(self, .CCLASS_UPPERCASE)
.end
@@ -102,9 +99,8 @@ Match a single lowercase character.
=cut
-.sub "lower"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_LOWERCASE)
+.sub "lower" :method
+ .return '!cclass'(self, .CCLASS_LOWERCASE)
.end
@@ -114,9 +110,8 @@ Match a single alphabetic character.
=cut
-.sub "alpha"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_ALPHABETIC)
+.sub "alpha" :method
+ .return '!cclass'(self, .CCLASS_ALPHABETIC)
.end
=item C<digit()>
@@ -125,9 +120,8 @@ Match a single digit.
=cut
-.sub "digit"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_NUMERIC)
+.sub "digit" :method
+ .return '!cclass'(self, .CCLASS_NUMERIC)
.end
=item C<xdigit()>
@@ -136,9 +130,8 @@ Match a single alphanumeric character.
=cut
-.sub "xdigit"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_HEXADECIMAL)
+.sub "xdigit" :method
+ .return '!cclass'(self, .CCLASS_HEXADECIMAL)
.end
=item C<space()>
@@ -147,9 +140,8 @@ Match a single whitespace character.
=cut
-.sub "space"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_WHITESPACE)
+.sub "space" :method
+ .return '!cclass'(self, .CCLASS_WHITESPACE)
.end
=item C<print()>
@@ -158,9 +150,8 @@ Match a single printable character.
=cut
-.sub "print"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_PRINTING)
+.sub "print" :method
+ .return '!cclass'(self, .CCLASS_PRINTING)
.end
=item C<graph()>
@@ -169,9 +160,8 @@ Match a single "graphical" character.
=cut
-.sub "graph"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_GRAPHICAL)
+.sub "graph" :method
+ .return '!cclass'(self, .CCLASS_GRAPHICAL)
.end
=item C<blank()>
@@ -180,9 +170,8 @@ Match a single "blank" character.
=cut
-.sub "blank"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_BLANK)
+.sub "blank" :method
+ .return '!cclass'(self, .CCLASS_BLANK)
.end
=item C<cntrl()>
@@ -191,9 +180,8 @@ Match a single "control" character.
=cut
-.sub "cntrl"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_CONTROL)
+.sub "cntrl" :method
+ .return '!cclass'(self, .CCLASS_CONTROL)
.end
=item C<punct()>
@@ -202,9 +190,8 @@ Match a single punctuation character.
=cut
-.sub "punct"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_PUNCTUATION)
+.sub "punct" :method
+ .return '!cclass'(self, .CCLASS_PUNCTUATION)
.end
=item C<alnum()>
@@ -213,9 +200,8 @@ Match a single alphanumeric character.
=cut
-.sub "alnum"
- .param pmc mob
- .return '!cclass'(mob, .CCLASS_ALPHANUMERIC)
+.sub "alnum" :method
+ .return '!cclass'(self, .CCLASS_ALPHANUMERIC)
.end
=item C<sp()>
@@ -224,9 +210,8 @@ Match a single space character. (Taken from E05.)
=cut
-.sub "sp"
- .param pmc mob
- .return '!literal'(mob, ' ')
+.sub "sp" :method
+ .return '!literal'(self, ' ')
.end
=item C<lt()>
@@ -235,9 +220,8 @@ Match a single left angle bracket. (Taken from E05.)
=cut
-.sub "lt"
- .param pmc mob
- .return '!literal'(mob, '<')
+.sub "lt" :method
+ .return '!literal'(self, '<')
.end
=item C<gt()>
@@ -246,9 +230,8 @@ Match a single right angle bracket. (Taken from E05.)
=cut
-.sub "gt"
- .param pmc mob
- .return '!literal'(mob, '>')
+.sub "gt" :method
+ .return '!literal'(self, '>')
.end
=item C<dot()>
@@ -257,9 +240,8 @@ Match a single dot ('.'). (Taken from E05.)
=cut
-.sub "dot"
- .param pmc mob
- .return '!literal'(mob, '.')
+.sub "dot" :method
+ .return '!literal'(self, '.')
.end
=item C<ws()>
@@ -268,17 +250,16 @@ Match whitespace between tokens.
=cut
-.sub "ws"
- .param pmc mob
+.sub "ws" :method
.local string target
- .local pmc mfrom, mpos
+ .local pmc mob, mfrom, mpos
.local int rep, pos, lastpos
.local string nextchars
.const .Sub corou = "ws_corou"
nextchars = ""
ws_1:
$P0 = get_hll_global ['PGE'], 'Match'
- (mob, pos, target, mfrom, mpos) = $P0.'new'(mob)
+ (mob, pos, target, mfrom, mpos) = $P0.'new'(self)
lastpos = length target
pos = mfrom
if pos >= lastpos goto found
@@ -335,13 +316,12 @@ Perl 5's \b regex).
=cut
-.sub "wb"
- .param pmc mob
+.sub "wb" :method
.local string target
- .local pmc mfrom, mpos
+ .local pmc mob
.local int pos
$P0 = get_hll_global ['PGE'], 'Match'
- (mob, pos, target) = $P0.'new'(mob)
+ (mob, pos, target) = $P0.'new'(self)
if pos == 0 goto succeed
$I0 = length target
if pos == $I0 goto succeed
@@ -364,15 +344,14 @@ success.
=cut
-.sub "before"
- .param pmc mob
+.sub "before" :method
.param string pattern :optional
.param int has_pattern :opt_flag
.param pmc adverbs :slurpy :named
- .local pmc cache, rule
+ .local pmc mob, cache, rule
if has_pattern goto lookahead
- mob = 'fail'(mob)
+ mob = 'fail'(self)
.return (mob)
lookahead:
cache = get_global '%!cache'
@@ -385,7 +364,7 @@ success.
rule = $P0(pattern)
cache[pattern] = rule
match:
- mob = rule(mob)
+ mob = rule(self)
unless mob goto end
$P0 = getattribute mob, '$.from'
$P1 = getattribute mob, '$.pos'
@@ -412,14 +391,14 @@ potentially very inefficient, but it "works" for now.
=cut
-.sub "after"
- .param pmc mob
+.sub "after" :method
.param string pattern :optional
.param int has_pattern :opt_flag
.param pmc adverbs :slurpy :named
- .local pmc cache, rule
+ .local pmc mob, cache, rule
.local int from
+ mob = self
if has_pattern goto lookbehind
mob = fail(mob)
.return (mob)
View
21 compilers/tge/TGE.pir
@@ -81,6 +81,13 @@ applies to a child of the current node (generally inherited attributes).
.namespace [ 'TGE' ]
.sub '__onload' :load
+ # make sure we execute this sub only once
+ $P0 = get_global '$!tge_loaded'
+ unless null $P0 goto end
+ $P0 = new 'Integer'
+ assign $P0, 1
+ set_global '$!tge_loaded', $P0
+
# use other modules
load_bytecode 'PGE.pbc'
load_bytecode 'PGE/Util.pbc'
@@ -90,14 +97,14 @@ applies to a child of the current node (generally inherited attributes).
load_bytecode 'compilers/tge/TGE/Grammar.pbc'
load_bytecode 'compilers/tge/TGE/Compiler.pbc'
- # import <die> rule from PGE::Util
- $P0 = get_hll_global ['PGE::Util'], 'die'
- set_hll_global ['TGE::Parser'], 'die', $P0
-
- # import <line_number> method from PGE::Util
- $P0 = get_hll_global ['PGE::Util'], 'line_number'
- set_hll_global ['TGE::Parser'], 'line_number', $P0
+ # import <die> and <line_number> rules from PGE::Util
+ $P0 = get_class ['TGE::Parser']
+ $P1 = get_hll_global ['PGE::Util'], 'die'
+ $P0.'add_method'('die', $P1)
+ $P1 = get_hll_global ['PGE::Util'], 'line_number'
+ $P0.'add_method'('line_number', $P1)
+ end:
.return ()
.end
View
15 config/gen/core_pmcs.pm
@@ -111,8 +111,13 @@ END_C
/* This isn't strictly true, but the headerizer should not bother */
-void Parrot_register_core_pmcs(PARROT_INTERP, PMC* registry);
-extern void Parrot_initialize_core_pmcs(PARROT_INTERP);
+void Parrot_register_core_pmcs(PARROT_INTERP, NOTNULL(PMC *registry))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+extern void Parrot_initialize_core_pmcs(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
void Parrot_initialize_core_pmcs(PARROT_INTERP)
{
int pass;
@@ -133,14 +138,14 @@ END_C
}
}
-static void register_pmc(PARROT_INTERP, PMC* registry, int pmc_id)
+static void register_pmc(PARROT_INTERP, PMC *registry, int pmc_id)
{
- STRING* const key = interp->vtables[pmc_id]->whoami;
+ STRING * const key = interp->vtables[pmc_id]->whoami;
VTABLE_set_integer_keyed_str(interp, registry, key, pmc_id);
}
void
-Parrot_register_core_pmcs(PARROT_INTERP, PMC* registry)
+Parrot_register_core_pmcs(PARROT_INTERP, NOTNULL(PMC *registry))
{
END_C
View
2 config/gen/makefiles/root.in
@@ -416,6 +416,7 @@ INTERP_O_FILES = \
$(SRC_DIR)/misc$(O) \
$(SRC_DIR)/mmd$(O) \
$(SRC_DIR)/nci$(O) \
+ $(SRC_DIR)/oo$(O) \
$(SRC_DIR)/objects$(O) \
$(SRC_DIR)/packfile$(O) \
$(SRC_DIR)/packout$(O) \
@@ -579,6 +580,7 @@ STR_FILES = \
$(SRC_DIR)/library.str \
$(SRC_DIR)/mmd.str \
$(SRC_DIR)/pmc.str \
+ $(SRC_DIR)/oo.str \
$(SRC_DIR)/objects.str \
$(SRC_DIR)/spf_render.str \
$(SRC_DIR)/spf_vtable.str \
View
3 docs/book/ch04_pir_subroutines.pod
@@ -401,8 +401,7 @@ first method:
.local pmc class
.local pmc obj
newclass class, "Foo" # create a new Foo class
- find_type $I0, "Foo" # find its dynamic type number
- new obj, $I0 # instantiate a Foo object
+ new obj, "Foo" # instantiate a Foo object
obj."_meth"() # call obj."_meth" which is actually
print "done\n" # "_meth" in the "Foo" namespace
end
View
18 docs/compiler_faq.pod
@@ -396,14 +396,22 @@ property of the class PMC:
=head2 How do I instantiate a class?
-You can do so either with an integer type identifier:
+You can do so either with the class name:
- $I0 = find_type 'Dog'
- new $P0, $I0 # creates a Dog object and stores it in register $P0
+ new $P0, 'Dog'
-or with the class name:
+or with the class object:
- new $P0, 'Dog'
+ $P1 = get_class 'Dog' # find the 'Dog' class
+ unless null $P1 goto have_dog_class
+ printerr "Oops; can't find the 'Dog' class.\n"
+ .return ()
+ have_dog_class:
+ new $P0, $P1 # creates a Dog object and stores it in register $P0
+
+The chief difference is that using a string constant will produce the
+specific error "Class 'Dog' not found" if that happens to be the case;
+the other code has to check explicitly.
During the C<new> opcode the constructor is called.
View
3 docs/imcc/calling_conventions.pod
@@ -222,8 +222,7 @@ C<meth_call> which must immediately be preceded by the C<.invocant>:
.local pmc class
.local pmc obj
newclass class, "Foo"
- find_type $I0, "Foo"
- new obj, $I0
+ new obj, class
.pcc_begin
.arg x
.arg y
View
107 docs/pdds/pdd15_objects.pod
@@ -346,11 +346,16 @@ associated with a namespace.) Just adding a sub to a namespace will not
automatically make it a method of the class, you have to call add_method
too.
-=item isa(class *)
+=item isa(pmc *)
-Returns true or false if the class passed in as a parameter is in the
-inheritance hierarchy of the object. {{This should also support type
-names and namespace names as a parameter, not just class objects.}}
+Returns true or false if the class object, namespace object, key, or
+string name PMC passed in as a parameter is a class in the inheritance
+hierarchy of the object.
+
+=item isa_str(string *)
+
+Returns true or false if the string passed in as a parameter is a
+class in the inheritance hierarchy of the object.
=item can(string *)
@@ -641,11 +646,23 @@ composed into the class).
=item get_attr(STRING*)
-Returns the attribute with the fully qualified name for the object.
+Returns the attribute with the string name for the object.
+
+=item get_attr_keyed(PMC*, STRING*)
-=item set_attr(STRING*, PMC *)
+Returns the attribute with the string name for the object. Lookup is on
+the attribute store of a particular parent of the object's class,
+identified by a classname, namespace, or key PMC.
-Set the attribute with the fully qualified name for the object.
+=item set_attr(STRING*, PMC*)
+
+Set the attribute with the string name for the object.
+
+=item set_attr_keyed(PMC*, STRING*, PMC*)
+
+Set the attribute with the string name for the object. The value is set
+in the attribute store of a particular parent of the object's class,
+identified by a classname, namespace, or key PMC.
=item get_class
@@ -929,7 +946,7 @@ as an attribute in the child class, pass an optional class object or namespace
key $P3 for the parent class.
If the attribute doesn't exist, it will throw an exception. If the attribute
-exists, but the value hasn't been set, it will return an C<Undef> PMC.
+exists, but the value hasn't been set, it will return a null PMC.
=item setattribute
@@ -945,43 +962,52 @@ If the attribute doesn't exist, it will throw an exception.
=item callmethod
- callmethod
- callmethod $S1
+ callmethod $P1, $S1, $P2
+
+Call the method specified in the attribute $S1 using $P1 as the invocant and
+using the continuation passed in $P2. If you need to create a new continuation
+use C<callmethodcc>.
+
+ callmethod $P1, $P2, $P3
+
+Call the method specified in the Sub object $P2 using $P1 as the invocant and
+using the continuation passed in $P3. If you need to create a new continuation
+use C<callmethodcc>.
-Call a method. If the method name is provided in $S1, we find the PMC
-for the named method and put it in the sub/method slot. If no name is
-provided we assume that all the calling conventions have already been
-set up and the method PMC is already in the proper place.
=item callmethodcc
- callmethodcc
- callmethodcc $S1
+ callmethodcc $P1, $S1
+ callmethodcc $P1, $P2
+
+Call the method specified in the attribute $S1, or in the Sub object $P2, using
+$P1 as the invocant for method lookup and generate a new return continuation.
-Make a method call, automatically generating a return continuation. If a
-method name is passed in we look up the method PMC for the object and
-put it in the method slot. If a method name isn't provided then we
-assume that things are already properly set up.
+Throws a Method_Not_Found_Exception for a non-existent method.
=item callmethodsupercc
- callmethodsupercc $S1
+ callmethodsupercc $P1, $S1
+ callmethodsupercc $P1, $P2
-Make a method call, automatically generating a return continuation. A variant
-of C<callmethodcc> that skips over the current class when searching for the
-method, and only looks in the parent classes. PIR may provide some syntactic
-sugar for this.
+Call the method specified in the attribute $S1, or in the Sub object $P2, using
+$P1 as the invocant for method lookup and generate a new return continuation.
+This is a variant of C<callmethodcc> that skips over the current class when
+searching for the method, and only looks in the parent classes. PIR may
+provide some syntactical sugar for this.
=item callmethodnextcc
- callmethodnextcc $S1
+ callmethodnextcc $P1, $S1
+ callmethodnextcc $P1, $P2
-Make a method call, automatically generating a return continuation. A variant
-of C<callmethodcc> that picks up an existing C<find_method> search where it
-left off for the current call. {{ Note: this depends on find_method being
-resumable, and on the context of a particular method including a pointer to the
-find_method call that found it. Neither may be feasible. }} PIR may provide
-some syntactic sugar for this.
+Call the method specified in the attribute $S1, or in the Sub object $P2,
+using $P1 as the invocant for method lookup and generate a new return
+continuation. A variant of C<callmethodcc> that picks up an existing
+C<find_method> search where it left off for the current call. {{ Note: this
+depends on find_method being resumable, and on the context of a particular
+method including a pointer to the find_method call that found it. Neither may
+be feasible. }} PIR may provide some syntactic sugar for this.
=item newclass
@@ -993,7 +1019,12 @@ optionally pass a hash of initialization parameters for the class in $P3.
=item subclass
+ $P1 = subclass $S2
+ $P1 = subclass $P2
+ $P1 = subclass $S2, $S3
$P1 = subclass $P2, $S3
+ $P1 = subclass $S2, $P3
+ $P1 = subclass $P2, $P3
Create a new class, named $S3, which has $P2 as its immediate parent. $P2 may
be either another high-level class based on the Class PMC, or it may be a
@@ -1012,6 +1043,18 @@ currently selected namespace. Passing in a namespace object looks for the class
in that namespace object. A key looks for the class in the namespace identified
by the multilevel key relative to the currently selected HLL.
+If the class doesn't exist, it returns a null PMC.
+
+=item typeof
+
+ $S1 = typeof $P2
+ $P1 = typeof $P2
+
+Lookup the type of the instance object in $P2. Return the string name if the
+destination is a string register or variable. If the destination is a PMC
+register or variable, return the class object for an instance of a high-level
+class, or the class proxy object for an instance of a low-level PMC.
+
=item new
$P1 = new $S2
View
2 docs/pdds/pdd17_pmc.pod
@@ -433,7 +433,7 @@ with appropriate prototypes.
In C code, the first parameter to any vtable routine is the current
interpreter. The second parameter is the PMC itself.
-The following list details each of the vtable methods, their prototypes, and
+The following list details each of the vtable functions, their prototypes, and
their behavior.
=head3 Core Vtable Functions
View
5 examples/benchmarks/oo1.pasm
@@ -43,14 +43,13 @@
set I10, 0
set I11, 100000
- find_type I12, "Foo"
loop:
- new P3, I12
+ P3 = new "Foo"
inc I10
#sleep 0.0001
lt I10, I11, loop
- new P3, I12
+ P3 =new "Foo"
classoffset I0, P3, "Foo"
getattribute P2, P3, I0
print P2
View
5 examples/benchmarks/oo2.pasm
@@ -31,13 +31,12 @@
set I10, 0
set I11, 500000
- find_type I12, "Foo"
loop:
- new P3, I12
+ P3 = new "Foo"
inc I10
lt I10, I11, loop
- new P3, I12
+ P3 = new "Foo"
classoffset I0, P3, "Foo"
getattribute P2, P3, I0
print P2
View
3 examples/benchmarks/oo3.pasm
@@ -8,8 +8,7 @@
set I10, 0
set I11, 500000
- find_type I12, "Foo"
- new P3, I12
+ P3 = new "Foo"
loop:
classoffset I0, P3, "Foo"
getattribute P2, P3, I0
View
3 examples/benchmarks/oo4.pasm
@@ -8,8 +8,7 @@
set I10, 1
set I11, 500000
- find_type I12, "Foo"
- new P3, I12
+ P3 = new "Foo"
loop:
classoffset I0, P3, "Foo"
new P4, 'Integer'
View
3 examples/benchmarks/oo5.pir
@@ -9,9 +9,8 @@
.local int typ
.local int i
i = 1
- typ = find_type "Foo"
.local pmc o
- o = new typ
+ o = new "Foo"
loop:
$P4 = o."i"()
.local pmc x
View
3 examples/benchmarks/oo6.pir
@@ -9,9 +9,8 @@
.local int typ
.local int i
i = 1
- typ = find_type "Foo"
.local pmc o
- o = new typ
+ o = new "Foo"
loop:
$P4 = new 'Integer'
$P4 = i
View
3 examples/benchmarks/oofib.pir
@@ -21,8 +21,7 @@ noarg:
A = newclass "A"
B = subclass A, "B"
- find_type $I0, "B"
- b = new $I0
+ b = new "B"
.sym pmc r
r = b."fib"(N)
View
3 examples/io/httpd2.pir
@@ -19,8 +19,7 @@ Leopold Toetsch <lt@toetsch.at> - some code base on httpd.pir.
.local pmc d, opts
.local int clid
opts = 'get_config'(args)
- clid = find_type ['HTTP'; 'Daemon']
- d = new clid, opts
+ d = new ['HTTP'; 'Daemon'], opts
unless d goto err
push_eh ignore
$S0 = opts['url']
View
5 examples/japh/japh4.pasm
@@ -1,9 +1,10 @@
-newclass P2, "Japh"
+newclass P1, "Japh"
+new P2, "Japh"
print P2
end
.namespace ["Japh"]
-.pcc_sub __get_string:
+.pcc_sub :vtable get_string:
set S3, "Just another Parrot Hacker\n"
set_returns "0", S3
returncc
View
3 examples/japh/japh5.pasm
@@ -1,12 +1,13 @@
# JaPH utilizing an object
newclass P0, "Japh"
+ new P0, "Japh"
set P0[1], "Just"
set P0[2], "another"
set P0[3], "Parrot"
set P0[0], "Hacker"
end
.namespace ["Japh"]
-.pcc_sub __set_string_keyed:
+.pcc_sub :vtable set_string_keyed:
get_params "0,0,0", P5, I5, S5
print S5
if I5, sp
View
3 examples/japh/japh6.pasm
@@ -1,4 +1,5 @@
newclass P0, "Japh"
+ new P0, "Japh"
set I0, 0
set S0, P0[I0]
print S0
@@ -7,7 +8,7 @@
print S0
end
.namespace ["Japh"]
-.pcc_sub __get_string_keyed:
+.pcc_sub :vtable get_string_keyed:
get_params "0,0", P1, I1
unless I1, x
set S1, "Parrot Hacker\n"
View
3 examples/pge/simple.pir
@@ -6,8 +6,7 @@
.local pmc p6rule
.local string op
- $I0 = find_type "PGE::OPTable"
- optable = new $I0
+ optable = new "PGE::OPTable"
store_global "Simple", "$optable", optable
p6rule = compreg "PGE::P6Rule"
View
4 examples/pir/sudoku.pir
@@ -2101,7 +2101,7 @@ out:
print s
.end
-.sub wait
+.sub "wait" :method
.end
.namespace ["NCurses"]
@@ -2140,7 +2140,7 @@ out:
f(win, s)
.end
-.sub wait
+.sub "wait" :method
.local pmc f
.local int key
f = global "ncurses::getch"
View
157 examples/sdl/anim_image.pir
@@ -6,121 +6,106 @@ anim_image.pir - animate an image in a Parrot SDL window
To run this file, run the following command from the Parrot directory:
- $ ./parrot examples/sdl/anim_image.pir
- Drew 1080 frames in 0.948230 seconds (1138.964142 fps)
- $
+ $ ./parrot examples/sdl/anim_image.pir
+ Drew 1080 frames in 0.948230 seconds (1138.964142 fps)
+ $
=cut
.sub _main :main
- load_bytecode "library/SDL/App.pir"
- load_bytecode "library/SDL/Color.pir"
- load_bytecode "library/SDL/Rect.pir"
- load_bytecode "library/SDL/Image.pir"
- load_bytecode "library/SDL/Sprite.pir"
+ load_bytecode "library/SDL/App.pir"
+ load_bytecode "library/SDL/Color.pir"
+ load_bytecode "library/SDL/Rect.pir"
+ load_bytecode "library/SDL/Image.pir"
+ load_bytecode "library/SDL/Sprite.pir"
- .local pmc app
- .local int app_type
+ .local pmc app
+ app = new 'SDL::App'
+ app.'init'( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1 )
- find_type app_type, 'SDL::App'
- app = new app_type
- app.'init'( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1 )
+ .local pmc main_screen
+ main_screen = app.'surface'()
- .local pmc main_screen
- main_screen = app.'surface'()
+ .local pmc dest_rect
+ dest_rect = new 'SDL::Rect'
+ dest_rect.'init'( 'height' => 100, 'width' => 100, 'x' => 0, 'y' => 190 )
- .local int rect_type
- find_type rect_type, 'SDL::Rect'
+ .local pmc prev_rect
+ prev_rect = new 'SDL::Rect'
+ prev_rect.'init'( 'height' => 100, 'width' => 101, 'x' => 0, 'y' => 190 )
- .local pmc dest_rect
- dest_rect = new rect_type
- dest_rect.'init'( 'height' => 100, 'width' => 100, 'x' => 0, 'y' => 190 )
+ .local pmc source_rect
+ source_rect = new 'SDL::Rect'
+ source_rect.'init'( 'height' => 56, 'width' => 100, 'x' => 0, 'y' => 0 )
- .local pmc prev_rect
- prev_rect = new rect_type
- prev_rect.'init'( 'height' => 100, 'width' => 101, 'x' => 0, 'y' => 190 )
+ .local pmc black
+ black = new 'SDL::Color'
+ black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
- .local pmc source_rect
- source_rect = new rect_type
- source_rect.'init'( 'height' => 56, 'width' => 100, 'x' => 0, 'y' => 0 )
+ .local pmc image
+ image = new 'SDL::Image'
+ image.'init'( 'examples/sdl/parrot_small.png' )
- .local int color_type
- find_type color_type, 'SDL::Color'
+ .local pmc sprite
+ sprite = new 'SDL::Sprite'
+ sprite.'init'( 'surface' => image, 'source_x' => 0, 'source_y' => 0, 'dest_x' => 0, 'dest_y' => 190, 'bgcolor' => black )
- .local pmc black
- black = new color_type
- black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
+ .local num start_time
+ time start_time
- .local int sprite_type
- find_type sprite_type, 'SDL::Sprite'
+ _animate_on_x_axis( main_screen, sprite, 0, 540, 1)
+ sleep 1
+ _animate_on_x_axis( main_screen, sprite, 540, 0, -1)
- .local pmc image
- .local int image_type
+ .local num end_time
+ time end_time
- find_type image_type, 'SDL::Image'
- image = new image_type
- image.'init'( 'examples/sdl/parrot_small.png' )
+ .local num total_time
+ total_time = end_time - start_time
+ dec total_time
- .local pmc sprite
- sprite = new sprite_type
- sprite.'init'( 'surface' => image, 'source_x' => 0, 'source_y' => 0, 'dest_x' => 0, 'dest_y' => 190, 'bgcolor' => black )
+ .local num fps
+ fps = 1080/total_time
- .local num start_time
- time start_time
+ print "Drew 1080 frames in "
+ print total_time
+ print " seconds ("
+ print fps
+ print " fps)\n"
- _animate_on_x_axis( main_screen, sprite, 0, 540, 1)
- sleep 1
- _animate_on_x_axis( main_screen, sprite, 540, 0, -1)
+ sleep 1
- .local num end_time
- time end_time
-
- .local num total_time
- total_time = end_time - start_time
- dec total_time
-
- .local num fps
- fps = 1080/total_time
-
- print "Drew 1080 frames in "
- print total_time
- print " seconds ("
- print fps
- print " fps)\n"
-
- sleep 1
-
- app.'quit'()
- end
+ app.'quit'()
+ end
.end
.sub _animate_on_x_axis
- .param pmc screen
- .param pmc sprite
- .param int start_pos
- .param int end_pos
- .param int step_size
+ .param pmc screen
+ .param pmc sprite
+ .param int start_pos
+ .param int end_pos
+ .param int step_size
- .local int x_pos
- x_pos = start_pos
+ .local int x_pos
+ x_pos = start_pos
- .local pmc prev_rect
- .local pmc rect
+ .local pmc prev_rect
+ .local pmc rect
- .local pmc rect_array
- rect_array = new Array
- set rect_array, 2
+ .local pmc rect_array
+ rect_array = new Array
+ set rect_array, 2
_loop:
- add x_pos, step_size
- sprite.'x'( x_pos )
- (prev_rect, rect) = sprite.'draw_undraw'( screen )
- set rect_array[ 0 ], prev_rect
- set rect_array[ 1 ], rect
-
- screen.'update_rects'( rect_array )
- if x_pos != end_pos goto _loop
+ add x_pos, step_size
+ sprite.'x'( x_pos )
+ (prev_rect, rect) = sprite.'draw_undraw'( screen )
+ set rect_array[ 0 ], prev_rect
+ set rect_array[ 1 ], rect
+
+ screen.'update_rects'( rect_array )
+ if x_pos != end_pos goto _loop
.end
=head1 AUTHOR
View
154 examples/sdl/anim_image_dblbuf.pir
@@ -6,115 +6,99 @@ anim_image_dblbuf.pir - animate an image in a doublebuffered Parrot SDL window
To run this file, run the following command from the Parrot root directory:
- $ ./parrot examples/sdl/anim_image_dblbuf.pir
- Drew 540 frames in 2.200484 seconds (245.400580 fps)
- $
+ $ ./parrot examples/sdl/anim_image_dblbuf.pir
+ Drew 540 frames in 2.200484 seconds (245.400580 fps)
+ $
=cut
.sub _main :main
- load_bytecode "library/SDL/App.pir"
- load_bytecode "library/SDL/Color.pir"
- load_bytecode "library/SDL/Rect.pir"
- load_bytecode "library/SDL/Image.pir"
- load_bytecode "library/SDL/Sprite.pir"
+ load_bytecode "library/SDL/App.pir"
+ load_bytecode "library/SDL/Color.pir"
+ load_bytecode "library/SDL/Rect.pir"
+ load_bytecode "library/SDL/Image.pir"
+ load_bytecode "library/SDL/Sprite.pir"
- .local pmc app
- .local int app_type
+ .local pmc app
+ app = new 'SDL::App'
+ app.init( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1073741825 )
- find_type app_type, 'SDL::App'
- app = new app_type
- app.init( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1073741825 )
+ .local pmc main_screen
+ main_screen = app.'surface'()
- .local pmc main_screen
- main_screen = app.'surface'()
+ .local pmc dest_rect
+ dest_rect = new 'SDL::Rect'
+ dest_rect.'init'( 'height' => 100, 'width' => 100, 'x' => 0, 'y' => 190 )
- .local int rect_type
- find_type rect_type, 'SDL::Rect'
+ .local pmc prev_rect
+ prev_rect = new 'SDL::Rect'
+ prev_rect.'init'( 'height' => 100, 'width' => 101, 'x' => 0, 'y' => 190 )
- .local pmc dest_rect
- dest_rect = new rect_type
- dest_rect.'init'( 'height' => 100, 'width' => 100, 'x' => 0, 'y' => 190 )
+ .local pmc source_rect
+ source_rect = new 'SDL::Rect'
+ source_rect.'init'( 'height' => 56, 'width' => 100, 'x' => 0, 'y' => 0 )
- .local pmc prev_rect
- prev_rect = new rect_type
- prev_rect.'init'( 'height' => 100, 'width' => 101, 'x' => 0, 'y' => 190 )
+ .local pmc black
+ black = new 'SDL::Color'
+ black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
- .local pmc source_rect
- source_rect = new rect_type
- source_rect.'init'( 'height' => 56, 'width' => 100, 'x' => 0, 'y' => 0 )
+ .local pmc image
+ image = new 'SDL::Image'
+ image.'init'( 'examples/sdl/parrot_small.png' )
- .local int color_type
- find_type color_type, 'SDL::Color'
+ .local pmc sprite
+ sprite = new 'SDL::Sprite'
+ sprite.'init'( 'surface' => image, 'source_x' => 0, 'source_y' => 0, 'dest_x' => 0, 'dest_y' => 190, 'bgcolor' => black )
- .local pmc black
- black = new color_type
- black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
+ .local num start_time
+ time start_time
- .local int sprite_type
- find_type sprite_type, 'SDL::Sprite'
+ _animate_on_x_axis( main_screen, sprite, 0, 540, 2)
+ sleep 1
+ _animate_on_x_axis( main_screen, sprite, 540, 0, -2)
- .local pmc image
- .local int image_type
+ .local num end_time
+ time end_time
- find_type image_type, 'SDL::Image'
- image = new image_type
- image.'init'( 'examples/sdl/parrot_small.png' )
+ .local num total_time
+ total_time = end_time - start_time
+ dec total_time
+ .local num fps
+ fps = 540 / total_time
- .local pmc sprite
- sprite = new sprite_type
- sprite.'init'( 'surface' => image, 'source_x' => 0, 'source_y' => 0, 'dest_x' => 0, 'dest_y' => 190, 'bgcolor' => black )
+ print "Drew 540 frames in "
+ print total_time
+ print " seconds ("
+ print fps
+ print " fps)\n"
- .local num start_time
- time start_time
+ sleep 1
- _animate_on_x_axis( main_screen, sprite, 0, 540, 2)
- sleep 1
- _animate_on_x_axis( main_screen, sprite, 540, 0, -2)
-
- .local num end_time
- time end_time
-
- .local num total_time
- total_time = end_time - start_time
- dec total_time
-
- .local num fps
- fps = 540/total_time
-
- print "Drew 540 frames in "
- print total_time
- print " seconds ("
- print fps
- print " fps)\n"
-
- sleep 1
-
- app.'quit'()
- end
+ app.'quit'()
+ end
.end
.sub _animate_on_x_axis
- .param pmc screen
- .param pmc sprite
- .param int start_pos
- .param int end_pos
- .param int step_size
- # PMCs:
- # destination SDL::Surface and SDL::Sprite to animate
- # Ints:
- # starting and x coordinates and number of pixels to move at a time
-
- .local int x_pos
- x_pos = start_pos
+ .param pmc screen
+ .param pmc sprite
+ .param int start_pos
+ .param int end_pos
+ .param int step_size
+ # PMCs:
+ # destination SDL::Surface and SDL::Sprite to animate
+ # Ints:
+ # starting and x coordinates and number of pixels to move at a time
+
+ .local int x_pos
+ x_pos = start_pos
_loop:
- add x_pos, step_size
- sprite.'x'( x_pos )
- sprite.'draw'( screen )
- screen.'flip'()
- if x_pos != end_pos goto _loop
+ add x_pos, step_size
+ sprite.'x'( x_pos )
+ sprite.'draw'( screen )
+ screen.'flip'()
+ if x_pos != end_pos goto _loop
.end
=head1 AUTHOR
@@ -123,7 +107,7 @@ chromatic, E<lt>chromatic at wgz dot orgE<gt>.
=head1 COPYRIGHT
-Copyright (C) 2004, The Perl Foundation.
+Copyright (C) 2004-2007, The Perl Foundation.
=cut