Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'hll-load-library'
  • Loading branch information
tene committed May 18, 2009
2 parents 1203649 + 23faa00 commit 26dfbab
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
26 changes: 24 additions & 2 deletions perl6.pir
Expand Up @@ -58,7 +58,7 @@ Creates the Perl 6 compiler by subclassing a C<PCT::HLLCompiler> object.

load_bytecode 'config.pbc'

perl6.'language'('Perl6')
perl6.'language'('perl6')
$P0 = get_hll_namespace ['Perl6';'Grammar']
perl6.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Perl6';'Grammar';'Actions']
Expand Down Expand Up @@ -353,7 +353,7 @@ to the Perl 6 compiler.
exit 0
not_harness:

$P0 = compreg 'Perl6'
$P0 = compreg 'perl6'
$P1 = $P0.'command_line'(args_str, 'encoding'=>'utf8', 'transcode'=>'ascii')

.include 'iterator.pasm'
Expand Down Expand Up @@ -413,6 +413,28 @@ to the Perl 6 compiler.
.return (list)
.end


.sub 'fetch-library' :method
.param pmc request
.local pmc name, retval, library, inc_hash
name = request['name']
$S0 = join '::', name
retval = 'require'($S0, 'module'=>1)
if null retval goto fail
library = new 'Hash'
library['name'] = name
inc_hash = get_hll_global '%INC'
$S0 = inc_hash[$S0]
library['filename'] = $S0
$P0 = get_hll_global name, 'EXPORT'
library['symbols'] = $P0
$P0 = get_hll_namespace name
library['namespace'] = $P0
.return (library)
fail:
.return (retval)
.end

=back

=item postload()
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/control.pir
Expand Up @@ -369,7 +369,7 @@ on error.
goto got_lang
no_lang:
push_eh catch
compiler = compreg 'Perl6'
compiler = compreg 'perl6'
got_lang:
invokable = compiler.'compile'(code)

Expand Down
38 changes: 34 additions & 4 deletions src/builtins/eval.pir
Expand Up @@ -34,7 +34,7 @@ itself can be found in src/builtins/control.pir.
lang = options['lang']
if lang == 'Parrot' goto lang_parrot
if lang goto lang_compile
lang = 'Perl6'
lang = 'perl6'
lang_compile:
.local pmc compiler
compiler = compreg lang
Expand Down Expand Up @@ -129,7 +129,7 @@ itself can be found in src/builtins/control.pir.
$P0 = new 'List'
set_hll_global ['Perl6';'Grammar';'Actions'], '@?BLOCK', $P0
inc_hash[name] = realfilename
result = 'evalfile'(realfilename, 'lang'=>'Perl6')
result = 'evalfile'(realfilename, 'lang'=>'perl6')
set_hll_global ['Perl6';'Grammar';'Actions'], '@?NS', outer_ns_chain
set_hll_global ['Perl6';'Grammar';'Actions'], '@?BLOCK', outer_blocks

Expand All @@ -143,6 +143,38 @@ itself can be found in src/builtins/control.pir.
.param pmc args :slurpy
.param pmc options :slurpy :named

.local pmc ver, compiler_obj
.local string lang
compiler_obj = compreg 'perl6'

# This HLL stuff *should* be integrated with the rest... I spent an hour on it and failed.
ver = options['ver']
if null ver goto no_hll
$P0 = ver['lang']
if null $P0 goto no_hll
lang = $P0
.local pmc compiler, request, library, imports, callerns
$P0 = getinterp
callerns = $P0['namespace';1]
'load-language'(lang)
compiler = compreg lang
request = new 'Hash'
$P0 = compiler_obj.'parse_name'(module)
request['name'] = $P0
library = compiler.'fetch-library'(request)
imports = library['symbols']
imports = imports['DEFAULT']
.local pmc ns_iter, item
ns_iter = new 'Iterator', imports
import_loop:
unless ns_iter goto import_loop_end
$S0 = shift ns_iter
$P0 = imports[$S0]
callerns[$S0] = $P0
goto import_loop
import_loop_end:
.return (library)
no_hll:
# Require module.
.local pmc retval
retval = 'require'(module, 'module'=>1)
Expand All @@ -157,8 +189,6 @@ itself can be found in src/builtins/control.pir.

# See if we've had a namespace name passed in.
.local pmc import_ns
.local pmc compiler_obj
compiler_obj = compreg 'Perl6'
$P0 = options['import_to']
if null $P0 goto use_caller_ns
$S0 = $P0
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/guts.pir
Expand Up @@ -744,7 +744,7 @@ Add a trait with the given C<type> and C<name> to C<metaclass>.

is:
## get the (parrot)class object associated with name
$P0 = compreg 'Perl6'
$P0 = compreg 'perl6'
$P0 = $P0.'parse_name'(name)
$S0 = pop $P0
$P0 = get_hll_global $P0, $S0
Expand All @@ -769,7 +769,7 @@ Add a trait with the given C<type> and C<name> to C<metaclass>.

does:
## get the Role object for the role to be composed
$P0 = compreg 'Perl6'
$P0 = compreg 'perl6'
$P0 = $P0.'parse_name'(name)
$S0 = pop $P0
$P0 = get_hll_global $P0, $S0
Expand Down Expand Up @@ -971,7 +971,7 @@ and C<type>.
.param pmc var
.param string name
.param pmc arg :slurpy
$P0 = compreg 'Perl6'
$P0 = compreg 'perl6'
$P0 = $P0.'parse_name'(name)
$S0 = pop $P0
$P0 = get_hll_global $P0, $S0
Expand Down
7 changes: 6 additions & 1 deletion src/parrot/misc.pir
Expand Up @@ -44,4 +44,9 @@ Note that we currently do this by adding the method to Parrot's
.end
.namespace []
# work around a parrot bug.
.sub 'load-language'
.param string lang
load_language lang
.end
2 changes: 1 addition & 1 deletion src/parser/actions.pm
Expand Up @@ -47,7 +47,7 @@ method TOP($/) {
else {
$main := PAST::Block.new( :pirflags(':main') );
$main.loadinit().push(
PAST::Op.new( :inline('$P0 = compreg "Perl6"',
PAST::Op.new( :inline('$P0 = compreg "perl6"',
'unless null $P0 goto have_perl6',
'load_bytecode "perl6.pbc"',
'have_perl6:')
Expand Down
2 changes: 1 addition & 1 deletion src/parser/methods.pir
Expand Up @@ -28,7 +28,7 @@ Registers a type in the namespace.
# Parse name.
.local pmc ns
.local string short_name
$P0 = compreg 'Perl6'
$P0 = compreg 'perl6'
ns = $P0.'parse_name'(name)
short_name = pop ns

Expand Down

0 comments on commit 26dfbab

Please sign in to comment.