Created
August 5, 2010 17:21
-
-
Save Timbus/510046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method !STORE(\$to_store) { | |
Q:PIR { | |
.local pmc self, to_store, items, storage | |
self = find_lex 'self' | |
to_store = find_lex '$to_store' | |
# We create a new storage hash, in case we are referenced in | |
# what is being stored. | |
storage = root_new ['parrot';'Hash'] | |
setattribute self, '$!storage', storage | |
# Sequencify args | |
$P0 = get_hll_global 'Seq' | |
items = $P0.'new'(to_store) | |
#Get enum and enummap objects to call ACCEPTS on | |
.local pmc Enum, EnumMap | |
get_hll_global Enum, "Enum" | |
get_hll_global EnumMap, "EnumMap" | |
.local pmc item | |
fill_loop: | |
unless items goto done | |
item = items.'shift'() | |
$P1 = Enum.'ACCEPTS'(item) | |
unless $P1 goto check_emap | |
$P1 = getattribute item, '$!key' | |
$P2 = getattribute item, '$!value' | |
storage[$P1] = $P2 | |
goto fill_loop | |
check_emap: | |
$P1 = EnumMap.'ACCEPTS'(item) | |
unless $P1 goto default | |
item = item.'list'() | |
copy_map_loop: | |
unless item goto fill_loop | |
$P1 = item.'shift'() | |
$P2 = getattribute $P1, '$!key' | |
$P3 = getattribute $P1, '$!value' | |
storage[$P2] = $P3 | |
goto copy_map_loop | |
default: | |
unless items goto die_odd | |
$P0 = items.'shift'() | |
$P0 = new ['Perl6Scalar'], $P0 | |
setprop $P0, "rw", true | |
storage[item] = $P0 | |
goto fill_loop | |
die_odd: | |
$P1 = new "Str" | |
$P1 = 'Odd number of elements found where hash expected' | |
'&die'($P1) | |
done: | |
%r = self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment