Skip to content

Commit

Permalink
implement anon enums
Browse files Browse the repository at this point in the history
Not sure if we want to keep this factoring, it just reuses the
old infrastructure for now. Passes the anon enum tests.
  • Loading branch information
moritz committed Mar 10, 2012
1 parent 54e0769 commit 08417f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/core/Enumeration.pm
Expand Up @@ -46,3 +46,20 @@ my role NumericEnumeration {
self.key
}
}

sub ANON_ENUM(*@args) {
my Mu $prev = -1;
my %res;
for @args {
if .^isa(Enum) {
%res{.key} = .value;
}
else {
%res{$_} = $prev.=succ;
}
}
my $r := nqp::create(EnumMap);
nqp::bindattr($r, EnumMap, '$!storage',
nqp::getattr(%res, EnumMap, '$!storage'));
$r;
}
1 change: 1 addition & 0 deletions src/core/stubs.pm
Expand Up @@ -12,6 +12,7 @@ my class Seq is List does Positional { }
my class Exception { ... }
my class X::AdHoc { ... }
my class FatRat { ... }
my class Enum { ... }

sub DYNAMIC(\$name) is rw {
my Mu $x := pir::find_dynamic_lex__Ps(nqp::unbox_s($name));
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -424,7 +424,7 @@ S12-construction/BUILD.t
S12-construction/construction.t
S12-construction/named-params-in-BUILD.t
S12-construction/new.t
# S12-enums/anonymous.t # err: Undefined routine '&ANON_ENUM' called
S12-enums/anonymous.t
# S12-enums/as-role.t # err: Cannot yet turn an enum into a role
S12-enums/basic.t
S12-enums/misc.t
Expand Down

0 comments on commit 08417f8

Please sign in to comment.