Author: chromatic
Date: Sat Jun  9 14:03:19 2007
New Revision: 18893

Modified:
   trunk/   (props changed)
   trunk/languages/perl6/src/PAST/Grammar.tg
   trunk/languages/perl6/src/builtins/io.pir

Log:
 [EMAIL PROTECTED]:  chromatic | 2007-06-09 13:53:17 -0700
 [Perl 6] Added support for use and require.
 
 Note that this also supports import(), where possible.
 
 It's *close* to the specification, but there are some parts that need 
clarification.


Modified: trunk/languages/perl6/src/PAST/Grammar.tg
==============================================================================
--- trunk/languages/perl6/src/PAST/Grammar.tg   (original)
+++ trunk/languages/perl6/src/PAST/Grammar.tg   Sat Jun  9 14:03:19 2007
@@ -73,8 +73,19 @@
     .return tree.'get'('past', $P0, 'Perl6::Grammar::expression')
 
   use_statement:
-    null $P0
-    .return ($P0)
+    .local pmc name
+    name = $P0['version';'ident']
+
+    .local pmc require
+    require = new 'PAST::Op'
+    require.'init'('node' => $P0, 'name' => 'use')
+
+    .local pmc module_name
+    module_name = new 'PAST::Val'
+    module_name.'init'('node' => $P0, 'vtype' => '.Perl6Str', 'name' => name, 
'ctype' => 's~')
+    require.'push'(module_name)
+
+    .return (require)
   block:
     $P1 = tree.'get'('past', $P0, 'Perl6::Grammar::block')
     $P1.'blocktype'('immediate')

Modified: trunk/languages/perl6/src/builtins/io.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/io.pir   (original)
+++ trunk/languages/perl6/src/builtins/io.pir   Sat Jun  9 14:03:19 2007
@@ -34,6 +34,45 @@
     .return (1)
 .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
+    filename  = new .Perl6Str
+    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 pmc p6compiler
+    p6compiler = compreg 'Perl6'
+    p6compiler.'evalfiles'(filename)
+.end
 
 =back
 

Reply via email to