Permalink
Browse files

implement anon enums

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...
1 parent 54e0769 commit 08417f89062b519ddf3fb945da5547d6dfa5b537 @moritz moritz committed Mar 10, 2012
Showing with 19 additions and 1 deletion.
  1. +17 −0 src/core/Enumeration.pm
  2. +1 −0 src/core/stubs.pm
  3. +1 −1 t/spectest.data
View
@@ -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;
+}
View
@@ -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));
View
@@ -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

0 comments on commit 08417f8

Please sign in to comment.