Skip to content

Commit

Permalink
[src/glue] translated !setup_named_enum PIR->p6
Browse files Browse the repository at this point in the history
This is an idempotent commit that paves the way for more correct
enum semantics.
  • Loading branch information
Carl Masak committed Jul 22, 2010
1 parent 00848d2 commit 0d0fd7e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 32 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -176,6 +176,7 @@ CORE_SOURCES = \
src/core/operators.pm \
src/glue/handles.pm \
src/glue/subset.pm \
src/glue/enum.pm \
src/cheats/trait-export.pm \
src/cheats/num.pm \
src/cheats/eval.pm \
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -1520,7 +1520,7 @@ method type_declarator:sym<enum>($/) {
# Emit code to set up named enum.
@PACKAGE[0].block.loadinit.push(PAST::Op.new(
:pasttype('call'),
:name('!setup_named_enum'),
:name('&SETUP_NAMED_ENUM'),
~$<name>[0],
$value_ast
));
Expand Down
31 changes: 0 additions & 31 deletions src/glue/enum.pir
Expand Up @@ -52,37 +52,6 @@ Constructs a EnumMap, based upon the values list.
.return (result)
.end

=item !setup_named_enum

=cut

.sub '!setup_named_enum'
.param pmc name
.param pmc values

# For now, just install EnumMap under the main name.
.local pmc full_ns, base_ns
.local string shortname
$P0 = get_hll_global ['Perl6';'Grammar'], 'parse_name'
full_ns = $P0(name)
base_ns = clone full_ns
shortname = pop base_ns
set_hll_global base_ns, shortname, values

# Go over the keys/values and set them up.
.local pmc it
it = iter values
it_loop:
unless it goto it_loop_end
$P0 = shift it
$S0 = $P0.'key'()
$P1 = $P0.'value'()
set_hll_global full_ns, $S0, $P1
set_hll_global base_ns, $S0, $P1
goto it_loop
it_loop_end:
.end

# Local Variables:
# mode: pir
# fill-column: 100
Expand Down
15 changes: 15 additions & 0 deletions src/glue/enum.pm
@@ -0,0 +1,15 @@
# Note: this file probably wants to be in some Perl6::CompilerGuts namespace.

our sub SETUP_NAMED_ENUM($name, $values) {
# For now, just install EnumMap under the main name.
my @full_ns = Perl6::Grammar::parse_name($name);
my ($shortname, @base_ns) = @full_ns;
pir::set_hll_global__vPSP(@base_ns, $shortname, $values);

for $values.kv -> $key, $value {
pir::set_hll_global__vPSP(@full_ns, $key, $value);
pir::set_hll_global__vPSP(@base_ns, $key, $value);
}
}


0 comments on commit 0d0fd7e

Please sign in to comment.