tagged release 0.7.1
[parrot.git] / languages / tcl / runtime / builtin / lrepeat.pir
blob2d990f5b51aad374519db1c7adf44004d44466ef
1 .HLL 'Tcl', ''
2 .namespace []
4 .sub '&lrepeat'
5   .param pmc argv :slurpy
7   .local int argc
8   argc = elements argv
9   if argc < 2 goto bad_args
11   .local pmc toInteger
12   toInteger = get_root_global ['_tcl'], 'toInteger'
14   .local int count
15   $P0   = argv[0]
16   count = toInteger($P0)
18   if count < 1 goto must_have_count
20   # convert the Array ireturned by foldup into a TclList.
21   .local pmc retval
22   retval = new 'TclList'
24   .local int i_cnt
25   .local int o_cnt
27   o_cnt = 1
28 OUTER_LOOP:
29   if o_cnt > count goto OUTER_DONE
30   i_cnt = 1
31 INNER_LOOP:
32   if i_cnt >= argc goto INNER_DONE
33   $P0 = argv[i_cnt]
34   push retval, $P0
35   inc i_cnt
36   goto INNER_LOOP
37 INNER_DONE:
38   inc o_cnt
39   goto OUTER_LOOP
40 OUTER_DONE:
42   .return(retval)
44 must_have_count:
45   die 'must have a count of at least 1'
47 bad_args:
48   die 'wrong # args: should be "lrepeat positiveCount value ?value ...?"'
49 .end
51 # Local Variables:
52 #   mode: pir
53 #   fill-column: 100
54 # End:
55 # vim: expandtab shiftwidth=4 ft=pir: