<commit_before>#
# [lset]
#

.HLL 'Tcl', 'tcl_group'
.namespace

.sub '&lset'
  .param pmc argv :slurpy

  .local int return_type, argc
  .local pmc retval

  argc = argv
  if argc < 2 goto wrong_args

  .local string name
  $P0  = argv[0]
  name = $P0

  .local pmc read, set
  read = get_root_global ['_tcl'], '__read'
  set  = get_root_global ['_tcl'], '__set'

  retval = read(name)

  .local int count
  count = argv
  if count == 2 goto replace
  $P0 = argv[1]
  $S0 = $P0
  if $S0 == '' goto replace

lset:
  .local pmc __list
  __list = get_root_global ['_tcl'], '__list'
  retval = __list(retval)

  .local int i, end
  i   = 1
  end = count - 2
  .local pmc list
  list = retval

loop:
  if i >= end goto loop_done

  $I0 = argv[i]
  $P0 = list[$I0]
  $P0 = __list($P0)
  list[$I0] = $P0
  list      = $P0

  inc i
  goto loop

loop_done:
  $I0 = argv[i]
  $P0 = argv[-1]
  list[$I0] = $P0
  .return set(name, retval)

wrong_args:
  .throw ('wrong # args: should be "lset listVar index ?index...? value"')

replace:
  $P0 = argv[-1]
  .return set(name, $P0)

.end<commit_msg> r528@mini:  mdiep | 2006-08-04 01:18:51 -0400  [tcl]: Fix one of the [lset] tests<commit_after>#
# [lset]
#

.HLL 'Tcl', 'tcl_group'
.namespace

.sub '&lset'
  .param pmc argv :slurpy

  .local int argc
  argc = elements argv
  if argc < 2 goto wrong_args

  .local string name, value
  name  = argv[0]
  value = pop argv
  dec argc

  .local pmc __read, __set
  __read = get_root_global ['_tcl'], '__read'
  __set  = get_root_global ['_tcl'], '__set'

  .local pmc retval, list
  list   = __read(name)
  retval = list

  # we removed the value, so this would be one now
  if argc == 1 goto replace

lset:
  .local pmc __list, _list_index
  __list      = get_root_global ['_tcl'], '__list'
  _list_index = get_root_global ['_tcl'], '_list_index'

  unless argc == 2 goto iterate
  $P0 = argv[1]
  $P0 = __list($P0)
  $I0 = elements $P0
  if $I0 == 0 goto replace

iterate:
  list = __list(list)
  __set(name, list)
  
  .local pmc indices, prev
  .local int outer_i
  outer_i = 0
outer_loop:
  inc outer_i
  if outer_i == argc goto done
  indices = argv[outer_i]
  indices = __list(indices)

  $I0 = 0
  $I1 = elements indices
loop:
  if $I0 == $I1 goto outer_loop

  $P0 = indices[$I0]
  $I2 = _list_index(list, $P0)
  $S0 = $I2

  prev = list
  list = list[$I2]
  list = __list(list)
  prev[$I2] = list

  inc $I0
  goto loop

done:
  prev[$I2] = value
  .return(retval)

wrong_args:
  .throw ('wrong # args: should be "lset listVar index ?index...? value"')

replace:
  .return __set(name, value)
.end
{'fraction_non_alphanumeric': 0.13590733590733592, 'fraction_numerical': 0.02972972972972973, 'mean_word_length': 2.855654761904762, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938220', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1087, 'n_words': 323}