Permalink
Browse files

start to implement typeglobs

  • Loading branch information...
1 parent f35d9b7 commit 741b988cf376011253b436037c5f41533fec4e92 @FROGGS FROGGS committed Feb 16, 2014
Showing with 47 additions and 0 deletions.
  1. +32 −0 lib/Perl5/Terms.pm
  2. +15 −0 lib/Perl5/World.nqp
View
32 lib/Perl5/Terms.pm
@@ -74,6 +74,37 @@ multi P5open( \SELF, $m, $expr, *@list ) is export {
unless SELF ~~ any(STDOUT|STDERR)
}
+class Typeglob {
+ has $!descriptor;
+ has $!value;
+ has $.name;
+
+ method Str {
+ '*' ~ ($!value =:= GLOBAL ?? 'main' !! $!value.^name) ~
+ '::' ~ $.name
+ }
+
+ method name {
+ $!name // ($!name = nqp::substr($!descriptor.name, 1))
+ }
+
+ method STORE($other) {
+ $!name = $other.name;
+ }
+
+ method item is rw {
+ $!value.WHO{ '$' ~ $.name }
+ }
+
+ method hash is rw {
+ $!value.WHO{ '%' ~ $.name }
+ }
+
+ method list is rw {
+ $!value.WHO{ '@' ~ $.name }
+ }
+}
+
sub P5close(\SELF) is export { SELF && SELF.close }
@@ -83,6 +114,7 @@ role P5MatchPos {
sub EXPORT(|) {
my %ex;
+ %ex<Typeglob> := Typeglob;
%ex<STDIN> := STDIN;
%ex<STDOUT> := STDOUT;
%ex<STDERR> := STDERR;
View
15 lib/Perl5/World.nqp
@@ -84,6 +84,21 @@ class Perl5::World {
%info<default_value> := $*W.find_symbol(['Any']);
%info<scalar_value> := $*W.find_symbol(['Any']);
}
+ elsif $sigil eq '*' {
+ %info<container_base> := $*W.find_symbol(['Typeglob']);
+ %info<container_type> := %info<container_base>;
+ if @value_type {
+ %info<bind_constraint> := @value_type[0];
+ %info<value_type> := @value_type[0];
+ %info<default_value> := $*PACKAGE; #@value_type[0];
+ }
+ else {
+ %info<bind_constraint> := $*W.find_symbol(['Mu']);
+ %info<value_type> := $*W.find_symbol(['Any']);
+ %info<default_value> := $*PACKAGE; #@value_type[0];
+ }
+ %info<scalar_value> := %info<default_value>;
+ }
else {
%info<container_base> := $*W.find_symbol(['Scalar']);
%info<container_type> := %info<container_base>;

0 comments on commit 741b988

Please sign in to comment.