6 Read a variable from its name. It may be a scalar or an
9 Use the call level to determine if we are referring to a
10 global variable or a lexical variable - will no doubt
11 require further refinement later as we support namespaces
12 other than the default, and multiple interpreters.
25 if char != 41 goto scalar
27 char = index name, '('
28 if char == -1 goto scalar
32 var = substr name, 0, char
40 key = substr name, char, len
42 variable = findVar(var)
43 if null variable goto no_such_variable
45 $I0 = does variable, 'associative_array'
46 unless $I0 goto cant_read_not_array
48 variable = variable[key]
49 if null variable goto bad_index
50 $I0 = isa variable, 'Undef'
57 $S0 .= '": no such element in array'
63 $S0 .= "\": variable isn't array"
67 variable = findVar(name)
68 if null variable goto no_such_variable
70 $I0 = does variable, 'associative_array'
71 if $I0 goto cant_read_array
77 $S0 .= '": variable is array'
83 $S0 .= '": no such variable'
89 Read a variable from its name. If it doesn't exist, create it. It may be a
92 Use the call level to determine if we are referring to a
93 global variable or a lexical variable - will no doubt
94 require further refinement later as we support namespaces
95 other than the default, and multiple interpreters.
101 .param int depth :named('depth') :optional
109 if char != 41 goto scalar
111 char = index name, '('
112 if char == -1 goto scalar
116 var = substr name, 0, char
124 key = substr name, char, len
126 variable = findVar(var, 'depth' => depth)
127 unless null variable goto check_is_hash
129 variable = new 'TclArray'
130 variable = storeVar(var, variable, 'depth' => depth)
133 $I0 = does variable, 'associative_array'
134 unless $I0 goto cant_read_not_array
137 if null $P0 goto create_elem
146 $S0 = "can't read \""
148 $S0 .= "\": variable isn't array"
152 variable = findVar(name, 'depth' => depth)
153 if null variable goto make_variable
157 variable = new 'Undef'
158 variable = storeVar(name, variable, 'depth' => depth)
164 Set a variable by its name. It may be a scalar or an array.
166 Use the call level to determine if we are referring to a
167 global variable or a lexical variable - will no doubt
168 require further refinement later as we support namespaces
169 other than the default, and multiple interpreters.
179 # Some cases in the code allow a NULL pmc to show up here.
180 # This defensively converts them to an empty string.
181 unless_null value, got_value
182 value = new 'TclString'
190 if char != 41 goto scalar
192 char = index name, '('
193 if char == -1 goto scalar
197 var = substr name, 0, char
205 key = substr name, char, len
210 if null array goto create_array
212 $I0 = does array, 'associative_array'
213 unless $I0 goto cant_set_not_array
217 array = new 'TclArray'
218 array = storeVar(var, array)
221 variable = array[key]
222 if null variable goto set_new_elem
223 assign variable, value
235 $S0 .= "\": variable isn't array"
240 if null $P0 goto create_scalar
241 $I0 = does $P0, 'associative_array'
242 if $I0 goto cant_set_array
245 storeVar(name, value)
252 $S0 .= "\": variable is array"
258 Utility function used by readVar and setVar.
260 Gets the actual variable from memory and returns it.
266 .param int isglobal :named('global') :optional
267 .param int depth :named('depth') :optional
270 ns = new 'ResizableStringArray'
275 $I0 = index name, '::'
276 if $I0 == 0 goto absolute_global
277 if $I0 != -1 goto global_var
278 if isglobal goto global_var
280 .local pmc call_chain
281 .local int call_level
282 call_chain = get_root_global ['_tcl'], 'call_chain'
283 call_level = elements call_chain
284 if call_level == 0 goto global_var
288 .local pmc lexpad, variable
289 push_eh lexical_notfound
290 lexpad = call_chain[-1]
293 if null value goto args_check
294 $I0 = isa value, 'Undef'
295 if $I0 goto args_check
299 # args is special -- it doesn't show up in [info vars]
300 # unless you explicitly set it in your proc. but if you
301 # try to get it, it's always there.
302 unless name == '$args' goto notfound
303 value = lexpad['args']
310 ns = splitNamespace(name, depth)
315 ns = get_root_namespace ns
316 if null ns goto notfound
319 if null value goto notfound
320 $I0 = isa value, 'Undef'
326 .local pmc colons, split
327 colons = get_root_global ['_tcl'], 'colons'
328 split = get_root_global ['parrot'; 'PGE::Util'], 'split'
330 ns = split(colons, name)
335 ns = get_root_namespace ns
336 if null ns goto notfound
339 if null value goto found
340 $I0 = isa value, 'Undef'
345 unless absolute goto root_global_var
352 =head2 _Tcl::storeVar
354 Utility function used by readVar and setVar.
356 Sets the actual variable from memory.
363 .param int isglobal :named('global') :optional
364 .param int depth :named('depth') :optional
367 ns = new 'ResizableStringArray'
369 $I0 = index name, '::'
370 if $I0 != -1 goto global_var
371 if isglobal goto global_var
373 .local pmc call_chain
374 .local int call_level
375 call_chain = get_root_global ['_tcl'], 'call_chain'
376 call_level = elements call_chain
377 if call_level == 0 goto global_var
382 lexpad = call_chain[-1]
385 if null $P0 goto lexical_is_null
396 ns = splitNamespace(name, depth)
401 ns = get_root_namespace ns
402 if null ns goto global_not_undef
404 if null $P0 goto global_not_undef
418 # vim: expandtab shiftwidth=4 ft=pir: