Skip to content

Commit

Permalink
Refactor $*IN, $*OUT, $*ERR. Add $*PERL. Add --version option.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jul 5, 2010
1 parent 5a5d7ef commit 3312298
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 51 deletions.
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
2010.06
2 changes: 2 additions & 0 deletions build/Makefile.in
Expand Up @@ -314,12 +314,14 @@ $(PERL6_EXE): $(PERL6_PBC)
$(PERL6_PBC): $(S1_PERL6_PBC) src/gen/core.pm
$(PARROT) $(PARROT_ARGS) $(S1_PERL6_PBC) --target=pir $(STAGESTATS) \
src/gen/core.pm > $(CORE_PIR)
$(PERL) build/gen_version.pl > src/gen/version.pir
$(PARROT) $(PARROT_ARGS) -o $(PERL6_PBC) src/Perl6/Compiler.pir

# the stage-1 compiler
$(S1_PERL6_PBC): $(PARROT) $(SOURCES)
$(PERL) -e "" > $(CORE_PIR)
@win32_libparrot_copy@
$(PERL) build/gen_version.pl > src/gen/version.pir
$(PARROT) $(PARROT_ARGS) -o $(S1_PERL6_PBC) src/Perl6/Compiler.pir

$(PERL6_G): $(NQP_EXE) src/Perl6/Grammar.pm
Expand Down
27 changes: 27 additions & 0 deletions build/gen_version.pl
@@ -0,0 +1,27 @@
#! perl

=head1 TITLE
gen_version.pl - script to generate Rakudo version information
=cut

use POSIX 'strftime';

print "# generated by build/gen_version.pl\n";

open(my $fh, "<", "VERSION") or die $!;
my $VERSION = <$fh>;
close $fh;

if (-d '.git' && open(my $GIT, '-|', "git describe")) {
$VERSION = <$GIT>;
close $GIT;
}

chomp $VERSION;
print ".macro_const RAKUDO_VERSION '$VERSION'\n";


my $date = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime);
print ".macro_const RAKUDO_BUILD_DATE '$date'\n";
11 changes: 11 additions & 0 deletions src/Perl6/Compiler.pir
Expand Up @@ -118,6 +118,7 @@ Perl6::Compiler - Perl6 compiler

.loadlib 'os'
.loadlib 'file'
.include 'src/gen/version.pir'
.include 'src/gen/builtins.pir'
.include 'src/gen/signature_pm.pir'
.include 'src/gen/parameter_pm.pir'
Expand Down Expand Up @@ -222,6 +223,16 @@ Perl6::Compiler - Perl6 compiler
exit 0
.end

.sub 'version' :method
say ''
print 'This is Rakudo Perl 6, version '
say .RAKUDO_VERSION
say ''
say 'Copyright 2008-2010, The Perl Foundation'
say ''
exit 0
.end

.sub '' :anon
.annotate 'file', 'CORE.setting'
.end
Expand Down
95 changes: 44 additions & 51 deletions src/cheats/process.pm
@@ -1,57 +1,50 @@
# Really we should be able to write $PROCESS::IN := ...

INIT {
Q:PIR {
.local pmc IO
IO = get_hll_global 'IO'
package PROCESS {
INIT {
our $IN = IO.new(:PIO(pir::getstdin__P));
our $OUT = IO.new(:PIO(pir::getstdout__P));
our $ERR = IO.new(:PIO(pir::getstderr__P));

$P0 = getstdin
$P0.'encoding'('utf8')
$P0 = IO.'new'('PIO'=>$P0)
set_hll_global ['PROCESS'], '$IN', $P0
our $PERL = {
name => 'Rakudo',
version => Q:PIR { %r = box .RAKUDO_VERSION }
};

$P0 = getstdout
$P0.'encoding'('utf8')
$P0 = IO.'new'('PIO'=>$P0)
set_hll_global ['PROCESS'], '$OUT', $P0

$P0 = getstderr
$P0.'encoding'('utf8')
$P0 = IO.'new'('PIO'=>$P0)
set_hll_global ['PROCESS'], '$ERR', $P0

## set up $*OS, $*OSVER $*EXECUTABLE_NAME
.include 'sysinfo.pasm'
.local string info
info = sysinfo .SYSINFO_PARROT_OS_VERSION
$P0 = new ['Str']
$P0 = info
set_hll_global ['PROCESS'], '$OSVER', $P0
## do the OS last so that the PID workaround can use info
info = sysinfo .SYSINFO_PARROT_OS
$P0 = new ['Str']
$P0 = info
set_hll_global ['PROCESS'], '$OS', $P0

## Set up $*PID. Parrot doesn't give us the PID for now.
## idea: http://irclog.perlgeek.de/parrot/2010-04-19#i_2242900
## Well, this file *is* in the cheats directory... :-)
.local pmc library
.local string getpid_func
null library
getpid_func = 'getpid'
if info != 'MSWin32' goto setup_io_non_MSWin32
## Do it differently on Windows
library = loadlib 'kernel32'
getpid_func = 'GetCurrentProcessId'
setup_io_non_MSWin32:
$P0 = dlfunc library, getpid_func, 'i'
$I0 = 0
unless $P0 goto setup_io_no_getpid_func
$I0 = $P0()
setup_io_no_getpid_func:
$P0 = box $I0
set_hll_global ['PROCESS'], '$PID', $P0
## Parrot request: http://trac.parrot.org/parrot/ticket/1564
Q:PIR {
## set up $*OS, $*OSVER $*EXECUTABLE_NAME
.include 'sysinfo.pasm'
.local string info
info = sysinfo .SYSINFO_PARROT_OS_VERSION
$P0 = new ['Str']
$P0 = info
set_hll_global ['PROCESS'], '$OSVER', $P0
## do the OS last so that the PID workaround can use info
info = sysinfo .SYSINFO_PARROT_OS
$P0 = new ['Str']
$P0 = info
set_hll_global ['PROCESS'], '$OS', $P0

## Set up $*PID. Parrot doesn't give us the PID for now.
## idea: http://irclog.perlgeek.de/parrot/2010-04-19#i_2242900
## Well, this file *is* in the cheats directory... :-)
.local pmc library
.local string getpid_func
null library
getpid_func = 'getpid'
if info != 'MSWin32' goto setup_io_non_MSWin32
## Do it differently on Windows
library = loadlib 'kernel32'
getpid_func = 'GetCurrentProcessId'
setup_io_non_MSWin32:
$P0 = dlfunc library, getpid_func, 'i'
$I0 = 0
unless $P0 goto setup_io_no_getpid_func
$I0 = $P0()
setup_io_no_getpid_func:
$P0 = box $I0
set_hll_global ['PROCESS'], '$PID', $P0
## Parrot request: http://trac.parrot.org/parrot/ticket/1564
}
}
}

0 comments on commit 3312298

Please sign in to comment.