Skip to content

Commit

Permalink
Revise %*ENV processing to resolve RT #57400.
Browse files Browse the repository at this point in the history
Fix a bug in initialization of contextual variables.
  • Loading branch information
pmichaud committed Sep 5, 2009
1 parent 8566a62 commit 825074a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
50 changes: 47 additions & 3 deletions src/builtins/globals.pir
Expand Up @@ -18,10 +18,8 @@ src/builtins/globals.pir - initialize miscellaneous global variables
p6meta = get_hll_global ['Perl6Object'], '$!P6META'

## set up %*ENV
$P0 = get_hll_global 'Hash'
p6meta.'register'('Env', 'parent'=>$P0, 'protoobject'=>$P0)
.local pmc env
env = root_new ['parrot';'Env']
env = '!env_to_hash'()
set_hll_global ['PROCESS'], '%ENV', env

## set up @*INC
Expand Down Expand Up @@ -127,6 +125,52 @@ src/builtins/globals.pir - initialize miscellaneous global variables
.end


.sub '!env_to_hash'
.local pmc env, hash
env = root_new ['parrot';'Env']
hash = new ['Perl6Hash']
$P0 = iter env
env_loop:
unless $P0 goto env_done
$S0 = shift $P0
$S1 = env[$S0]
hash[$S0] = $S1
goto env_loop
env_done:
.return (hash)
.end


.sub '!hash_to_env'
.param pmc hash :optional
.param int has_hash :opt_flag

if has_hash goto have_hash
hash = '!find_contextual'('%*ENV')
have_hash:

.local pmc env
env = root_new ['parrot';'Env']
$P0 = iter env
env_loop:
unless $P0 goto env_done
$S0 = shift $P0
$I0 = exists hash[$S0]
if $I0 goto env_loop
delete env[$S0]
goto env_loop
env_done:

$P0 = iter hash
hash_loop:
unless $P0 goto hash_done
$S0 = shift $P0
$S1 = hash[$S0]
env[$S0] = $S1
goto hash_loop
hash_done:
.end

# Local Variables:
# mode: pir
# fill-column: 100
Expand Down
1 change: 1 addition & 0 deletions src/builtins/io.pir
Expand Up @@ -129,6 +129,7 @@ It is an error to use bare C<unlink> without arguments.
.sub '!qx'
.param string cmd
.local pmc pio
'!hash_to_env'()
pio = open cmd, 'rp'
unless pio goto err_qx
pio.'encoding'('utf8')
Expand Down
3 changes: 3 additions & 0 deletions src/builtins/system.pir
Expand Up @@ -29,6 +29,7 @@ return the status code from the C<spawnw> opcode.
.param string cmd
.local int retval

'!hash_to_env'()
spawnw retval, cmd
.return (retval)
.end
Expand All @@ -39,6 +40,7 @@ return the status code from the C<spawnw> opcode.
.local int retval

unshift args, path
'!hash_to_env'()
spawnw retval, args
.return (retval)
.end
Expand All @@ -47,6 +49,7 @@ return the status code from the C<spawnw> opcode.
.param pmc path_and_args
.local int retval

'!hash_to_env'()
spawnw retval, path_and_args
.return (retval)
.end
Expand Down
1 change: 0 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -2136,7 +2136,6 @@ method variable($/, $key) {
$vardecl.name($varname);
$vardecl.namespace(@ns);
$vardecl.scope('package');
$vardecl.viviself( container_itype($sigil) );
$var<vardecl> := $vardecl;
$twigil := '';
}
Expand Down

0 comments on commit 825074a

Please sign in to comment.