tagged release 0.7.1
[parrot.git] / languages / tcl / runtime / string_to_list.pir
blob1c0e3ba53e70a8b2c96303a35fb7d59af38fe66a
1 .HLL '_Tcl', ''
2 .namespace []
4 .sub listToDict
5   .param pmc list
7   .local int sizeof_list
8   sizeof_list = elements list
10   $I0 = mod sizeof_list, 2
11   if $I0 == 1 goto odd_args
13   .local pmc result
14   result = new 'TclDict'
16   .local int pos
17   pos = 0
19 loop:
20   if pos >= sizeof_list goto done
21   $S1 = list[pos]
22   inc pos
23   $P2 = list[pos]
24   inc pos
25   $I0 = isa $P2, 'String'
26   if $I0 goto is_string
27 is_list:
28   $P2 = listToDict($P2)
29   result[$S1] = $P2
30   goto loop
32 is_string:
33   # Can we listify the value here? If so, make it into a dictionary.
34   $P3 = toList($P2)
35   $I0 = elements $P3
36   if $I0 <= 1 goto only_string
37   push_eh only_string
38     $P3 = listToDict($P3)
39   pop_eh
40   result[$S1] = $P3
41   goto loop
43 only_string:
44   result[$S1] = $P2
45   goto loop
47 done:
48   .return (result)
50 odd_args:
51   die 'missing value to go with key'
52 .end
54 .sub stringToDict
55   .param string str
57   .local pmc list
58   $P0 = new 'TclString'
59   list = $P0.'get_list'(str)
60   .return listToDict(list)
61 .end
63 # Local Variables:
64 #   mode: pir
65 #   fill-column: 100
66 # End:
67 # vim: expandtab shiftwidth=4 ft=pir: