Permalink
Browse files

[STD,CORE,etc.]

Major refactor of symbol tables to get rid of all backpointers.
OUTER:: is now always a symbolic link, and all scopes are indexable by id
in a global hash in $ALL.  All private stash attrs start with ! now.


git-svn-id: http://svn.pugscode.org/pugs@28525 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 0dd0bb1 commit 844fa0bafc1fa1e160724606c6b41c53db163690 lwall committed Oct 1, 2009
Showing with 122 additions and 81 deletions.
  1. +9 −3 CORE.pad
  2. +1 −2 CORE.setting
  3. +26 −18 Cursor.pmc
  4. +12 −4 NULL.pad
  5. +4 −4 STASH.pmc
  6. +70 −50 STD.pm
View
@@ -1,9 +1,10 @@
+my $id = 'MY:file<CORE.pad>:line(1):pos(0)';
use strict;
use STASH;
use NAME;
my $file = { name => 'CORE.pad' };
my $core = STASH::->new( _file => $file, _line => __LINE__,
- _id => ['MY:file<CORE.pad>'];
+ '!id' => [$id];
Bool => NAME::->new( name => 'Bool', file => $file, line => __LINE__ ),
'Bool::' => STASH::->new( _file => $file, _line => __LINE__,
True => NAME::->new( name => 'True', file => $file, line => __LINE__ ),
@@ -376,12 +377,17 @@ sub fixup {
}
}
for my $k (keys %$stash) {
- next if $k =~ /^_/;
+ next if $k =~ /^!/;
my $v = $stash->{$k};
if ($v->{export}) {
$stash->{'EXPORT::'}{$v->{export}}{$k} = $v;
}
}
}
fixup($core);
-$core;
+my $ALL = {
+ 'CORE' => $core,
+ 'SETTING' => $core,
+ $id => $core,
+};
+$ALL;
View
@@ -69,8 +69,7 @@ class Num {
constant e is export = 2.71828_18284_59045_23536_02874_71352_66249;
constant i is export = 1i;
}
-import Num;
-# XXX hand export till import works
+import Num <pi e i>;
constant pi = 3.14159_26535_89793_23846_26433_83279_50288;
constant e = 2.71828_18284_59045_23536_02874_71352_66249;
constant i = 1i;
View
@@ -137,7 +137,6 @@ sub parsefile {
$result->you_were_here;
}
elsif ($file =~ /\.pm$/) {
- $::YOU_WERE_HERE = $::UNIT;
$result->you_were_here;
}
$result;
@@ -203,10 +202,9 @@ sub gettrait {
if ($traitname eq 'export') {
if (defined $text) {
$text =~ s/://g;
- $text .= '::';
}
else {
- $text = 'DEFAULT::';
+ $text = 'DEFAULT';
}
$self->set_export($text);
$text;
@@ -222,13 +220,15 @@ sub gettrait {
sub set_export {
my $self = shift;
my $text = shift;
+ my $textpkg = $text . '::';
my $name = $::DECLARAND->{name};
- my $xpad = $::DECLARAND->{xpad};
+ my $xpad = delete $::DECLARAND->{xpad};
$::DECLARAND->{export} = $text;
- my $x = $xpad->{'EXPORT::'} //= STASH::->new( 'PARENT::' => $::CURPAD );
- $x->{$text} //= STASH::->new( 'PARENT::' => $x );
- $x->{$text}->{$name} = $::DECLARAND;
- $x->{$text}->{'&'.$name} = $::DECLARAND
+ my $sid = $::CURPAD->idref;
+ my $x = $xpad->{'EXPORT::'} //= STASH::->new( 'PARENT::' => $sid, '!id' => [$sid->[0] . '::EXPORT'] );
+ $x->{$textpkg} //= STASH::->new( 'PARENT::' => $x->idref, '!id' => [$sid->[0] . '::EXPORT::' . $text] );
+ $x->{$textpkg}->{$name} = $::DECLARAND;
+ $x->{$textpkg}->{'&'.$name} = $::DECLARAND
if $name =~ /^\w/ and $::SCOPE ne 'constant';
$self;
}
@@ -244,14 +244,21 @@ sub you_were_here {
my $file = $::FILE->{name};
$file =~ s/(\.setting)?$/.syml/;
$file =~ s!.*/!!;
- $::UNIT //= $::YOU_WERE_HERE;
- my $id = $::UNIT->{'OUTER::'}->id;
- $::UNIT->{_SETTINGNAME} = $id // '???';
- $::UNIT->{_GLOBALish} = $::GLOBAL;
- delete $::UNIT->{'OUTER::'};
- delete $::UNIT->{_GLOBALish}->{'PARENT::'}; # don't want to slurp in CORE
+
+ # setting?
+ if ($::YOU_WERE_HERE) {
+ $STD::ALL->{SETTING} = $::YOU_WERE_HERE;
+ }
+ else {
+ $::UNIT->{'$?SETTINGID'} = $STD::ALL->{SETTING}->id;
+ $::UNIT->{'$?COREID'} = $STD::ALL->{CORE}->id;
+ $STD::ALL = {
+ UNIT => $::UNIT,
+ };
+ }
+
open(SETTING, ">$file") or die "Can't open new setting file $file: $!";
- print SETTING Dump($::YOU_WERE_HERE);
+ print SETTING Dump($STD::ALL);
close SETTING;
$self;
}
@@ -370,6 +377,7 @@ sub _AUTOLEXpeek { my $self = shift;
return $::LEXERS{ref $self}->{$key} //= $self->_AUTOLEXgen($key, $retree);
}
+
sub _AUTOLEXgen { my $self = shift;
my $key = shift;
my $retree = shift;
@@ -1137,11 +1145,10 @@ sub do_import { my $self = shift;
my $pkg = $self->find_stash($module);
if ($pkg->{really}) {
- $pkg = $pkg->{really};
+ $pkg = $pkg->{really}->{UNIT};
}
else {
- use YAML::XS;
-# warn Dump($pkg);
+ $pkg = $self->find_stash($module . '::');
}
if ($args) {
my $text = $args->Str;
@@ -1221,6 +1228,7 @@ sub do_import_aliases {
}
}
else {
+ next if /^!/;
$self->add_variable($_);
}
}
View
@@ -1,9 +1,10 @@
use 5.010;
use strict;
use STASH;
+my $id = "MY:file<NULL.pad>:line(1):pos(0)";
my $core = STASH::->new(
- _id => ["MY:file<NULL.pad>:line(1):pos(0)"],
- _file => 'NULL.pad', _line => __LINE__ ,
+ '!id' => [$id],
+ '!file' => 'NULL.pad', '!line' => __LINE__ ,
);
sub fixup {
@@ -19,12 +20,19 @@ sub fixup {
}
}
for my $k (keys %$stash) {
- next if $k =~ /^\_/;
+ next if $k =~ /^\!/;
my $v = $stash->{$k};
if ($v->{export}) {
$stash->{'EXPORT::'}->{ '$v->{export}' . '::' }->{$k} = $v;
}
}
}
fixup($core);
-$core;
+my $ALL = {
+ 'CORE' => $core,
+ 'MY:file<NULL.pad>' => $core,
+ 'SETTING' => $core,
+ $id => $core,
+
+};
+$ALL;
View
@@ -5,8 +5,8 @@ sub new {
my %attrs = @_;
bless \%attrs, $class;
}
-sub idref { return $_[0]->{'_id'} };
-sub id { return $_[0]->{'_id'}->[0] };
-sub file { return $_[0]->{'_file'} };
-sub line { return $_[0]->{'_line'} };
+sub idref { return $_[0]->{'!id'} };
+sub id { return $_[0]->{'!id'}->[0] // '???' };
+sub file { return $_[0]->{'!file'} };
+sub line { return $_[0]->{'!line'} };
1;
Oops, something went wrong. Retry.

0 comments on commit 844fa0b

Please sign in to comment.