Author: pmichaud
Date: Tue Aug 19 23:01:43 2008
New Revision: 30371

Added:
   trunk/languages/perl6/src/builtins/eval.pir   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/languages/perl6/config/makefiles/root.in
   trunk/languages/perl6/src/builtins/globals.pir
   trunk/languages/perl6/src/builtins/io.pir

Log:
[rakudo]: enable precompiled Test.pm
* Add @*INC and %*INC
* Update 'evalfile', 'require', and 'use'
* On my system, speeds spectest_regression by about 67%


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Tue Aug 19 23:01:43 2008
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Aug 20 01:57:37 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Wed Aug 20 04:58:13 2008 UT
 #
 # See tools/dev/install_files.pl for documentation on the
 # format of this file.
@@ -1914,6 +1914,7 @@
 languages/perl6/src/builtins/cmp.pir                        [perl6]
 languages/perl6/src/builtins/control.pir                    [perl6]
 languages/perl6/src/builtins/enums.pir                      [perl6]
+languages/perl6/src/builtins/eval.pir                       [perl6]
 languages/perl6/src/builtins/globals.pir                    [perl6]
 languages/perl6/src/builtins/guts.pir                       [perl6]
 languages/perl6/src/builtins/io.pir                         [perl6]

Modified: trunk/languages/perl6/config/makefiles/root.in
==============================================================================
--- trunk/languages/perl6/config/makefiles/root.in      (original)
+++ trunk/languages/perl6/config/makefiles/root.in      Tue Aug 19 23:01:43 2008
@@ -34,7 +34,7 @@
 #CONDITIONED_LINE(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X 
compilation/linking
 #CONDITIONED_LINE(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@
 
-all: perl6.pbc
+all: perl6.pbc Test.pir
 
 xmas: perl6$(EXE)
 
@@ -85,6 +85,7 @@
   src/builtins/assign.pir \
   src/builtins/cmp.pir \
   src/builtins/control.pir \
+  src/builtins/eval.pir \
   src/builtins/enums.pir \
   src/builtins/guts.pir \
   src/builtins/io.pir \
@@ -118,6 +119,9 @@
 installable_perl6$(EXE): perl6.pbc
        $(PBC_TO_EXE) perl6.pbc --install
 
+Test.pir: Test.pm perl6.pbc
+       $(PARROT) $(PARROT_ARGS) perl6.pbc --target=pir --output=Test.pir 
Test.pm
+
 src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg 
src/parser/grammar-oper.pg
        $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
            --output=src/gen_grammar.pir \
@@ -234,6 +238,7 @@
   perl6$(O) \
   perl6$(EXE) \
   installable_perl6$(EXE) \
+  Test.pir \
   src/gen_grammar.pir \
   src/gen_actions.pir \
   src/gen_builtins.pir \

Added: trunk/languages/perl6/src/builtins/eval.pir
==============================================================================
--- (empty file)
+++ trunk/languages/perl6/src/builtins/eval.pir Tue Aug 19 23:01:43 2008
@@ -0,0 +1,142 @@
+## $Id$
+
+=head1 NAME
+
+src/builtins/eval.pir - Perl6 evaluators
+
+=head1 DESCRIPTION
+
+This file implements methods and functions that evaluate code,
+such as C<eval>, C<require>, and C<use>.
+
+=head1 Methods
+
+=over 4
+
+=cut
+
+.namespace []
+.sub 'onload' :anon :init :load
+    $P0 = get_hll_namespace ['Any']
+    '!EXPORT'('evalfile', 'from'=>$P0)
+.end
+
+
+.namespace ['Any']
+.sub 'evalfile' :method :multi(_)
+    .param pmc options         :slurpy :named
+
+    .local string filename
+    filename = self
+
+    .local string lang
+    lang = options['lang']
+    if lang == 'Parrot' goto lang_parrot
+    if lang goto lang_compile
+    lang = 'Perl6'
+  lang_compile:
+    .local pmc compiler
+    compiler = compreg lang
+    .return compiler.'evalfiles'(filename)
+
+  lang_parrot:
+    load_bytecode filename
+    .return (1)
+.end
+
+
+.namespace []
+.sub 'require' :multi(_)
+    .param string name
+    .param pmc options         :named :slurpy
+
+    .local int ismodule
+    .local pmc module
+    ismodule = 0
+    module = options['module']
+    if null module goto have_name
+    ismodule = istrue module
+    unless ismodule goto have_name
+
+    ##  convert '::' to '/'
+  slash_convert:
+    $I0 = index name, '::'
+    if $I0 < 0 goto have_name
+    substr name, $I0, 2, '/'
+    goto slash_convert
+
+  have_name:
+    ##  see if we loaded this already
+    .local pmc inc_hash
+    inc_hash = get_hll_global '%INC'
+    $I0 = exists inc_hash[name]
+    unless $I0 goto require_name
+    $I0 = defined inc_hash[name]
+    .return ($I0)
+
+  require_name:
+    ##  loop through @INC
+    .local pmc inc_it
+    $P0 = get_hll_global '@INC'
+    inc_it = iter $P0
+  inc_loop:
+    unless inc_it goto inc_end
+    .local string basename, realfilename
+    $S0 = shift inc_it
+    basename = concat $S0, '/'
+    basename .= name
+    if ismodule goto try_module
+    realfilename = basename
+    $I0 = stat realfilename, 0
+    if $I0 goto eval_perl6
+    goto inc_loop
+  try_module:
+    realfilename = concat basename, '.pbc'
+    $I0 = stat realfilename, 0
+    if $I0 goto eval_parrot
+    realfilename = concat basename, '.pir'
+    $I0 = stat realfilename, 0
+    if $I0 goto eval_parrot
+    realfilename = concat basename, '.pm'
+    $I0 = stat realfilename, 0
+    if $I0 goto eval_perl6
+    goto inc_loop
+  inc_end:
+    $S0 = concat "Can't find ", basename
+    concat $S0, ' in @INC'
+    'die'($S0)
+    .return (0)
+
+  eval_parrot:
+    .local pmc result
+    result = 'evalfile'(realfilename, 'lang'=>'Parrot')
+    goto done
+
+  eval_perl6:
+    result = 'evalfile'(realfilename, 'lang'=>'Perl6')
+
+  done:
+    inc_hash[name] = realfilename
+    .return (result)
+.end
+
+
+.sub 'use'
+    .param string module
+    .param pmc args            :slurpy
+    .param pmc options         :slurpy :named
+
+    $P0 = 'require'(module, 'module'=>1)
+.end
+
+
+=back
+
+=cut
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+

Modified: trunk/languages/perl6/src/builtins/globals.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/globals.pir      (original)
+++ trunk/languages/perl6/src/builtins/globals.pir      Tue Aug 19 23:01:43 2008
@@ -15,8 +15,20 @@
     ##  set up %*ENV
     $P0 = get_hll_global 'Hash'
     p6meta.'register'('Env', 'parent'=>$P0, 'protoobject'=>$P0)
-    $P0 = new 'Env'
-    set_hll_global '%ENV', $P0
+    .local pmc env
+    env = new 'Env'
+    set_hll_global '%ENV', env
+
+    ##  set up @*INC
+    $S0 = env['PERL6LIB']
+    $P0 = split ':', $S0
+    push $P0, '.'
+    $P0 = 'list'($P0)
+    set_hll_global '@INC', $P0
+
+    ##  set up %*INC
+    $P0 = new 'Perl6Hash'
+    set_hll_global '%INC', $P0
 
     ##  create $*IN, $*OUT, $*ERR filehandles
     .local pmc pio, perl6io, perl6ioclass

Modified: trunk/languages/perl6/src/builtins/io.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/io.pir   (original)
+++ trunk/languages/perl6/src/builtins/io.pir   Tue Aug 19 23:01:43 2008
@@ -49,58 +49,6 @@
 .end
 
 
-.sub 'use'
-    .param pmc module
-    .param pmc args :slurpy
-
-    .local string module_string
-    module_string = module
-
-    .local pmc path
-    path     = split '::', module_string
-
-    .local string file_string
-    file_string = join '/', path
-
-    .local pmc filename
-    $P0 = get_hll_global 'Str'
-    filename  = $P0.'new'()
-    filename  = file_string
-    filename .= '.pm'
-
-    require(filename)
-
-    .local pmc import
-    import = find_global module_string, 'import'
-
-    .local int have_import
-    have_import = defined import
-    unless have_import goto import_finished
-    import(args :flat)
-
-  import_finished:
-
-.end
-
-.sub 'require'
-    .param pmc filename
-    .local string path
-
-    $S0 = substr filename, 0, 1
-    if $S0 == '/' goto eval_file
-
-    .local pmc env
-    .local string perl6lib
-    env = new 'Env'
-    perl6lib = env['PERL6LIB']
-    path = '!find_file_in_path'(perl6lib, filename)
-
-  eval_file:
-    .local pmc p6compiler
-    p6compiler = compreg 'Perl6'
-    p6compiler.'evalfiles'(path)
-.end
-
 .sub 'open'
     .param string filename
     .param int r :named('r') :optional

Reply via email to