6 VERSION = PARROT_VERSION;
10 var.ops - Variable Ops
14 These operations deal with both lexical and global variables,
15 as well as the symbol tables that contain them.
19 ###############################################################################
21 =head2 Lexical variable ops
23 Operations to create, modify and delete lexical variables.
29 ########################################
31 =item B<store_lex>(in STR, invar PMC)
33 Store object $2 as lexical symbol $1. The opcode might succeed
34 or throw an exception on unknown lexical names depending on the
35 implementation of the LexPad PMC.
36 Parrot's LexPad throws an exception for unknown names.
41 op store_lex(in STR, invar PMC) {
42 parrot_context_t * const ctx = CONTEXT(interp);
43 STRING * const lex_name = $1;
44 PMC * const lex_pad = Parrot_find_pad(interp, lex_name, ctx);
46 if (PMC_IS_NULL(lex_pad)) {
47 real_exception(interp, NULL, LEX_NOT_FOUND,
48 "Lexical '%Ss' not found", lex_name);
50 VTABLE_set_pmc_keyed_str(interp, lex_pad, lex_name, $2);
53 ########################################
55 =item B<find_lex>(out PMC, in STR)
57 Find the lexical variable named $2 and store it in $1. This
58 opcode either throws an exception or returns a Null PMC for the failure case,
59 depending on the implementation of the LexPad PMC. Parrot's
60 standard LexPad throws and exception for non-existing names.
64 op find_lex(out PMC, in STR) {
65 parrot_context_t * const ctx = CONTEXT(interp);
66 STRING * const lex_name = $2;
67 PMC * const lex_pad = Parrot_find_pad(interp, lex_name, ctx);
72 : VTABLE_get_pmc_keyed_str(interp, lex_pad, lex_name);
74 real_exception(interp, NULL, LEX_NOT_FOUND,
75 "Lexical '%Ss' not found", lex_name);
84 ###############################################################################
86 =head2 Namespace opcodes
90 =item B<get_namespace>(out PMC)
92 Set $1 to the current namespace.
94 =item B<get_namespace>(out PMC, in PMC)
96 Set $1 to the namespace denoted by the key constant $2, relative to the
97 current namespace. If the namespace doesn't exist, $1 is set to null.
101 op get_namespace(out PMC) {
102 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
106 op get_namespace(out PMC, in PMC) {
107 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
108 PMC * const ns = Parrot_get_namespace_keyed(interp, cur_ns, $2);
110 $1 = PMC_IS_NULL(ns) ? PMCNULL : ns;
113 =item B<get_hll_namespace>(out PMC)
115 Set $1 to the current HLL root namespace.
117 =item B<get_hll_namespace>(out PMC, in PMC)
119 Set $1 to the namespace denoted by the key constant $2, relative to the
120 current HLL root namespace. If the namespace doesn't exist, $1 is set to
125 op get_hll_namespace(out PMC) {
126 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
130 op get_hll_namespace(out PMC, in PMC) {
131 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
132 if (PMC_IS_NULL(hll_ns))
135 PMC * const ns = Parrot_get_namespace_keyed(interp, hll_ns, $2);
140 =item B<get_root_namespace>(out PMC)
142 Set $1 to the true root namespace.
144 =item B<get_root_namespace>(out PMC, in PMC)
146 Set $1 to the namespace denoted by the key constant $2, relative to the true
147 root namespace. If the namespace doesn't exist, $1 is set to null.
151 op get_root_namespace(out PMC) {
152 PMC * const root_ns = interp->root_namespace;
156 op get_root_namespace(out PMC, in PMC) {
157 PMC * const root_ns = interp->root_namespace;
158 if (PMC_IS_NULL(root_ns))
161 PMC * const ns = Parrot_get_namespace_keyed(interp, root_ns, $2);
170 ###############################################################################
172 =head2 Global variable 'get' opcodes
176 =item B<get_global>(out PMC, in STR)
178 Set $1 to the global named $2 in current namespace. If the global doesn't
179 exist, $1 is set to null.
181 =item B<get_global>(out PMC, in PMC, in STR)
183 Set $1 to the global named $3 in the namespace denoted by the key constant
184 $2, relative to the current namespace. If the namespace or the global
185 doesn't exist, $1 is set to null.
189 op get_global(out PMC, in STR) {
190 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
191 $1 = Parrot_find_global_op(interp, cur_ns, $2, expr NEXT());
194 op get_global(out PMC, in PMC, in STR) {
195 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
196 if (PMC_IS_NULL(cur_ns)) {
200 PMC * const ns = Parrot_get_namespace_keyed(interp, cur_ns, $2);
204 $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
208 =item B<get_hll_global>(out PMC, in STR)
210 Set $1 to the global named $2 in the current HLL root namespace. If the
211 global doesn't exist, $1 is set to null.
213 =item B<get_hll_global>(out PMC, in PMC, in STR)
215 Set $1 to the global named $3 in the namespace denoted by the key constant
216 $2, relative to the current HLL root namespace. If the namespace or the
217 global doesn't exist, $1 is set to null.
221 op get_hll_global(out PMC, in STR) {
222 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
223 $1 = Parrot_find_global_op(interp, hll_ns, $2, expr NEXT());
226 op get_hll_global(out PMC, in PMC, in STR) {
227 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
228 if (PMC_IS_NULL(hll_ns)) {
232 PMC * const ns = Parrot_get_namespace_keyed(interp, hll_ns, $2);
236 $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
240 =item B<get_root_global>(out PMC, in STR)
242 Set $1 to the global named $2 in the true root namespace. If the global
243 doesn't exist, $1 is set to null.
245 =item B<get_root_global>(out PMC, in PMC, in STR)
247 Set $1 to the global named $3 in the namespace denoted by the key constant
248 $2, relative to the true root namespace. If the namespace or the global
249 doesn't exist, $1 is set to null.
253 op get_root_global(out PMC, in STR) {
254 PMC * const root_ns = interp->root_namespace;
255 $1 = Parrot_find_global_op(interp, root_ns, $2, expr NEXT());
258 op get_root_global(out PMC, in PMC, in STR) {
259 PMC * const root_ns = interp->root_namespace;
260 if (PMC_IS_NULL(root_ns))
263 PMC * const ns = Parrot_get_namespace_keyed(interp, root_ns, $2);
267 $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
275 ###############################################################################
277 =head2 Global variable 'set' opcodes
281 =item B<set_global>(in STR, invar PMC)
283 Set the global named $1 in the current namespace to $2.
285 =item B<set_global>(in PMC, in STR, invar PMC)
287 Set the global named $2 in the namespace denoted by the key constant $1,
288 relative to the current namespace, to $3. If the namespace does not exist,
293 op set_global(in STR, invar PMC) {
294 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
295 Parrot_set_global(interp, cur_ns, $1, $2);
298 op set_global(in PMC, in STR, invar PMC) {
299 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
300 PMC * const ns = Parrot_make_namespace_keyed(interp, cur_ns, $1);
302 Parrot_set_global(interp, ns, $2, $3);
305 =item B<set_hll_global>(in STR, invar PMC)
307 Set the global named $1 to $2 in the current HLL root namespace.
309 =item B<set_hll_global>(in PMC, in STR, invar PMC)
311 Set the global named $2 in the namespace denoted by the key constant
312 $1 (relative to the current HLL namespace) to $3. If the namespace
313 does not exist, it is created.
317 op set_hll_global(in STR, invar PMC) {
318 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
319 Parrot_set_global(interp, hll_ns, $1, $2);
322 op set_hll_global(in PMC, in STR, invar PMC) {
323 PMC * const hll_ns = Parrot_get_ctx_HLL_namespace(interp);
324 PMC * const ns = Parrot_make_namespace_keyed(interp, hll_ns, $1);
326 Parrot_set_global(interp, ns, $2, $3);
329 =item B<set_root_global>(in STR, invar PMC)
331 Set the global named $1 in the true root namespace to $2.
333 =item B<set_root_global>(in PMC, in STR, invar PMC)
335 Set the global named $2 in the namespace denoted by the key constant
336 $1 (relative to the true root namespace) to $3. If the namespace does
337 not exist, it is created.
341 op set_root_global(in STR, invar PMC) {
342 PMC * const root_ns = interp->root_namespace;
343 Parrot_set_global(interp, root_ns, $1, $2);
346 op set_root_global(in PMC, in STR, invar PMC) {
347 PMC * const root_ns = interp->root_namespace;
348 PMC * const ns = Parrot_make_namespace_keyed(interp, root_ns, $1);
350 Parrot_set_global(interp, ns, $2, $3);
357 ###############################################################################
359 =head2 Global variable ops
361 Operations to modify global variables
367 ########################################
369 =item B<store_global>(in STR, invar PMC)
371 Store value $2 as global symbol $1 in the current namespace.
373 =item B<store_global>(in STR, in STR, invar PMC)
375 =item B<store_global>(in PMC, in STR, invar PMC)
377 Store global $3 as global symbol $2 in namespace designated by $1. If
378 namespace does not exist, create it. $1 may be a key, a string, or an array
383 op store_global(in STR, invar PMC) :deprecated {
384 Parrot_store_global_cur(interp, $1, $2);
387 op store_global(in STR, in STR, invar PMC) :deprecated {
388 Parrot_store_global_s(interp, $1, $2, $3);
391 op store_global(in PMC, in STR, invar PMC) :deprecated {
392 Parrot_store_global_k(interp, $1, $2, $3);
395 ########################################
397 =item B<find_global>(out PMC, in STR)
399 Find the global named $2 in the current namespace and store it in $1.
401 If the global doesn't exist either throws an exception or sets $1 to the
402 Null PMC, depending on current errors settings. See B<errorson>.
404 =item B<find_global>(out PMC, in STR, in STR)
406 Find the global named $3 in the namespace named $2 and store it in $1.
408 If the global doesn't exist either throws an exception or sets $1 to the
409 Null PMC, depending on current errors settings. See B<errorson>.
411 =item B<find_global>(out PMC, in PMC, in STR)
413 Find the global named $3 in the namespace designated by $2 and store it in
414 $1. $2 may be a key, a string, or an array of strings.
416 If the global doesn't exist either throws an exception or sets $1 to the
417 Null PMC, depending on current errors settings. See B<errorson>.
421 op find_global(out PMC, in STR) :deprecated {
422 PMC * const cur_ns = CONTEXT(interp)->current_namespace;
423 $1 = Parrot_find_global_op(interp, cur_ns, $2, expr NEXT());
426 op find_global(out PMC, in STR, in STR) :deprecated {
427 PMC * const ns = Parrot_get_namespace_keyed_str(interp,
428 Parrot_get_ctx_HLL_namespace(interp),
430 $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
433 op find_global(out PMC, in PMC, in STR) :deprecated {
434 PMC * const ns = Parrot_get_namespace_keyed(interp,
435 Parrot_get_ctx_HLL_namespace(interp),
437 $1 = Parrot_find_global_op(interp, ns, $3, expr NEXT());
440 =item B<find_name>(out PMC, in STR)
442 Find the name $2 in lexical, current, global, or builtin namespace and
443 store it in $1. If the name doesn't exist
444 either throws an exception or sets $1 to PMCNULL, depending on current
445 errors settings. See B<errorson>.
449 op find_name(out PMC, in STR) {
451 real_exception(interp, NULL, 1, "Tried to find null name");
453 $1 = Parrot_find_name_op(interp, $2, expr NEXT());
460 Copyright (C) 2001-2008, The Perl Foundation.
464 This program is free software. It is subject to the same license
465 as the Parrot interpreter itself.
471 * c-file-style: "parrot"
473 * vim: expandtab shiftwidth=4: