Skip to content

Commit

Permalink
POST::PBCCompiler - use old method to compile
Browse files Browse the repository at this point in the history
Use the code from bacek's PIR::Compiler to generate a PBC file.
  • Loading branch information
Benabik committed Aug 2, 2011
1 parent 9949e55 commit 5f2c12a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions compilers/pct/src/POST/PBCCompiler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,63 @@ method mainpmc($packfile, *%adverbs) {
$view.main_sub();
}

=begin
Emit PBC file.

Long explanation about it:
Currently there is no way in Parrot to generate Packfile and attach it
to Interp via existing API. This function is partially hack to generate
serialized PBC, load it back and execute it (modulus fix for TT#1685).

Best way to deal with such issues is:
1. Switch Interp to use Packfile* PMC internally.
2. Add API calls to attach freshly generated Packfile to current Interp.

Quick "fix" can be:
1. Add "PackFile_unpack_string" function which will accept STRING.
2. Expose this function via Interp (or Packfile PMC method).

Kind of wishful thinking, but we can fix it.

=end

method pbc($post, *%adverbs) {
#pir::trace(4);
my $packfile := self.packfile($post, |%adverbs);

my $main_sub := $post<main_sub>;

my $unlink;
my $filename := ~%adverbs<output>;
if !$filename {
# TODO Add mkstemp into OS PMC.
$filename := "/tmp/temp.pbc";
$unlink := 1;
}

my $handle := pir::new__Ps('FileHandle');
$handle.open($filename, 'w');
$handle.print(~$packfile);
$handle.close();

return sub() {
#pir::trace(1);
pir::load_bytecode($filename);

#if $unlink {
# my $os := pir::new__PS("OS");
# $os.rm($filename);
#}

Q:PIR<
%r = find_lex '$main_sub'
$S99 = %r
%r = find_sub_not_null $S99
%r()
>;
};
}
##########################################
# Emiting pbc
Expand Down

0 comments on commit 5f2c12a

Please sign in to comment.