Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Prepare for getting rid of Parrot property use.
We use them in a few places to hang things off of code objects, but
there's no reason they can't just be in an attribute.
  • Loading branch information
jnthn committed Apr 22, 2013
1 parent a7f687c commit 61e1e2a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -489,11 +489,13 @@ BEGIN {
# class Code {
# has $!do; # Low level code object
# has $!signature; # Signature object
# has $!compstuff; # Place for the compiler to hang stuff
# ... # Uncomposed
# }
Code.HOW.add_parent(Code, Any);
Code.HOW.add_attribute(Code, BOOTSTRAPATTR.new(:name<$!do>, :type(Mu), :package(Code)));
Code.HOW.add_attribute(Code, BOOTSTRAPATTR.new(:name<$!signature>, :type(Mu), :package(Code)));
Code.HOW.add_attribute(Code, BOOTSTRAPATTR.new(:name<$!compstuff>, :type(Mu), :package(Code)));

# Need clone in here, plus generics instantiation.
Code.HOW.add_method(Code, 'clone', static(sub ($self) {
Expand Down
38 changes: 33 additions & 5 deletions src/Perl6/World.nqp
Expand Up @@ -208,6 +208,9 @@ class Perl6::World is HLL::World {
# List of CHECK blocks to run.
has @!CHECKs;

# Clean-up tasks, to do after CHECK time.
has @!cleanup_tasks;

method BUILD(*%adv) {
@!BLOCKS := [];
@!CODES := [];
Expand All @@ -219,6 +222,7 @@ class Perl6::World is HLL::World {
%!sub_id_to_sc_idx := {};
%!code_object_fixup_list := {};
%!const_cache := {};
@!cleanup_tasks := [];
}

# Creates a new lexical scope and puts it on top of the stack.
Expand Down Expand Up @@ -883,7 +887,12 @@ class Perl6::World is HLL::World {
nqp::bindattr($signature, $sig_type, '$!code', $code);
}

# Takes a code object and the QAST::Block for its body.
# Takes a code object and the QAST::Block for its body. Finalizes the
# setup of the code object, including populated the $!compstuff array.
# This contains 3 elements:
# 0 = the QAST::Block object
# 1 = the compiler thunk
# 2 = the clone callback
method finish_code_object($code, $code_past, $is_dispatcher = 0, :$yada) {
my $fixups := QAST::Stmts.new();
my $des := QAST::Stmts.new();
Expand All @@ -905,6 +914,14 @@ class Perl6::World is HLL::World {
# Stash it under the QAST block unique ID.
%!sub_id_to_code_object{$code_past.cuid()} := $code;

# Create the compiler stuff array and stick it in the code object.
# Also add clearup task to remove it again later.
my @compstuff;
nqp::bindattr($code, $code_type, '$!compstuff', @compstuff);
nqp::push(@!cleanup_tasks, sub () {
nqp::bindattr($code, $code_type, '$!compstuff', nqp::null());
});

# For now, install stub that will dynamically compile the code if
# we ever try to run it during compilation.
my $precomp;
Expand Down Expand Up @@ -948,6 +965,9 @@ class Perl6::World is HLL::World {
my $clone_handler := sub ($orig, $clone) {
my $do := nqp::getattr($clone, $code_type, '$!do');
nqp::markcodestub($do);
nqp::push(@!cleanup_tasks, sub () {
nqp::bindattr($clone, $code_type, '$!compstuff', nqp::null());
});
pir::setprop__0PsP($do, 'CLONE_CALLBACK', $clone_handler);
};
pir::setprop__0PsP($stub, 'CLONE_CALLBACK', $clone_handler);
Expand All @@ -968,8 +988,12 @@ class Perl6::World is HLL::World {
# If we clone the stub, then we must remember to do a fixup
# of it also.
pir::setprop__0PsP($stub, 'CLONE_CALLBACK', sub ($orig, $clone) {
my $tmp := $fixups.unique('tmp_block_fixup');
self.add_object($clone);
nqp::push(@!cleanup_tasks, sub () {
nqp::bindattr($clone, $code_type, '$!compstuff', nqp::null());
});

my $tmp := $fixups.unique('tmp_block_fixup');
$fixups.push(QAST::Stmt.new(
QAST::Op.new(
:op('bind'),
Expand Down Expand Up @@ -1241,8 +1265,10 @@ class Perl6::World is HLL::World {
while $i < $num_subs {
my $subid := $precomp[$i].get_subid();
if nqp::existskey(%!sub_id_to_code_object, $subid) {
nqp::setcodeobj($precomp[$i], %!sub_id_to_code_object{$subid});
nqp::bindattr(%!sub_id_to_code_object{$subid}, $code_type, '$!do', $precomp[$i]);
my $code_obj := %!sub_id_to_code_object{$subid};
nqp::setcodeobj($precomp[$i], $code_obj);
nqp::bindattr($code_obj, $code_type, '$!do', $precomp[$i]);
nqp::bindattr($code_obj, $code_type, '$!compstuff', nqp::null());
}
if nqp::existskey(%!sub_id_to_static_lexpad, $subid) {
$precomp[$i].get_lexinfo.set_static_lexpad(%!sub_id_to_static_lexpad{$subid});
Expand Down Expand Up @@ -1728,12 +1754,14 @@ class Perl6::World is HLL::World {
}
}

# Runs the CHECK phasers and twiddles the PAST to look them up.
# Runs the CHECK phasers and twiddles the QAST to look them up. Also
# runs any other cleanup tasks.
method CHECK() {
for @!CHECKs {
my $result := $_[0]();
$_[1][0] := self.add_constant_folded_result($result);
}
for @!cleanup_tasks { $_() }
}

# Adds required libraries to a compilation unit.
Expand Down
1 change: 1 addition & 0 deletions src/vm/parrot/guts/bind.h
Expand Up @@ -70,6 +70,7 @@ typedef struct {
PMC *sc; /* Serialization context, though we don't care about that here. */
PMC *_do; /* Lower-level code object. */
PMC *signature; /* Signature object. */
PMC *compstuff; /* Place for the compiler to hang stuff */
PMC *state_vars; /* Storage for state variables. */
PMC *phasers; /* Hash mapping phaser names to lists of phasers. */
PMC *dispatchees; /* List of dispatchees, if any. */
Expand Down

0 comments on commit 61e1e2a

Please sign in to comment.