4 .HLL 'Tcl', 'tcl_group'
8 .param pmc argv :slurpy
13 unless $I3 goto no_args
15 .local string subcommand_name
16 subcommand_name = shift argv
19 options = new 'ResizablePMCArray'
29 options[9] = 'lappend'
31 options[11] = 'remove'
32 options[12] = 'replace'
36 options[16] = 'update'
37 options[17] = 'values'
40 .local pmc select_option
41 select_option = get_root_global ['_tcl'], 'select_option'
42 .local string canonical_subcommand
43 canonical_subcommand = select_option(options, subcommand_name, 'subcommand')
45 .local pmc subcommand_proc
48 subcommand_proc = get_root_global ['_tcl'; 'helpers'; 'dict'], canonical_subcommand
49 if_null subcommand_proc, bad_args
50 .return subcommand_proc(argv)
53 .return ('') # once all commands are implemented, remove this...
56 tcl_error 'wrong # args: should be "dict subcommand ?arg ...?"'
62 .namespace [ 'helpers'; 'dict' ]
69 if argc < 2 goto bad_args
72 read = get_root_global ['_tcl'], '__read'
73 set = get_root_global ['_tcl'], '__set'
75 .local pmc dictionary, dict_name
76 dict_name = shift argv
78 dictionary = read(dict_name)
80 dictionary = __dict(dictionary)
84 get_results '0,0', $P0, $S0
85 $I0 = index $S0, 'variable is array'
86 if $I0 != -1 goto cant_dict_array
87 dictionary = new 'TclDict'
93 # argv now contains all the new elements to append.
95 $I0 = exists dictionary[key]
97 value = new 'TclString'
102 value = dictionary[key]
106 unless argc goto loop_done
111 stringy = new 'String'
117 dictionary[key] = value
118 set(dict_name, dictionary)
123 $S1 = "can't set \"" . $S1
124 $S1 .= '": variable is array'
128 tcl_error 'wrong # args: should be "dict append varName key ?value ...?"'
140 retval = new 'TclDict'
146 unless $I1 goto loop_done
156 tcl_error 'wrong # args: should be "dict create ?key value ...?"'
165 if argc < 2 goto bad_args
167 .local pmc dictionary
168 dictionary = shift argv
169 dictionary = __dict(dictionary)
174 unless argc goto loop_done
176 dictionary = dictionary[key]
177 if_null dictionary, not_exist
187 tcl_error 'wrong # args: should be "dict exists dictionary key ?key ...?"'
196 if argc < 2 goto bad_args
198 .local pmc dictionary
199 dictionary = shift argv
200 dictionary = __dict(dictionary)
203 options = new 'TclList'
205 options[1] = 'script'
208 .local pmc select_option, __script, __boolean
209 select_option = get_root_global ['_tcl'], 'select_option'
210 __script = get_root_global ['_tcl'], '__script'
211 __boolean = get_root_global ['_tcl'], '__boolean'
214 option = select_option(options, option, 'filterType')
216 .local pmc results, key, value
217 results = new 'TclDict'
219 if option == 'script' goto do_script_prelude
221 .local pmc globber, pattern
222 globber = compreg 'Tcl::Glob'
223 if argc != 3 goto missing_glob
226 .local pmc rule, match, iterator
227 rule = globber.'compile'(pattern)
228 iterator = new 'Iterator', dictionary
230 if option == 'key' goto do_key_loop
233 unless iterator goto do_value_done
235 value = dictionary[key]
237 unless match goto do_value_loop
244 unless iterator goto do_key_done
247 unless match goto do_key_loop
248 value = dictionary[key]
256 if argc != 2 goto bad_script_args
258 .local pmc vars, body
262 if $I0 != 2 goto bad_list_size
265 .local string keyVar,valueVar
270 iterator = new 'Iterator', dictionary
272 retval = new 'TclDict'
274 body_proc = __script(body)
276 .local pmc check_key,check_value
278 unless iterator goto end_script_loop
279 check_key = shift iterator
280 __set(keyVar,check_key)
281 check_value = dictionary[check_key]
282 __set(valueVar,check_value)
287 unless $P1 goto script_loop
288 retval[check_key] = check_value
295 .get_return_code($I0)
296 if $I0 == .CONTROL_CONTINUE goto script_loop
297 if $I0 == .CONTROL_BREAK goto end_script_loop
301 tcl_error 'wrong # args: should be "dict filter dictionary script {keyVar valueVar} filterScript"'
304 tcl_error 'must have exactly two variable names'
308 $S1 = 'wrong # args: should be "dict filter dictionary ' . $S1
309 $S1 .= ' globPattern"'
313 tcl_error 'wrong # args: should be "dict filter dictionary filterType ..."'
321 if argc != 3 goto bad_args
323 .local pmc set, script
324 set = get_root_global ['_tcl'], '__set'
325 script = get_root_global ['_tcl'], '__script'
328 .local string keyVar, valueVar
330 varNames = shift argv
331 varNames = __list(varNames)
332 $I0 = elements varNames
333 if $I0 != 2 goto bad_list_size
335 valueVar = varNames[1]
337 .local pmc dictionary
338 dictionary = shift argv
339 dictionary = __dict(dictionary)
343 code = __script(body)
346 iterator = new 'Iterator', dictionary
348 unless iterator goto for_loop_done
352 $P2 = dictionary[$S1]
363 .get_return_code($I0)
364 if $I0 == .CONTROL_CONTINUE goto for_loop
365 if $I0 == .CONTROL_BREAK goto for_loop_done
373 tcl_error 'must have exactly two variable names'
376 tcl_error 'wrong # args: should be "dict for {keyVar valueVar} dictionary script"'
385 if argc < 1 goto bad_args
387 .local pmc dictionary
388 dictionary = shift argv
389 dictionary = __dict(dictionary)
390 if argc < 0 goto loop_done
395 if argc <= 1 goto loop_done
397 dictionary = dictionary[key]
398 if_null dictionary, not_exist
399 dictionary = __dict(dictionary) # might be a string, error out if so
403 if argc == 0 goto done
405 dictionary = dictionary[key]
406 if_null dictionary, not_exist
413 $S1 .= '" not known in dictionary'
417 tcl_error 'wrong # args: should be "dict get dictionary ?key key ...?"'
425 if argc < 2 goto bad_args
426 if argc > 3 goto bad_args
429 read = get_root_global ['_tcl'], '__read'
430 set = get_root_global ['_tcl'], '__set'
432 .local pmc dictionary, dict_name
433 dict_name = shift argv
435 dictionary = read(dict_name)
437 dictionary = __dict(dictionary)
441 get_results '0,0', $P0, $S0
442 $I0 = index $S0, 'variable is array'
443 if $I0 != -1 goto cant_dict_array
444 dictionary = new 'TclDict'
451 increment = new 'TclInt'
454 if argc == 2 goto got_increment
455 increment = shift argv
456 increment = __integer (increment)
461 $I0 = exists dictionary[key]
467 value = dictionary[key]
468 value = __integer(value)
472 dictionary[key] = value
473 set(dict_name, dictionary)
481 $S1 = "can't set \"" . $S1
482 $S1 .= '": variable is array'
486 tcl_error 'wrong # args: should be "dict incr varName key ?increment?"'
490 # This is a stub, doesn't actually generate the info.
491 # it's exposing the guts of the interface, not sure how if it's appropriate
492 # to do this in partcl.
498 if argc != 1 goto bad_args
500 .local pmc dictionary
501 dictionary = shift argv
502 dictionary = __dict(dictionary)
507 tcl_error 'wrong # args: should be "dict info dictionary"'
516 if argc < 2 goto bad_args
519 read = get_root_global ['_tcl'], '__read'
520 set = get_root_global ['_tcl'], '__set'
522 .local pmc dictionary, dict_name
523 dict_name = shift argv
525 dictionary = read(dict_name)
527 dictionary = __dict(dictionary)
531 get_results '0,0', $P0, $S0
532 $I0 = index $S0, 'variable is array'
533 if $I0 != -1 goto cant_dict_array
534 dictionary = new 'TclDict'
537 .local pmc key, value
540 # argv now contains all the new list elements to lappend.
542 $I0 = exists dictionary[key]
544 value = new 'TclList'
548 value = dictionary[key]
549 value = __list(value)
553 unless argc goto loop_done
559 dictionary[key] = value
560 set(dict_name, dictionary)
565 $S1 = "can't set \"" . $S1
566 $S1 .= '": variable is array'
570 tcl_error 'wrong # args: should be "dict lappend varName key ?value ...?"'
578 if argc < 1 goto bad_args
579 if argc > 2 goto bad_args
581 .local pmc dictionary
582 dictionary = shift argv
583 dictionary = __dict(dictionary)
585 .local string pattern
587 if argc == 1 goto got_pattern
592 globber = compreg 'Tcl::Glob'
594 .local pmc rule, match
595 rule = globber.'compile'(pattern)
598 iterator = new 'Iterator', dictionary
600 .local pmc results, key
601 results = new 'TclList'
603 unless iterator goto loop_done
606 unless match goto loop
614 tcl_error 'wrong # args: should be "dict keys dictionary ?pattern?"'
623 if argc == 0 goto nothing
628 retval = __dict(retval)
629 if argc == 1 goto done
630 $P2 = shift argv # discard
632 .local pmc dictionary,key,value,iterator
637 dictionary = shift argv
638 dictionary = __dict(dictionary)
639 iterator = new 'Iterator', dictionary
641 unless iterator goto dict_loop
643 value = dictionary[key]
659 if argc < 1 goto bad_args
661 .local pmc dictionary
662 dictionary = shift argv
663 dictionary = __dict(dictionary)
664 dictionary = clone dictionary
666 .local pmc key, value
669 unless argc goto loop_done
671 delete dictionary[key]
678 tcl_error 'wrong # args: should be "dict remove dictionary ?key ...?"'
687 if argc < 1 goto bad_args
688 if argc == 2 goto bad_args
690 .local pmc dictionary
691 dictionary = shift argv
692 dictionary = __dict(dictionary)
693 dictionary = clone dictionary
695 if argc < 0 goto loop_done
697 if $I0 == 0 goto odd_args # we shifted the dict off, above...
699 .local pmc key, value
702 unless argc goto loop_done
705 dictionary[key] = value
712 tcl_error 'missing value to go with key'
715 tcl_error 'wrong # args: should be "dict replace dictionary ?key value ...?"'
723 if argc < 3 goto bad_args
726 read = get_root_global ['_tcl'], '__read'
727 set = get_root_global ['_tcl'], '__set'
729 .local pmc dictionary, dict_name
730 dict_name = shift argv
732 dictionary = read(dict_name)
734 dictionary = __dict(dictionary)
738 get_results '0,0', $P0, $S0
739 $I0 = index $S0, 'variable is array'
740 if $I0 != -1 goto cant_dict_array
741 dictionary = new 'TclDict'
747 .local pmc key, sub_dict
748 sub_dict = dictionary
751 if argc <= 1 goto loop_done
754 # Does this key exist? set it.
755 if null $P1 goto new_key
764 key = shift argv # should be the last one..
765 sub_dict[key] = value
767 set(dict_name, dictionary)
772 $S1 = "can't set \"" . $S1
773 $S1 .= '": variable is array'
777 tcl_error 'wrong # args: should be "dict set varName key ?key ...? value"'
785 if argc !=1 goto bad_args
787 .local pmc dictionary
788 dictionary = shift argv
789 dictionary = __dict(dictionary)
792 size = elements dictionary
796 tcl_error 'wrong # args: should be "dict size dictionary"'
805 if argc < 2 goto bad_args
808 read = get_root_global ['_tcl'], '__read'
809 set = get_root_global ['_tcl'], '__set'
811 .local pmc dictionary, dict_name
812 dict_name = shift argv
814 dictionary = read(dict_name)
816 dictionary = __dict(dictionary)
820 get_results '0,0', $P0, $S0
821 $I0 = index $S0, 'variable is array'
822 if $I0 != -1 goto cant_dict_array
823 dictionary = new 'TclDict'
824 set(dict_name, dictionary)
828 .local pmc key, sub_dict
829 sub_dict = dictionary
832 if argc <=1 goto loop_done
834 sub_dict = sub_dict[key]
835 if null sub_dict goto not_exist
838 key = shift argv # should be the last one..
846 $S1 .= '" not known in dictionary'
851 $S1 = "can't set \"" . $S1
852 $S1 .= '": variable is array'
856 tcl_error 'wrong # args: should be "dict unset varName key ?key ...?"'
864 if argc < 4 goto bad_args
869 read = get_root_global ['_tcl'], '__read'
870 set = get_root_global ['_tcl'], '__set'
872 .local pmc dictionary, dict_name
873 dict_name = shift argv
875 dictionary = read(dict_name)
877 dictionary = __dict(dictionary)
881 get_results '0,0', $P0, $S0
882 $I0 = index $S0, 'variable is array'
883 if $I0 != -1 goto cant_dict_array
884 dictionary = new 'TclDict'
890 .local pmc keys,varnames
891 keys = new 'ResizablePMCArray'
892 varnames = new 'ResizablePMCArray'
893 # get lists of both keys & varnames, setting the variables.
896 unless $I0 goto done_key_loop
901 $P3 = dictionary[$P1]
905 # run the body of the script. save the return vaalue.
910 # go through the varnames, setting the appropriate keys to those values.
911 .local pmc iter1,iter2
912 iter1 = new 'Iterator', keys
913 iter2 = new 'Iterator', varnames
915 unless iter1 goto set_loop_done
919 dictionary[$P1] = $P3
928 $S1 = "can't set \"" . $S1
929 $S1 .= '": variable is array'
933 tcl_error 'wrong # args: should be "dict update varName key varName ?key varName ...? script"'
943 if argc < 1 goto bad_args
944 if argc > 2 goto bad_args
946 .local pmc dictionary
947 dictionary = shift argv
948 dictionary = __dict(dictionary)
950 .local string pattern
952 if argc == 1 goto got_pattern
957 globber = compreg 'Tcl::Glob'
959 .local pmc rule, match
960 rule = globber.'compile'(pattern)
963 iterator = new 'Iterator', dictionary
965 .local pmc results, key, value
966 results = new 'TclList'
968 unless iterator goto loop_done
970 value = dictionary[key]
972 unless match goto loop
980 tcl_error 'wrong # args: should be "dict values dictionary ?pattern?"'
988 if argc ==0 goto bad_args
991 read = get_root_global ['_tcl'], '__read'
992 set = get_root_global ['_tcl'], '__set'
994 .local pmc dictionary, dict_name
995 dict_name = shift argv
997 dictionary = read(dict_name)
999 dictionary = __dict(dictionary)
1003 get_results '0,0', $P0, $S0
1004 $I0 = index $S0, 'variable is array'
1005 if $I0 != -1 goto cant_dict_array
1006 dictionary = new 'TclDict'
1011 # walk to point in hierarchy for keys..
1016 unless $I0 goto done_keys
1018 dictionary=dictionary[key]
1022 iterator = new 'Iterator', dictionary
1025 unless iterator goto done_alias
1026 $P1 = shift iterator
1027 $P2 = dictionary[$P1]
1032 $P1 = __script(body)
1035 iterator = new 'Iterator', dictionary
1037 unless iterator goto done_update
1038 $P1 = shift iterator
1040 dictionary[$P1] = $P2
1048 $S1 = "can't set \"" . $S1
1049 $S1 .= '": variable is array'
1053 tcl_error 'wrong # args: should be "dict with dictVar ?key ...? script"'
1062 # vim: expandtab shiftwidth=4 ft=pir: