Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement PROCESS::
  • Loading branch information
sorear committed Jul 26, 2010
1 parent c085987 commit 3daf2eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Body.pm
Expand Up @@ -154,7 +154,12 @@ use CgOp ();
my ($self, @components) = @_;

my $pkgcg;
if ($components[0] eq 'GLOBAL::') {
# TODO: S02 says PROCESS:: and GLOBAL:: are also accessible as lexical
# packages in UNIT::.
if ($components[0] eq 'PROCESS::') {
$pkgcg = CgOp::rawsget('Kernel.Process');
shift @components;
} elsif ($components[0] eq 'GLOBAL::') {
$pkgcg = CgOp::scopedlex('$?GLOBAL');
shift @components;
} elsif ($components[0] eq 'OUR::') {
Expand Down
1 change: 1 addition & 0 deletions CodeGen.pm
Expand Up @@ -50,6 +50,7 @@ use 5.010;

'Kernel.ContextHelper' => [m => 'Variable'],
'Kernel.StrP' => [f => 'IP6'],
'Kernel.Process' => [f => 'Variable'],
'Kernel.Global' => [f => 'Variable'],
'Kernel.PackageLookup' => [m => 'Variable'],
'Kernel.SlurpyHelper' => [m => 'List<Variable>'],
Expand Down
15 changes: 14 additions & 1 deletion Kernel.cs
Expand Up @@ -629,7 +629,16 @@ public class Kernel {
}
th = th.caller;
}
return PackageLookup(GlobalO, name.Remove(1,1));
name = name.Remove(1,1);
Dictionary<string,Variable> gstash = (Dictionary<string,Variable>)
(((CLRImportObject)GlobalO).val);
Variable v;

if (gstash.TryGetValue(name, out v)) {
return v;
} else {
return PackageLookup(ProcessO, name);
}
}

public static Variable DefaultNew(IP6 proto) {
Expand Down Expand Up @@ -679,6 +688,8 @@ public class Kernel {
// XXX should be per-unit
public static Variable Global;
public static IP6 GlobalO;
public static Variable Process;
public static IP6 ProcessO;

static Kernel() {
SubMO = new DynMetaObject("Sub");
Expand All @@ -696,6 +707,8 @@ public class Kernel {

GlobalO = new CLRImportObject(new Dictionary<string,Variable>());
Global = NewROScalar(GlobalO);
ProcessO = new CLRImportObject(new Dictionary<string,Variable>());
Process = NewROScalar(ProcessO);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions test.pl
Expand Up @@ -2,7 +2,7 @@

use Test;

plan 115;
plan 117;

ok 1, "one is true";
ok 2, "two is also true";
Expand Down Expand Up @@ -352,8 +352,13 @@
foo(99);
ok !$*BAR.defined, "contextuals undefined are undef";

$PROCESS::qaax = 555;
ok $*qaax == 555, "contextuals default to PROCESS";
$GLOBAL::qeex = 5;
$PROCESS::qeex = 3;
ok $*qeex == 5, "GLOBAL takes precedence";
$GLOBAL::quux = 111;
ok $*quux == 111, "contextuals default to GLOBAL";
ok $*quux == 111, "contextuals default to GLOBAL too";
{
my $*quux = 222;
ok $*quux == 222, "but can be overriden";
Expand Down

0 comments on commit 3daf2eb

Please sign in to comment.