5 .param pmc argv :slurpy
7 .local int return_type, argc
13 if argc == 0 goto wrong_args
15 compare = get_root_global ['_tcl';'helpers';'lsort'], 'ascii'
16 sort = get_root_global ['_tcl';'helpers';'lsort'], 'sort'
19 .local int decr, unique
24 unless argv goto got_list
26 if $P0 == '-decreasing' goto c_decr
27 if $P0 == '-increasing' goto c_incr
28 if $P0 == '-unique' goto c_uniq
29 if $P0 == '-integer' goto c_int
30 if $P0 == '-real' goto c_real
31 if $P0 == '-dictionary' goto c_dict
32 if $P0 == '-command' goto c_command
36 compare = get_root_global ['_tcl';'helpers';'lsort'], 'dictionary'
39 compare = get_root_global ['_tcl';'helpers';'lsort'], 'real'
51 compare = get_root_global ['_tcl';'helpers';'lsort'], 'integer'
54 .local string compareName
55 compareName = shift argv
56 $S0 = '&' . compareName
57 compare = find_global $S0
63 toList = get_root_global ['_tcl'], 'toList'
68 unless unique goto skip_unique
73 if size == 0 goto strip_end
77 if c == size goto strip_end
81 if $P1 != $P2 goto strip_loop
89 unless decr goto ordered
101 $S0 .= '": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, or -unique'
104 die 'wrong # args: should be "lsort ?options? list"'
108 .namespace [ 'helpers'; 'lsort' ]
121 # check that they're actually integers.
122 # We recalculate this every time, but without smarter PMCs, we can't
123 # afford to change the string value of the given PMC.
125 toInteger = get_root_global ['_tcl'], 'toInteger'
141 .include 'cclass.pasm'
143 .local int len1, len2, pos1, pos2
149 if pos1 >= len1 goto end1
150 if pos2 >= len2 goto greater
152 $I0 = is_cclass .CCLASS_NUMERIC, s1, pos1
154 $I0 = is_cclass .CCLASS_NUMERIC, s2, pos2
157 .local string char1, char2, sortchar1, sortchar2
158 char1 = substr s1, pos1, 1
159 char2 = substr s2, pos2, 1
160 sortchar1 = downcase char1
161 sortchar2 = downcase char2
162 if sortchar1 != sortchar2 goto got_chars
175 $I3 = find_not_cclass .CCLASS_NUMERIC, s1, pos1, len1
176 if $I3 == pos1 goto greater
178 $I4 = find_not_cclass .CCLASS_NUMERIC, s2, pos2, len2
179 if $I4 == pos2 goto less
183 $S1 = substr s1, pos1, $I5
184 $S2 = substr s2, pos2, $I6
191 if $I1 < $I2 goto less
192 if $I1 > $I2 goto greater
196 if len1 == len2 goto equal
212 # check that they're actually numbers
214 toNumber = get_root_global ['_tcl'], 'toNumber'
228 # vim: expandtab shiftwidth=4 ft=pir: