Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Compile time symbol installation becomes a task for the SC builder.
  • Loading branch information
jnthn committed Mar 13, 2011
1 parent e458b36 commit 2b1619e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
24 changes: 24 additions & 0 deletions src/HLL/SerializationContextBuilder.pm
Expand Up @@ -169,6 +169,30 @@ class HLL::Compiler::SerializationContextBuilder {
}
}

# Installs a symbol into the package. Does so immediately, and
# makes sure this happens on deserialization also.
method install_package_symbol(@sym, $obj) {
@sym := pir::clone__PP(@sym);
my $name := ~@sym.pop();

# XXX Eventually, we'll want to do immediate installation.
#pir::get_hll_namespace__PP(@sym).add_var($name, $obj);
#pir::say('# installed ' ~ pir::join('::', @sym) ~ "::" ~ $name);

# Deserialization installation. XXX And fixup for now too.
self.add_event(:deserialize_past(
PAST::Op.new(
:pasttype('bind'),
PAST::Var.new( :name($name), :namespace(@sym), :scope('package') ),
self.get_slot_past_for_object($obj)
)),
:fixup_past(PAST::Op.new(
:pasttype('bind'),
PAST::Var.new( :name($name), :namespace(@sym), :scope('package') ),
self.get_slot_past_for_object($obj)
)));
}

# Creates a meta-object for a package, adds it to the root objects and
# stores an event for the action. Returns the created object.
method pkg_create_mo($how, :$name, :$repr) {
Expand Down
27 changes: 10 additions & 17 deletions src/NQP/Actions.pm
Expand Up @@ -415,8 +415,16 @@ method package_def($/) {
# Get the body code.
my $past := $<block> ?? $<block>.ast !! $<comp_unit>.ast;

# Prefix the class initialization with initial setup. Also install it
# in the symbol table right away.
# Install it in the package or lexpad as needed.
if $*SCOPE eq 'our' || $*SCOPE eq '' {
$past.namespace( $<name><identifier> );
$*SC.install_package_symbol($<name><identifier>, $*PKGMETA);
}
else {
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
}

# Prefix the class initialization with initial setup.
$*PACKAGE-SETUP.unshift(PAST::Stmts.new(
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('type_obj'), :scope('register'), :isdecl(1) ),
Expand All @@ -427,18 +435,6 @@ method package_def($/) {
PAST::Var.new( :name('type_obj'), :scope('register') )
)
));

# Install it in the package or lexpad as needed.
if $*SCOPE eq 'our' || $*SCOPE eq '' {
$past.namespace( $<name><identifier> );
$*PACKAGE-SETUP[0].push(PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name($name), :namespace(@ns), :scope('package') ),
PAST::Var.new( :name('type_obj'), :scope('register') )
));
}
else {
$/.CURSOR.panic("$*SCOPE scoped packages are not supported");
}

# Evaluate everything in the package in-line unless this is a generic
# type in which case it needs delayed evaluation. Normally, $?CLASS is
Expand Down Expand Up @@ -523,9 +519,6 @@ method package_def($/) {
),
PAST::Var.new( :name('type_obj'), :scope('register') )
));

# Set up slot for the type object to live in.
@BLOCK[0][0].unshift(PAST::Var.new( :name($name), :namespace(@ns), :scope('package'), :isdecl(1) ));

# Attach the class code to run at loadinit time.
$past.loadinit.push(PAST::Block.new( :blocktype('immediate'), $*PACKAGE-SETUP ));
Expand Down

0 comments on commit 2b1619e

Please sign in to comment.