Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Separate out the Rakudo metaclass (calling it ClassHOW) from the Parr…
…ot one, and make sure everything we create uses this metaclass. This means we poke less stuff into p6object's namespace, and paves the way for various other refactors and additions.
  • Loading branch information
jnthn committed Jul 24, 2009
1 parent b198624 commit 9c44089
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build/Makefile.in
Expand Up @@ -41,7 +41,6 @@ SOURCES = perl6.pir \
src/parser/expression.pir \
src/parser/methods.pir \
src/parser/quote_expression.pir \
src/parrot/ClassHOW.pir \
src/parrot/Protoobject.pir \
src/parrot/P6role.pir \
src/parrot/misc.pir \
Expand All @@ -52,6 +51,7 @@ SOURCES = perl6.pir \

BUILTINS_PIR = \
src/classes/Object.pir \
src/classes/ClassHOW.pir \
src/classes/Any.pir \
src/classes/Junction.pir \
src/classes/Signature.pir \
Expand Down
2 changes: 1 addition & 1 deletion build/PARROT_REVISION
@@ -1 +1 @@
40249
40232
5 changes: 2 additions & 3 deletions perl6.pir
Expand Up @@ -22,8 +22,8 @@ This is the base file for the Rakudo Perl 6 compiler.
.local pmc p6meta
load_bytecode 'PCT.pbc'
$P0 = get_root_global ['parrot'], 'P6metaclass'
$P0.'new_class'('Perl6Object', 'name'=>'Object')
p6meta = $P0.'HOW'()
$P1 = $P0.'new_class'('Perl6Object', 'name'=>'Object')
p6meta = $P1.'HOW'()
set_hll_global ['Perl6Object'], '$!P6META', p6meta
.local pmc hllns, parrotns, imports, exports
hllns = get_hll_namespace
Expand Down Expand Up @@ -464,7 +464,6 @@ Currently this does the equivalent of EXPORTALL on the core namespaces.
## This goes at the bottom because the methods end up in the 'parrot'
## HLL namespace.
.HLL 'parrot'
.include 'src/parrot/ClassHOW.pir'
.include 'src/parrot/P6role.pir'
.include 'src/parrot/Protoobject.pir'
.include 'src/parrot/misc.pir'
Expand Down
9 changes: 7 additions & 2 deletions src/builtins/guts.pir
Expand Up @@ -592,6 +592,11 @@ and creating the protoobjects.
goto roles_it_loop
roles_it_loop_end:

# Create a HOW of the right type.
.local pmc how
how = new ['ClassHOW']
setattribute how, 'parrotclass', metaclass

# Create proto-object with default parent being Any or Grammar, unless
# there already is a parent.
$P0 = metaclass.'parents'()
Expand All @@ -603,9 +608,9 @@ and creating the protoobjects.
if $P0 != 'grammar' goto register
$S0 = 'Grammar'
register:
.tailcall p6meta.'register'(metaclass, 'parent'=>$S0)
.tailcall p6meta.'register'(metaclass, 'parent'=>$S0, 'how'=>how)
register_parent_set:
.tailcall p6meta.'register'(metaclass)
.tailcall p6meta.'register'(metaclass, 'how'=>how)
no_pkgtype:
.end

Expand Down
31 changes: 25 additions & 6 deletions src/parrot/ClassHOW.pir → src/classes/ClassHOW.pir
Expand Up @@ -2,15 +2,35 @@

=head1 TITLE

ClassHOW - default metaclass
ClassHOW - default metaclass for Perl 6

=head1 DESCRIPTION

This file for now actually just adds a method or two into P6metaclass. In the
long run, we probably need to subclass that, and make sure we have all of the
methods in here that are defined in the HOW API.
This class subclasses P6metaclass to give Perl 6 specific meta-class behaviors.

=head2 Methods on P6metaclass
=cut

.namespace ['ClassHOW']

.sub 'onload' :anon :init :load
.local pmc p6meta, classhowproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'

# We need to specially construct our subclass of p6metaclass. We also
# make it subclass Object.
$P0 = newclass 'ClassHOW'
$P1 = get_root_global ['parrot'], 'P6metaclass'
$P1 = typeof $P1
addparent $P0, $P1
$P1 = get_hll_global 'Object'
$P1 = p6meta.'get_parrotclass'($P1)
addparent $P0, $P1

# Now rebless p6meta - which means Object's metaclass - into it.
rebless_subclass p6meta, $P0
.end

=head2 Methods on ClassHOW

=over

Expand All @@ -20,7 +40,6 @@ Tests role membership.

=cut

.namespace ['P6metaclass']
.sub 'does' :method
.param pmc obj
.param pmc type
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Exception.pir
Expand Up @@ -4,7 +4,7 @@
.namespace [ 'Perl6Exception' ]

.sub '' :anon :init :load
.local pmc p6meta, failureproto, exceptionproto
.local pmc p6meta, exceptionproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
exceptionproto = p6meta.'new_class'('Perl6Exception', 'parent'=>'Any parrot;Exception', 'attr'=>'$!exception', 'name'=>'Exception')
p6meta.'register'('Exception', 'protoobject'=>exceptionproto)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Failure.pir
Expand Up @@ -4,7 +4,7 @@
.namespace [ 'Failure' ]

.sub '' :anon :init :load
.local pmc p6meta, failureproto, exceptionproto
.local pmc p6meta, failureproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
failureproto = p6meta.'new_class'('Failure', 'parent'=>'parrot;Undef Any', 'attr'=>'$!exception')
p6meta.'register'('Undef', 'parent'=>failureproto, 'protoobject'=>failureproto)
Expand Down

0 comments on commit 9c44089

Please sign in to comment.