<commit_before>.namespace [ "_Tcl" ]

=head2 _Tcl::__read

Read a variable from it's name. It may be a scalar or an
array.

Use the call level to determine if we are referring to a 
global variable or a lexical variable - will no doubt
require further refinement later as we support namespaces
other than the default, and multiple interpreters.

=cut

.sub __read
  .param string name
  
  .local pmc variable
  .local int return_type
  return_type = TCL_OK

  # is this an array?
  # ends with )
  .local int char
  char = ord name, -1
  if char != 41 goto scalar
  # contains a (
  char = index name, "("
  if char == -1 goto scalar

array:
  .local string var
  var = substr name, 0, char
  
  .local string key
  .local int len
  len = length name
  len -= char
  len -= 2
  inc char
  key = substr name, char, len
  
  variable = __find_var(var)
  isnull variable, no_such_variable
  
  $I0 = does variable, "hash"
  unless $I0 goto cant_read_not_array
  
  variable = variable[key]
  goto done

cant_read_not_array:
  return_type = TCL_ERROR
  $S0 =  "can't read \""
  $S0 .= name
  $S0 .= "\": variable isn't array"
  variable = new String
  variable = $S0
  goto done

scalar:
  variable = __find_var(name)
  isnull variable, no_such_variable
  
  $I0 = does variable, "hash"
  if $I0 goto cant_read_array
  goto done

cant_read_array:
  return_type = TCL_ERROR
  $S0 = "can't read \""
  $S0 .= name
  $S0 .= "\": variable is an array"
  variable = new String
  variable = $S0
  goto done

no_such_variable:
  return_type = TCL_ERROR
  $S0 = "can't read \""
  $S0 .= name
  $S0 .= "\": no such variable"
  variable = new String
  variable = $S0
  # goto done

done:
  .return(return_type, variable)
.end

=head2 _Tcl::__set

Set a variable by it's name. It may be a scalar or an array.

Use the call level to determine if we are referring to a 
global variable or a lexical variable - will no doubt
require further refinement later as we support namespaces
other than the default, and multiple interpreters.

=cut

.sub __set
  .param string name
  .param pmc value

  .local pmc variable
  .local int return_type
  return_type = TCL_OK

  # is this an array?
  # ends with )
  .local int char
  char = ord name, -1
  if char != 41 goto scalar
  # contains a (
  char = index name, "("
  if char == -1 goto scalar

array:
  .local string var<commit_msg>grammatico<commit_after>.namespace [ "_Tcl" ]

=head2 _Tcl::__read

Read a variable from its name. It may be a scalar or an
array.

Use the call level to determine if we are referring to a 
global variable or a lexical variable - will no doubt
require further refinement later as we support namespaces
other than the default, and multiple interpreters.

=cut

.sub __read
  .param string name
  
  .local pmc variable
  .local int return_type
  return_type = TCL_OK

  # is this an array?
  # ends with )
  .local int char
  char = ord name, -1
  if char != 41 goto scalar
  # contains a (
  char = index name, "("
  if char == -1 goto scalar

array:
  .local string var
  var = substr name, 0, char
  
  .local string key
  .local int len
  len = length name
  len -= char
  len -= 2
  inc char
  key = substr name, char, len
  
  variable = __find_var(var)
  isnull variable, no_such_variable
  
  $I0 = does variable, "hash"
  unless $I0 goto cant_read_not_array
  
  variable = variable[key]
  goto done

cant_read_not_array:
  return_type = TCL_ERROR
  $S0 =  "can't read \""
  $S0 .= name
  $S0 .= "\": variable isn't array"
  variable = new String
  variable = $S0
  goto done

scalar:
  variable = __find_var(name)
  isnull variable, no_such_variable
  
  $I0 = does variable, "hash"
  if $I0 goto cant_read_array
  goto done

cant_read_array:
  return_type = TCL_ERROR
  $S0 = "can't read \""
  $S0 .= name
  $S0 .= "\": variable is an array"
  variable = new String
  variable = $S0
  goto done

no_such_variable:
  return_type = TCL_ERROR
  $S0 = "can't read \""
  $S0 .= name
  $S0 .= "\": no such variable"
  variable = new String
  variable = $S0
  # goto done

done:
  .return(return_type, variable)
.end

=head2 _Tcl::__set

Set a variable by its name. It may be a scalar or an array.

Use the call level to determine if we are referring to a 
global variable or a lexical variable - will no doubt
require further refinement later as we support namespaces
other than the default, and multiple interpreters.

=cut

.sub __set
  .param string name
  .param pmc value

  .local pmc variable
  .local int return_type
  return_type = TCL_OK

  # is this an array?
  # ends with )
  .local int char
  char = ord name, -1
  if char != 41 goto scalar
  # contains a (
  char = index name, "("
  if char == -1 goto scalar

array:
  .local string var
{'fraction_non_alphanumeric': 0.08310366758532965, 'fraction_numerical': 0.011871952512189952, 'mean_word_length': 2.9153526970954355, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '3079898', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1610, 'n_words': 641}