5 * Intermediate Code Compiler for Parrot.
7 * Copyright (C) 2002 Melvin Smith <melvin.smith@mindspring.com>
8 * Copyright (C) 2002-2010, Parrot Foundation.
10 * Grammar of the PIR language parser.
23 #include "parrot/dynext.h"
24 #include "pmc/pmc_callcontext.h"
27 #include "optimizer.h"
29 /* prevent declarations of malloc() and free() in the generated parser. */
31 #define YYFREE(Ptr) do { /* empty */; } while (YYID (0))
34 # define YYENABLE_NLS 0
37 #ifndef YYLTYPE_IS_TRIVIAL
38 # define YYLTYPE_IS_TRIVIAL 0
41 /* HEADERIZER HFILE: compilers/imcc/imc.h */
43 /* HEADERIZER BEGIN: static */
44 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
46 static void add_pcc_named_arg
(PARROT_INTERP
,
47 ARGMOD
(SymReg
*cur_call
),
49 ARGMOD
(SymReg
*value
))
50 __attribute__nonnull__
(1)
51 __attribute__nonnull__
(2)
52 __attribute__nonnull__
(3)
53 __attribute__nonnull__
(4)
54 FUNC_MODIFIES
(*cur_call
)
56 FUNC_MODIFIES
(*value
);
58 static void add_pcc_named_arg_var
(PARROT_INTERP
,
59 ARGMOD
(SymReg
*cur_call
),
61 ARGMOD
(SymReg
*value
))
62 __attribute__nonnull__
(1)
63 __attribute__nonnull__
(2)
64 __attribute__nonnull__
(3)
65 __attribute__nonnull__
(4)
66 FUNC_MODIFIES
(*cur_call
)
68 FUNC_MODIFIES
(*value
);
70 static void add_pcc_named_param
(PARROT_INTERP
,
71 ARGMOD
(SymReg
*cur_call
),
73 ARGMOD
(SymReg
*value
))
74 __attribute__nonnull__
(1)
75 __attribute__nonnull__
(2)
76 __attribute__nonnull__
(3)
77 __attribute__nonnull__
(4)
78 FUNC_MODIFIES
(*cur_call
)
80 FUNC_MODIFIES
(*value
);
82 static void add_pcc_named_result
(PARROT_INTERP
,
83 ARGMOD
(SymReg
*cur_call
),
85 ARGMOD
(SymReg
*value
))
86 __attribute__nonnull__
(1)
87 __attribute__nonnull__
(2)
88 __attribute__nonnull__
(3)
89 __attribute__nonnull__
(4)
90 FUNC_MODIFIES
(*cur_call
)
92 FUNC_MODIFIES
(*value
);
94 static void add_pcc_named_return
(PARROT_INTERP
,
95 ARGMOD
(SymReg
*cur_call
),
97 ARGMOD
(SymReg
*value
))
98 __attribute__nonnull__
(1)
99 __attribute__nonnull__
(2)
100 __attribute__nonnull__
(3)
101 __attribute__nonnull__
(4)
102 FUNC_MODIFIES
(*cur_call
)
104 FUNC_MODIFIES
(*value
);
106 static void adv_named_set
(PARROT_INTERP
, ARGIN
(const char *name
))
107 __attribute__nonnull__
(1)
108 __attribute__nonnull__
(2);
110 static void adv_named_set_u
(PARROT_INTERP
, ARGIN
(const char *name
))
111 __attribute__nonnull__
(1)
112 __attribute__nonnull__
(2);
114 static void begin_return_or_yield
(PARROT_INTERP
, int yield
)
115 __attribute__nonnull__
(1);
117 static void clear_state
(PARROT_INTERP
)
118 __attribute__nonnull__
(1);
120 static void do_loadlib
(PARROT_INTERP
, ARGIN
(const char *lib
))
121 __attribute__nonnull__
(1)
122 __attribute__nonnull__
(2);
124 PARROT_WARN_UNUSED_RESULT
125 PARROT_CAN_RETURN_NULL
126 static Instruction
* func_ins
(PARROT_INTERP
,
127 ARGMOD
(IMC_Unit
*unit
),
129 ARGIN
(const char *op
),
134 __attribute__nonnull__
(1)
135 __attribute__nonnull__
(2)
136 __attribute__nonnull__
(3)
137 __attribute__nonnull__
(4)
138 __attribute__nonnull__
(5)
142 PARROT_WARN_UNUSED_RESULT
143 PARROT_CAN_RETURN_NULL
144 static Instruction
* iINDEXFETCH
(PARROT_INTERP
,
145 ARGMOD
(IMC_Unit
*unit
),
149 __attribute__nonnull__
(1)
150 __attribute__nonnull__
(2)
151 __attribute__nonnull__
(3)
152 __attribute__nonnull__
(4)
153 __attribute__nonnull__
(5)
154 FUNC_MODIFIES
(*unit
);
156 PARROT_WARN_UNUSED_RESULT
157 PARROT_CAN_RETURN_NULL
158 static Instruction
* iINDEXSET
(PARROT_INTERP
,
159 ARGMOD
(IMC_Unit
*unit
),
163 __attribute__nonnull__
(1)
164 __attribute__nonnull__
(2)
165 __attribute__nonnull__
(3)
166 __attribute__nonnull__
(4)
167 __attribute__nonnull__
(5)
168 FUNC_MODIFIES
(*unit
);
170 PARROT_WARN_UNUSED_RESULT
171 PARROT_CANNOT_RETURN_NULL
172 static Instruction
* iLABEL
(PARROT_INTERP
,
173 ARGMOD_NULLOK
(IMC_Unit
*unit
),
175 __attribute__nonnull__
(1)
176 __attribute__nonnull__
(3)
180 PARROT_WARN_UNUSED_RESULT
181 PARROT_CAN_RETURN_NULL
182 static const char * inv_op
(ARGIN
(const char *op
))
183 __attribute__nonnull__
(1);
185 PARROT_IGNORABLE_RESULT
186 PARROT_CANNOT_RETURN_NULL
187 static Instruction
* iSUBROUTINE
(PARROT_INTERP
,
188 ARGMOD_NULLOK
(IMC_Unit
*unit
),
190 __attribute__nonnull__
(1)
191 __attribute__nonnull__
(3)
195 PARROT_IGNORABLE_RESULT
196 PARROT_CAN_RETURN_NULL
197 static Instruction
* MK_I
(PARROT_INTERP
,
198 ARGMOD
(IMC_Unit
*unit
),
199 ARGIN
(const char *fmt
),
202 __attribute__nonnull__
(1)
203 __attribute__nonnull__
(2)
204 __attribute__nonnull__
(3)
205 FUNC_MODIFIES
(*unit
);
207 PARROT_WARN_UNUSED_RESULT
208 PARROT_CAN_RETURN_NULL
209 static Instruction
* mk_pmc_const
(PARROT_INTERP
,
210 ARGMOD
(IMC_Unit
*unit
),
211 ARGIN
(const char *type
),
212 ARGMOD
(SymReg
*left
),
213 ARGIN
(const char *constant
))
214 __attribute__nonnull__
(1)
215 __attribute__nonnull__
(2)
216 __attribute__nonnull__
(3)
217 __attribute__nonnull__
(4)
218 __attribute__nonnull__
(5)
220 FUNC_MODIFIES
(*left
);
222 PARROT_WARN_UNUSED_RESULT
223 PARROT_CAN_RETURN_NULL
224 static Instruction
* mk_pmc_const_named
(PARROT_INTERP
,
225 ARGMOD
(IMC_Unit
*unit
),
226 ARGIN
(const char *name
),
227 ARGMOD
(SymReg
*left
),
228 ARGIN
(const char *constant
))
229 __attribute__nonnull__
(1)
230 __attribute__nonnull__
(2)
231 __attribute__nonnull__
(3)
232 __attribute__nonnull__
(4)
233 __attribute__nonnull__
(5)
235 FUNC_MODIFIES
(*left
);
237 PARROT_WARN_UNUSED_RESULT
238 PARROT_CANNOT_RETURN_NULL
239 static SymReg
* mk_sub_address_fromc
(PARROT_INTERP
, ARGIN
(const char *name
))
240 __attribute__nonnull__
(1)
241 __attribute__nonnull__
(2);
243 PARROT_WARN_UNUSED_RESULT
244 PARROT_CANNOT_RETURN_NULL
245 static SymReg
* mk_sub_address_u
(PARROT_INTERP
, ARGIN
(const char *name
))
246 __attribute__nonnull__
(1)
247 __attribute__nonnull__
(2);
249 static void set_lexical
(PARROT_INTERP
,
251 ARGMOD
(SymReg
*name
))
252 __attribute__nonnull__
(1)
253 __attribute__nonnull__
(2)
254 __attribute__nonnull__
(3)
256 FUNC_MODIFIES
(*name
);
258 #define ASSERT_ARGS_add_pcc_named_arg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
259 PARROT_ASSERT_ARG
(interp
) \
260 , PARROT_ASSERT_ARG
(cur_call
) \
261 , PARROT_ASSERT_ARG
(name
) \
262 , PARROT_ASSERT_ARG
(value
))
263 #define ASSERT_ARGS_add_pcc_named_arg_var __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
264 PARROT_ASSERT_ARG
(interp
) \
265 , PARROT_ASSERT_ARG
(cur_call
) \
266 , PARROT_ASSERT_ARG
(name
) \
267 , PARROT_ASSERT_ARG
(value
))
268 #define ASSERT_ARGS_add_pcc_named_param __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
269 PARROT_ASSERT_ARG
(interp
) \
270 , PARROT_ASSERT_ARG
(cur_call
) \
271 , PARROT_ASSERT_ARG
(name
) \
272 , PARROT_ASSERT_ARG
(value
))
273 #define ASSERT_ARGS_add_pcc_named_result __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
274 PARROT_ASSERT_ARG
(interp
) \
275 , PARROT_ASSERT_ARG
(cur_call
) \
276 , PARROT_ASSERT_ARG
(name
) \
277 , PARROT_ASSERT_ARG
(value
))
278 #define ASSERT_ARGS_add_pcc_named_return __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
279 PARROT_ASSERT_ARG
(interp
) \
280 , PARROT_ASSERT_ARG
(cur_call
) \
281 , PARROT_ASSERT_ARG
(name
) \
282 , PARROT_ASSERT_ARG
(value
))
283 #define ASSERT_ARGS_adv_named_set __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
284 PARROT_ASSERT_ARG
(interp
) \
285 , PARROT_ASSERT_ARG
(name
))
286 #define ASSERT_ARGS_adv_named_set_u __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
287 PARROT_ASSERT_ARG
(interp
) \
288 , PARROT_ASSERT_ARG
(name
))
289 #define ASSERT_ARGS_begin_return_or_yield __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
290 PARROT_ASSERT_ARG
(interp
))
291 #define ASSERT_ARGS_clear_state __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
292 PARROT_ASSERT_ARG
(interp
))
293 #define ASSERT_ARGS_do_loadlib __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
294 PARROT_ASSERT_ARG
(interp
) \
295 , PARROT_ASSERT_ARG
(lib
))
296 #define ASSERT_ARGS_func_ins __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
297 PARROT_ASSERT_ARG
(interp
) \
298 , PARROT_ASSERT_ARG
(unit
) \
299 , PARROT_ASSERT_ARG
(lhs
) \
300 , PARROT_ASSERT_ARG
(op
) \
301 , PARROT_ASSERT_ARG
(r
))
302 #define ASSERT_ARGS_iINDEXFETCH __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
303 PARROT_ASSERT_ARG
(interp
) \
304 , PARROT_ASSERT_ARG
(unit
) \
305 , PARROT_ASSERT_ARG
(r0
) \
306 , PARROT_ASSERT_ARG
(r1
) \
307 , PARROT_ASSERT_ARG
(r2
))
308 #define ASSERT_ARGS_iINDEXSET __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
309 PARROT_ASSERT_ARG
(interp
) \
310 , PARROT_ASSERT_ARG
(unit
) \
311 , PARROT_ASSERT_ARG
(r0
) \
312 , PARROT_ASSERT_ARG
(r1
) \
313 , PARROT_ASSERT_ARG
(r2
))
314 #define ASSERT_ARGS_iLABEL __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
315 PARROT_ASSERT_ARG
(interp
) \
316 , PARROT_ASSERT_ARG
(r0
))
317 #define ASSERT_ARGS_inv_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
318 PARROT_ASSERT_ARG
(op
))
319 #define ASSERT_ARGS_iSUBROUTINE __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
320 PARROT_ASSERT_ARG
(interp
) \
321 , PARROT_ASSERT_ARG
(r
))
322 #define ASSERT_ARGS_MK_I __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
323 PARROT_ASSERT_ARG
(interp
) \
324 , PARROT_ASSERT_ARG
(unit
) \
325 , PARROT_ASSERT_ARG
(fmt
))
326 #define ASSERT_ARGS_mk_pmc_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
327 PARROT_ASSERT_ARG
(interp
) \
328 , PARROT_ASSERT_ARG
(unit
) \
329 , PARROT_ASSERT_ARG
(type
) \
330 , PARROT_ASSERT_ARG
(left
) \
331 , PARROT_ASSERT_ARG
(constant
))
332 #define ASSERT_ARGS_mk_pmc_const_named __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
333 PARROT_ASSERT_ARG
(interp
) \
334 , PARROT_ASSERT_ARG
(unit
) \
335 , PARROT_ASSERT_ARG
(name
) \
336 , PARROT_ASSERT_ARG
(left
) \
337 , PARROT_ASSERT_ARG
(constant
))
338 #define ASSERT_ARGS_mk_sub_address_fromc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
339 PARROT_ASSERT_ARG
(interp
) \
340 , PARROT_ASSERT_ARG
(name
))
341 #define ASSERT_ARGS_mk_sub_address_u __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
342 PARROT_ASSERT_ARG
(interp
) \
343 , PARROT_ASSERT_ARG
(name
))
344 #define ASSERT_ARGS_set_lexical __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
345 PARROT_ASSERT_ARG
(interp
) \
346 , PARROT_ASSERT_ARG
(r
) \
347 , PARROT_ASSERT_ARG
(name
))
348 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
349 /* HEADERIZER END: static */
353 #define YYERROR_VERBOSE 1
356 * We use a pure parser with the interpreter as a parameter. However this still
357 * doesn't make the parser reentrant, as there are too many globals around.
361 * Choosing instructions for Parrot is pretty easy since many are
370 =item C<static Instruction * MK_I(PARROT_INTERP, IMC_Unit *unit, const char
373 build and emitb instruction by INS. fmt may contain:
381 NOTE: Most usage of this function is with
382 IMCC_INFO(interp)->cur_unit, but there are some
383 exceptions. Thus, we can't easily factorize that piece of
390 PARROT_IGNORABLE_RESULT
391 PARROT_CAN_RETURN_NULL
393 MK_I
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
), ARGIN
(const char *fmt
), int n
, ...
)
400 SymReg
*r
[IMCC_MAX_FIX_REGS
];
403 for
(p
= opname
, q
= fmt
; *q
&& *q
!= ' ';)
411 fprintf
(stderr
, "op '%s' format '%s' (%d)\n", opname
, fmt?
:"", n
);
415 for
(i
= 0; i
< n
; ++i
) {
416 r
[i
] = va_arg
(ap
, SymReg
*);
419 return INS
(interp
, unit
, opname
, fmt
, r
, n
,
420 IMCC_INFO
(interp
)->keyvec
, 1);
425 =item C<static Instruction* mk_pmc_const(PARROT_INTERP, IMC_Unit *unit, const
426 char *type, SymReg *left, const char *constant)>
432 PARROT_WARN_UNUSED_RESULT
433 PARROT_CAN_RETURN_NULL
435 mk_pmc_const
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
), ARGIN
(const char *type
),
436 ARGMOD
(SymReg
*left
), ARGIN
(const char *constant
))
438 ASSERT_ARGS
(mk_pmc_const
)
439 const int type_enum
= atoi
(type
);
440 const int ascii
= (*constant
== '\'' ||
*constant
== '"');
445 if
(left
->type
== VTADDRESS
) { /* IDENTIFIER */
446 if
(IMCC_INFO
(interp
)->state
->pasm_file
) {
447 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
448 "Ident as PMC constant",
449 " %s\n", left
->name
);
451 left
->type
= VTIDENTIFIER
;
456 /* strip delimiters */
457 name
= mem_sys_strdup
(constant
+ 1);
458 name
[strlen
(name
) - 1] = 0;
461 name
= mem_sys_strdup
(constant
);
466 case enum_class_Coroutine
:
467 rhs
= mk_const
(interp
, name
, 'p');
470 rhs
->type |
= VT_ENCODED
;
472 rhs
->usage |
= U_FIXUP | U_SUBID_LOOKUP
;
475 rhs
= mk_const
(interp
, name
, 'P');
480 rhs
->pmc_type
= type_enum
;
484 return INS
(interp
, unit
, "set_p_pc", "", r
, 2, 0, 1);
489 =item C<static Instruction* mk_pmc_const_named(PARROT_INTERP, IMC_Unit *unit,
490 const char *name, SymReg *left, const char *constant)>
496 PARROT_WARN_UNUSED_RESULT
497 PARROT_CAN_RETURN_NULL
499 mk_pmc_const_named
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
),
500 ARGIN
(const char *name
), ARGMOD
(SymReg
*left
), ARGIN
(const char *constant
))
502 ASSERT_ARGS
(mk_pmc_const_named
)
506 const int ascii
= (*constant
== '\'' ||
*constant
== '"');
507 char *unquoted_name
= mem_sys_strdup
(name
+ 1);
508 size_t name_length
= strlen
(unquoted_name
) - 1;
510 unquoted_name
[name_length
] = 0;
512 if
(left
->type
== VTADDRESS
) { /* IDENTIFIER */
513 if
(IMCC_INFO
(interp
)->state
->pasm_file
) {
514 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
515 "Ident as PMC constant",
516 " %s\n", left
->name
);
518 left
->type
= VTIDENTIFIER
;
523 /* strip delimiters */
524 const_name
= mem_sys_strdup
(constant
+ 1);
525 const_name
[strlen
(const_name
) - 1] = 0;
528 const_name
= mem_sys_strdup
(constant
);
531 if
((strncmp
(unquoted_name
, "Sub", name_length
) == 0)
532 ||
(strncmp
(unquoted_name
, "Coroutine", name_length
) == 0)) {
533 rhs
= mk_const
(interp
, const_name
, 'p');
536 rhs
->type |
= VT_ENCODED
;
538 rhs
->usage |
= U_FIXUP | U_SUBID_LOOKUP
;
541 rhs
= mk_const
(interp
, const_name
, 'P');
545 rhs
->pmc_type
= Parrot_pmc_get_type_str
(interp
,
546 Parrot_str_new
(interp
, unquoted_name
, name_length
));
548 mem_sys_free
(unquoted_name
);
549 mem_sys_free
(const_name
);
551 return INS
(interp
, unit
, "set_p_pc", "", r
, 2, 0, 1);
556 =item C<static Instruction* func_ins(PARROT_INTERP, IMC_Unit *unit, SymReg *lhs,
557 const char *op, SymReg **r, int n, int keyv, int emit)>
563 PARROT_WARN_UNUSED_RESULT
564 PARROT_CAN_RETURN_NULL
566 func_ins
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
), ARGIN
(SymReg
*lhs
), ARGIN
(const char *op
),
567 ARGMOD
(SymReg
**r
), int n
, int keyv
, int emit
)
569 ASSERT_ARGS
(func_ins
)
571 /* shift regs up by 1 */
572 for
(i
= n
- 1; i
>= 0; --i
)
577 return INS
(interp
, unit
, op
, "", r
, n
+1, keyv
, emit
);
582 =item C<static void clear_state(PARROT_INTERP)>
589 clear_state
(PARROT_INTERP
)
591 ASSERT_ARGS
(clear_state
)
592 IMCC_INFO
(interp
) -> nargs
= 0;
593 IMCC_INFO
(interp
) -> keyvec
= 0;
598 =item C<Instruction * INS_LABEL(PARROT_INTERP, IMC_Unit *unit, SymReg *r0, int
605 PARROT_WARN_UNUSED_RESULT
606 PARROT_CANNOT_RETURN_NULL
608 INS_LABEL
(PARROT_INTERP
, ARGMOD_NULLOK
(IMC_Unit
*unit
), ARGMOD
(SymReg
*r0
), int emit
)
610 ASSERT_ARGS
(INS_LABEL
)
612 Instruction
* const ins
= _mk_instruction
("", "%s:", 1, &r0
, 0);
617 emitb
(interp
, unit
, ins
);
624 =item C<static Instruction * iLABEL(PARROT_INTERP, IMC_Unit *unit, SymReg *r0)>
630 PARROT_WARN_UNUSED_RESULT
631 PARROT_CANNOT_RETURN_NULL
633 iLABEL
(PARROT_INTERP
, ARGMOD_NULLOK
(IMC_Unit
*unit
), ARGMOD
(SymReg
*r0
))
636 Instruction
* const i
= INS_LABEL
(interp
, unit
, r0
, 1);
637 i
->line
= IMCC_INFO
(interp
)->line
;
645 =item C<static Instruction * iSUBROUTINE(PARROT_INTERP, IMC_Unit *unit, SymReg
652 PARROT_IGNORABLE_RESULT
653 PARROT_CANNOT_RETURN_NULL
655 iSUBROUTINE
(PARROT_INTERP
, ARGMOD_NULLOK
(IMC_Unit
*unit
), ARGMOD
(SymReg
*r
))
657 ASSERT_ARGS
(iSUBROUTINE
)
658 Instruction
* const i
= iLABEL
(interp
, unit
, r
);
660 r
->type
= (r
->type
& VT_ENCODED
) ? VT_PCC_SUB|VT_ENCODED
: VT_PCC_SUB
;
661 r
->pcc_sub
= mem_gc_allocate_zeroed_typed
(interp
, pcc_sub_t
);
663 IMCC_INFO
(interp
)->cur_call
= r
;
664 i
->line
= IMCC_INFO
(interp
)->line
;
666 add_namespace
(interp
, unit
);
672 =item C<static Instruction * iINDEXFETCH(PARROT_INTERP, IMC_Unit *unit, SymReg
673 *r0, SymReg *r1, SymReg *r2)>
681 PARROT_WARN_UNUSED_RESULT
682 PARROT_CAN_RETURN_NULL
684 iINDEXFETCH
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
), ARGIN
(SymReg
*r0
), ARGIN
(SymReg
*r1
),
687 ASSERT_ARGS
(iINDEXFETCH
)
688 IMCC_INFO
(interp
) -> keyvec |
= KEY_BIT
(2);
689 return MK_I
(interp
, unit
, "set %s, %s[%s]", 3, r0
, r1
, r2
);
694 =item C<static Instruction * iINDEXSET(PARROT_INTERP, IMC_Unit *unit, SymReg
695 *r0, SymReg *r1, SymReg *r2)>
703 PARROT_WARN_UNUSED_RESULT
704 PARROT_CAN_RETURN_NULL
706 iINDEXSET
(PARROT_INTERP
, ARGMOD
(IMC_Unit
*unit
), ARGIN
(SymReg
*r0
), ARGIN
(SymReg
*r1
),
709 ASSERT_ARGS
(iINDEXSET
)
710 if
(r0
->set
== 'P') {
711 IMCC_INFO
(interp
)->keyvec |
= KEY_BIT
(1);
712 MK_I
(interp
, unit
, "set %s[%s], %s", 3, r0
, r1
, r2
);
715 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
716 "unsupported indexed set op\n");
723 =item C<static const char * inv_op(const char *op)>
729 PARROT_WARN_UNUSED_RESULT
730 PARROT_CAN_RETURN_NULL
732 inv_op
(ARGIN
(const char *op
))
736 return get_neg_op
(op
, &n
);
741 =item C<Instruction * IMCC_create_itcall_label(PARROT_INTERP)>
747 PARROT_WARN_UNUSED_RESULT
748 PARROT_CANNOT_RETURN_NULL
750 IMCC_create_itcall_label
(PARROT_INTERP
)
752 ASSERT_ARGS
(IMCC_create_itcall_label
)
757 snprintf
(name
, sizeof
(name
), "%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR
,
758 IMCC_INFO
(interp
)->cnr
++);
760 r
= mk_pcc_sub
(interp
, name
, 0);
761 i
= iLABEL
(interp
, IMCC_INFO
(interp
)->cur_unit
, r
);
762 i
->type
= ITCALL | ITPCCSUB
;
764 IMCC_INFO
(interp
)->cur_call
= r
;
771 =item C<static SymReg * mk_sub_address_fromc(PARROT_INTERP, const char *name)>
777 PARROT_WARN_UNUSED_RESULT
778 PARROT_CANNOT_RETURN_NULL
780 mk_sub_address_fromc
(PARROT_INTERP
, ARGIN
(const char *name
))
782 ASSERT_ARGS
(mk_sub_address_fromc
)
783 /* name is a quoted sub name */
787 /* interpolate only if the first character is a double-quote */
789 STRING
*unescaped
= Parrot_str_unescape
(interp
, name
, '"', NULL
);
790 name_copy
= Parrot_str_to_cstring
(interp
, unescaped
);
793 name_copy
= mem_sys_strdup
(name
);
794 name_copy
[ strlen
(name
) - 1 ] = 0;
797 r
= mk_sub_address
(interp
, name_copy
+ 1);
798 mem_sys_free
(name_copy
);
805 =item C<static SymReg * mk_sub_address_u(PARROT_INTERP, const char *name)>
811 PARROT_WARN_UNUSED_RESULT
812 PARROT_CANNOT_RETURN_NULL
814 mk_sub_address_u
(PARROT_INTERP
, ARGIN
(const char *name
))
816 ASSERT_ARGS
(mk_sub_address_u
)
817 SymReg
* const r
= mk_sub_address
(interp
, name
);
818 r
->type |
= VT_ENCODED
;
825 =item C<void IMCC_itcall_sub(PARROT_INTERP, SymReg *sub)>
832 IMCC_itcall_sub
(PARROT_INTERP
, ARGIN
(SymReg
*sub
))
834 ASSERT_ARGS
(IMCC_itcall_sub
)
835 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->sub
= sub
;
837 if
(IMCC_INFO
(interp
)->cur_obj
) {
838 if
(IMCC_INFO
(interp
)->cur_obj
->set
!= 'P')
839 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
, "object isn't a PMC");
841 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->object
=
842 IMCC_INFO
(interp
)->cur_obj
;
843 IMCC_INFO
(interp
)->cur_obj
= NULL
;
846 if
(IMCC_INFO
(interp
)->cur_call
->pcc_sub
->sub
->pmc_type
== enum_class_NCI
)
847 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->flags |
= isNCI
;
849 if
(IMCC_INFO
(interp
)->cur_unit
->type
== IMC_PCCSUB
)
850 IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0]->pcc_sub
->calls_a_sub |
= 1;
856 =item C<static void begin_return_or_yield(PARROT_INTERP, int yield)>
863 begin_return_or_yield
(PARROT_INTERP
, int yield
)
865 ASSERT_ARGS
(begin_return_or_yield
)
867 Instruction
* const ins
= IMCC_INFO
(interp
)->cur_unit
->instructions
;
870 if
(!ins ||
!ins
->symregs
[0] ||
!(ins
->symregs
[0]->type
& VT_PCC_SUB
))
871 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
872 "yield or return directive outside pcc subroutine\n");
874 ins
->symregs
[0]->pcc_sub
->calls_a_sub
= 1 | ITPCCYIELD
;
875 snprintf
(name
, sizeof
(name
), yield ?
"%cpcc_sub_yield_%d" : "%cpcc_sub_ret_%d",
876 IMCC_INTERNAL_CHAR
, IMCC_INFO
(interp
)->cnr
++);
877 interp
->imc_info
->sr_return
= mk_pcc_sub
(interp
, name
, 0);
878 i
= iLABEL
(interp
, IMCC_INFO
(interp
)->cur_unit
, interp
->imc_info
->sr_return
);
879 i
->type
= yield ? ITPCCSUB | ITLABEL | ITPCCYIELD
: ITPCCSUB | ITLABEL
;
880 interp
->imc_info
->asm_state
= yield ? AsmInYield
: AsmInReturn
;
885 =item C<static void set_lexical(PARROT_INTERP, SymReg *r, SymReg *name)>
892 set_lexical
(PARROT_INTERP
, ARGMOD
(SymReg
*r
), ARGMOD
(SymReg
*name
))
894 ASSERT_ARGS
(set_lexical
)
896 r
->usage |
= U_LEXICAL
;
899 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
900 "register %s already declared as lexical %s", r
->name
, name
->name
);
902 /* chain all names in r->reg */
905 name
->usage |
= U_LEXICAL
;
912 =item C<static void add_pcc_named_arg(PARROT_INTERP, SymReg *cur_call, SymReg
913 *name, SymReg *value)>
920 add_pcc_named_arg
(PARROT_INTERP
,
921 ARGMOD
(SymReg
*cur_call
),
922 ARGMOD
(SymReg
*name
),
923 ARGMOD
(SymReg
*value
))
925 ASSERT_ARGS
(add_pcc_named_arg
)
926 name
->type |
= VT_NAMED
;
928 add_pcc_arg
(interp
, cur_call
, name
);
929 add_pcc_arg
(interp
, cur_call
, value
);
934 =item C<static void add_pcc_named_arg_var(PARROT_INTERP, SymReg *cur_call,
935 SymReg *name, SymReg *value)>
942 add_pcc_named_arg_var
(PARROT_INTERP
,
943 ARGMOD
(SymReg
*cur_call
),
944 ARGMOD
(SymReg
*name
),
945 ARGMOD
(SymReg
*value
))
947 ASSERT_ARGS
(add_pcc_named_arg_var
)
948 name
->type |
= VT_NAMED
;
949 add_pcc_arg
(interp
, cur_call
, name
);
950 add_pcc_arg
(interp
, cur_call
, value
);
955 =item C<static void add_pcc_named_result(PARROT_INTERP, SymReg *cur_call, SymReg
956 *name, SymReg *value)>
963 add_pcc_named_result
(PARROT_INTERP
,
964 ARGMOD
(SymReg
*cur_call
),
965 ARGMOD
(SymReg
*name
),
966 ARGMOD
(SymReg
*value
))
968 ASSERT_ARGS
(add_pcc_named_result
)
969 name
->type |
= VT_NAMED
;
971 add_pcc_result
(interp
, cur_call
, name
);
972 add_pcc_result
(interp
, cur_call
, value
);
977 =item C<static void add_pcc_named_param(PARROT_INTERP, SymReg *cur_call, SymReg
978 *name, SymReg *value)>
985 add_pcc_named_param
(PARROT_INTERP
,
986 ARGMOD
(SymReg
*cur_call
),
987 ARGMOD
(SymReg
*name
),
988 ARGMOD
(SymReg
*value
))
990 ASSERT_ARGS
(add_pcc_named_param
)
991 name
->type |
= VT_NAMED
;
993 add_pcc_arg
(interp
, cur_call
, name
);
994 add_pcc_arg
(interp
, cur_call
, value
);
999 =item C<static void add_pcc_named_return(PARROT_INTERP, SymReg *cur_call, SymReg
1000 *name, SymReg *value)>
1007 add_pcc_named_return
(PARROT_INTERP
,
1008 ARGMOD
(SymReg
*cur_call
),
1009 ARGMOD
(SymReg
*name
),
1010 ARGMOD
(SymReg
*value
))
1012 ASSERT_ARGS
(add_pcc_named_return
)
1013 name
->type |
= VT_NAMED
;
1015 add_pcc_result
(interp
, cur_call
, name
);
1016 add_pcc_result
(interp
, cur_call
, value
);
1021 =item C<static void adv_named_set(PARROT_INTERP, const char *name)>
1023 Sets the name of the current named argument.
1025 C<adv_named_set_u> is the Unicode version of this function.
1032 adv_named_set
(PARROT_INTERP
, ARGIN
(const char *name
))
1034 ASSERT_ARGS
(adv_named_set
)
1035 if
(IMCC_INFO
(interp
)->adv_named_id
)
1036 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
1037 "Named parameter with more than one name.\n");
1039 IMCC_INFO
(interp
)->adv_named_id
= mk_const
(interp
, name
, 'S');
1043 adv_named_set_u
(PARROT_INTERP
, ARGIN
(const char *name
))
1045 ASSERT_ARGS
(adv_named_set_u
)
1046 if
(IMCC_INFO
(interp
)->adv_named_id
)
1047 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
1048 "Named parameter with more than one name.\n");
1050 IMCC_INFO
(interp
)->adv_named_id
= mk_const
(interp
, name
, 'U');
1055 =item C<static void do_loadlib(PARROT_INTERP, const char *lib)>
1062 do_loadlib
(PARROT_INTERP
, ARGIN
(const char *lib
))
1064 ASSERT_ARGS
(do_loadlib
)
1065 STRING
* const s
= Parrot_str_unescape
(interp
, lib
+ 1, '"', NULL
);
1066 PMC
*ignored
= Parrot_load_lib
(interp
, s
, NULL
);
1068 Parrot_register_HLL_lib
(interp
, s
);
1071 /* HEADERIZER STOP */
1083 /* We need precedence for a few tokens to resolve a couple of conflicts */
1088 %token
<t
> SOL HLL TK_LINE TK_FILE
1089 %token
<t
> GOTO ARG IF UNLESS PNULL SET_RETURN SET_YIELD
1090 %token
<t
> ADV_FLAT ADV_SLURPY ADV_OPTIONAL ADV_OPT_FLAG ADV_NAMED ADV_ARROW
1091 %token
<t
> NEW ADV_INVOCANT ADV_CALL_SIG
1092 %token
<t
> NAMESPACE DOT_METHOD
1093 %token
<t
> SUB SYM LOCAL LEXICAL CONST ANNOTATE
1094 %token
<t
> INC DEC GLOBAL_CONST
1095 %token
<t
> PLUS_ASSIGN MINUS_ASSIGN MUL_ASSIGN DIV_ASSIGN CONCAT_ASSIGN
1096 %token
<t
> BAND_ASSIGN BOR_ASSIGN BXOR_ASSIGN FDIV FDIV_ASSIGN MOD_ASSIGN
1097 %token
<t
> SHR_ASSIGN SHL_ASSIGN SHR_U_ASSIGN
1098 %token
<t
> SHIFT_LEFT SHIFT_RIGHT INTV FLOATV STRINGV PMCV LOG_XOR
1099 %token
<t
> RELOP_EQ RELOP_NE RELOP_GT RELOP_GTE RELOP_LT RELOP_LTE
1100 %token
<t
> RESULT RETURN TAILCALL YIELDT GET_RESULTS
1101 %token
<t
> POW SHIFT_RIGHT_U LOG_AND LOG_OR
1102 %token
<t
> COMMA ESUB DOTDOT
1103 %token
<t
> PCC_BEGIN PCC_END PCC_CALL PCC_SUB PCC_BEGIN_RETURN PCC_END_RETURN
1104 %token
<t
> PCC_BEGIN_YIELD PCC_END_YIELD NCI_CALL METH_CALL INVOCANT
1105 %token
<t
> MAIN LOAD INIT IMMEDIATE POSTCOMP METHOD ANON OUTER NEED_LEX
1106 %token
<t
> MULTI VTABLE_METHOD LOADLIB SUB_INSTANCE_OF SUBID
1108 %token
<t
> UNIQUE_REG
1111 %token
<s
> IREG NREG SREG PREG IDENTIFIER REG MACRO ENDM
1112 %token
<s
> STRINGC INTC FLOATC USTRINGC
1113 %token
<s
> PARROT_OP
1114 %type
<t
> type hll_def return_or_yield comma_or_goto opt_unique_reg
1116 %type
<i
> class_namespace
1117 %type
<i
> constdef sub emit pcc_ret pcc_yield
1118 %type
<i
> compilation_units compilation_unit pmc_const pragma
1119 %type
<s
> classname relop any_string assign_op bin_op un_op
1120 %type
<i
> labels _labels label statement sub_call
1121 %type
<i
> pcc_sub_call
1122 %type
<sr
> sub_param sub_params pcc_arg pcc_result pcc_args pcc_results sub_param_type_def
1123 %type
<sr
> pcc_returns pcc_yields pcc_return pcc_call arg arglist the_sub multi_type
1124 %type
<t
> argtype_list argtype paramtype_list paramtype
1125 %type
<t
> pcc_return_many
1126 %type
<t
> proto sub_proto sub_proto_list multi multi_types outer
1127 %type
<t
> vtable instanceof subid
1128 %type
<t
> method ns_entry_name
1129 %type
<i
> instruction assignment conditional_statement labeled_inst opt_label op_assign
1130 %type
<i
> if_statement unless_statement
1131 %type
<i
> func_assign get_results
1132 %type
<i
> opt_invocant
1133 %type
<i
> annotate_directive
1134 %type
<sr
> target targetlist reg
const var result pcc_set_yield
1135 %type
<sr
> keylist keylist_force _keylist key maybe_ns
1136 %type
<sr
> vars _vars var_or_i _var_or_i label_op sub_label_op sub_label_op_c
1137 %type
<i
> pasmcode pasmline pasm_inst
1138 %type
<sr
> pasm_args
1139 %type
<i
> var_returns
1142 %token
<t
> LINECOMMENT
1143 %token
<s
> FILECOMMENT
1144 %type
<idlist
> id_list id_list_id
1146 %nonassoc CONCAT DOT
1152 /* Note that we pass interp last, because Bison only passes
1153 the last param to yyerror(). (Tested on bison <= 2.3)
1155 %parse
-param
{void *yyscanner
}
1156 %lex
-param
{void *yyscanner
}
1157 %parse
-param
{Parrot_Interp interp
}
1158 %lex
-param
{Parrot_Interp interp
}
1162 /* In effort to make the grammar readable but not militaristic, please space indent
1163 code blocks on 10 col boundaries and keep indentation same for all code blocks
1164 in a rule. Indent rule tokens | and ; to 4th col and sub rules 6th col
1170 compilation_units
{ if
(yynerrs) YYABORT; $$
= 0; }
1175 | compilation_units compilation_unit
1179 class_namespace
{ $$
= $1; }
1180 | constdef
{ $$
= $1; }
1184 imc_close_unit
(interp
, IMCC_INFO
(interp
)->cur_unit
);
1185 IMCC_INFO
(interp
)->cur_unit
= 0;
1190 imc_close_unit
(interp
, IMCC_INFO
(interp
)->cur_unit
);
1191 IMCC_INFO
(interp
)->cur_unit
= 0;
1193 | MACRO
'\n' { $$
= 0; }
1194 | pragma
{ $$
= 0; }
1195 | location_directive
{ $$
= 0; }
1200 hll_def
'\n' { $$
= 0; }
1201 | LOADLIB STRINGC
'\n'
1204 do_loadlib
(interp
, $2);
1210 TK_LINE INTC COMMA STRINGC
'\n'
1212 IMCC_INFO
(interp
)->line
= atoi
($2);
1213 /* set_filename() frees the STRINGC */
1214 set_filename
(interp
, $4);
1216 | TK_FILE STRINGC
'\n'
1218 /* set_filename() frees the STRINGC */
1219 set_filename
(interp
, $2);
1224 ANNOTATE STRINGC COMMA
const
1226 /* We'll want to store an entry while emitting instructions, so just
1227 * store annotation like it's an instruction. */
1228 SymReg
* const key
= mk_const
(interp
, $2, 'S');
1229 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, ".annotate", 2, key
, $4);
1238 STRING
* const hll_name
= Parrot_str_unescape
(interp
, $2 + 1, '"', NULL
);
1239 Parrot_pcc_set_HLL
(interp
, CURRENT_CONTEXT
(interp
),
1240 Parrot_register_HLL
(interp
, hll_name
));
1242 IMCC_INFO
(interp
)->cur_namespace
= NULL
;
1249 CONST
{ IMCC_INFO
(interp
)->is_def
= 1; } type IDENTIFIER
'=' const
1251 mk_const_ident
(interp
, $4, $3, $6, 1);
1253 IMCC_INFO
(interp
)->is_def
= 0;
1258 CONST
{ IMCC_INFO
(interp
)->is_def
= 1; } INTC var_or_i
'=' any_string
1260 $$
= mk_pmc_const
(interp
, IMCC_INFO
(interp
)->cur_unit
, $3, $4, $6);
1262 IMCC_INFO
(interp
)->is_def
= 0;
1265 | CONST
{ IMCC_INFO
(interp
)->is_def
= 1; } STRINGC var_or_i
'=' any_string
1267 $$
= mk_pmc_const_named
(interp
, IMCC_INFO
(interp
)->cur_unit
, $3, $4, $6);
1270 IMCC_INFO
(interp
)->is_def
= 0;
1284 labels pasm_inst
'\n' { $$
= 0; }
1285 | MACRO
'\n' { $$
= 0; }
1286 | FILECOMMENT
{ $$
= 0; }
1287 | LINECOMMENT
{ $$
= 0; }
1288 | class_namespace
{ $$
= $1; }
1293 pasm_inst: { clear_state
(interp
); }
1296 $$
= INS
(interp
, IMCC_INFO
(interp
)->cur_unit
,
1297 $2, 0, IMCC_INFO
(interp
)->regs
,
1298 IMCC_INFO
(interp
)->nargs
, IMCC_INFO
(interp
) -> keyvec
, 1);
1303 imc_close_unit
(interp
, IMCC_INFO
(interp
)->cur_unit
);
1304 IMCC_INFO
(interp
)->cur_unit
= imc_open_unit
(interp
, IMC_PASM
);
1308 $$
= iSUBROUTINE
(interp
,
1309 IMCC_INFO
(interp
)->cur_unit
,
1310 mk_sub_label
(interp
, $4));
1311 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->pragma
= $3;
1316 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "null", 1, $2);
1318 | LEXICAL STRINGC COMMA REG
1320 char *name
= mem_sys_strdup
($2 + 1);
1321 SymReg
*r
= mk_pasm_reg
(interp
, $4);
1323 name
[strlen
(name
) - 1] = 0;
1324 n
= mk_const
(interp
, name
, 'S');
1325 set_lexical
(interp
, r
, n
);
1331 |
/* none */ { $$
= 0;}
1338 emit: /* EMIT and EOM tokens are used when compiling a .pasm file. */
1339 EMIT
{ IMCC_INFO
(interp
)->cur_unit
= imc_open_unit
(interp
, IMC_PASM
); }
1343 /* if (optimizer_level & OPT_PASM)
1344 imc_compile_unit(interp, IMCC_INFO(interp)->cur_unit);
1357 NAMESPACE maybe_ns
'\n'
1361 if
(IMCC_INFO
(interp
)->state
->pasm_file
&& IMCC_INFO
(interp
)->cur_namespace
) {
1362 imc_close_unit
(interp
, IMCC_INFO
(interp
)->cur_unit
);
1365 IMCC_INFO
(interp
)->cur_namespace
= $2;
1367 IMCC_INFO
(interp
)->cur_unit
= imc_open_unit
(interp
, IMC_PASM
);
1376 |
'[' ']' { $$
= NULL
; }
1382 IMCC_INFO
(interp
)->cur_unit
= imc_open_unit
(interp
, IMC_PCCSUB
);
1386 iSUBROUTINE
(interp
, IMCC_INFO
(interp
)->cur_unit
, $3);
1390 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->pragma
= $5;
1391 if
(!IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0]->subid
) {
1392 IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0]->subid
= mem_sys_strdup
(
1393 IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0]->name
);
1397 sub_body ESUB
{ $$
= 0; IMCC_INFO
(interp
)->cur_call
= NULL
; }
1401 /* empty */ { $$
= 0; } %prec LOW_PREC
1403 | sub_params sub_param
'\n'
1405 if
(IMCC_INFO
(interp
)->adv_named_id
) {
1406 add_pcc_named_param
(interp
, IMCC_INFO
(interp
)->cur_call
,
1407 IMCC_INFO
(interp
)->adv_named_id
, $2);
1408 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
1411 add_pcc_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, $2);
1416 PARAM
{ IMCC_INFO
(interp
)->is_def
= 1; } sub_param_type_def
{ $$
= $3; IMCC_INFO
(interp
)->is_def
= 0; }
1420 type IDENTIFIER paramtype_list
1422 if
($3 & VT_UNIQUE_REG
)
1423 $$
= mk_ident_ur
(interp
, $2, $1);
1424 else if
($3 & VT_OPT_FLAG
&& $1 != 'I') {
1427 case
'N': type
= "num"; break
;
1428 case
'S': type
= "string"; break
;
1429 case
'P': type
= "pmc"; break
;
1430 default
: type
= "strange"; break
;
1433 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
1434 ":opt_flag parameter must be of type 'I', not '%s'", type
);
1437 $$
= mk_ident
(interp
, $2, $1);
1446 MULTI
'(' multi_types
')' { $$
= 0; }
1450 OUTER
'(' STRINGC
')'
1453 IMCC_INFO
(interp
)->cur_unit
->outer
= mk_sub_address_fromc
(interp
, $3);
1456 | OUTER
'(' IDENTIFIER
')'
1459 IMCC_INFO
(interp
)->cur_unit
->outer
= mk_const
(interp
, $3, 'S');
1468 IMCC_INFO
(interp
)->cur_unit
->vtable_name
= NULL
;
1469 IMCC_INFO
(interp
)->cur_unit
->is_vtable_method
= 1;
1471 | VTABLE_METHOD
'(' STRINGC
')'
1474 IMCC_INFO
(interp
)->cur_unit
->vtable_name
= $3;
1475 IMCC_INFO
(interp
)->cur_unit
->is_vtable_method
= 1;
1483 IMCC_INFO
(interp
)->cur_unit
->method_name
= NULL
;
1484 IMCC_INFO
(interp
)->cur_unit
->is_method
= 1;
1486 | METHOD
'(' any_string
')'
1489 IMCC_INFO
(interp
)->cur_unit
->method_name
= $3;
1490 IMCC_INFO
(interp
)->cur_unit
->is_method
= 1;
1498 IMCC_INFO
(interp
)->cur_unit
->ns_entry_name
= NULL
;
1499 IMCC_INFO
(interp
)->cur_unit
->has_ns_entry_name
= 1;
1501 | NS_ENTRY
'(' any_string
')'
1504 IMCC_INFO
(interp
)->cur_unit
->ns_entry_name
= $3;
1505 IMCC_INFO
(interp
)->cur_unit
->has_ns_entry_name
= 1;
1510 SUB_INSTANCE_OF
'(' STRINGC
')'
1513 IMCC_INFO
(interp
)->cur_unit
->instance_of
= $3;
1521 IMCC_INFO
(interp
)->cur_unit
->subid
= NULL
;
1523 | SUBID
'(' any_string
')'
1526 IMCC_INFO
(interp
)->cur_unit
->subid
= mk_const
(interp
, $3, 'S');
1527 IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0]->subid
= str_dup_remove_quotes
($3);
1535 add_pcc_multi
(interp
, IMCC_INFO
(interp
)->cur_call
, NULL
);
1537 | multi_types COMMA multi_type
1540 add_pcc_multi
(interp
, IMCC_INFO
(interp
)->cur_call
, $3);
1545 add_pcc_multi
(interp
, IMCC_INFO
(interp
)->cur_call
, $1);
1550 INTV
{ $$
= mk_const
(interp
, "INTVAL", 'S'); }
1551 | FLOATV
{ $$
= mk_const
(interp
, "FLOATVAL", 'S'); }
1552 | PMCV
{ $$
= mk_const
(interp
, "PMC", 'S'); }
1553 | STRINGV
{ $$
= mk_const
(interp
, "STRING", 'S'); }
1557 if
(strcmp
($1, "_") != 0)
1558 r
= mk_const
(interp
, $1, 'S');
1560 r
= mk_const
(interp
, "PMC", 'S');
1568 if
(strcmp
($1, "_") != 0)
1569 r
= mk_const
(interp
, $1, 'S');
1571 r
= mk_const
(interp
, "PMC", 'S');
1576 |
'[' keylist
']' { $$
= $2; }
1591 snprintf
(name
, sizeof
(name
), "%cpcc_sub_call_%d",
1592 IMCC_INTERNAL_CHAR
, IMCC_INFO
(interp
)->cnr
++);
1593 $
<sr
>$
= r
= mk_pcc_sub
(interp
, name
, 0);
1594 /* this mid rule action has the semantic value of the
1596 * This is used below to append args & results
1598 i
= iLABEL
(interp
, IMCC_INFO
(interp
)->cur_unit
, r
);
1599 IMCC_INFO
(interp
)->cur_call
= r
;
1602 * if we are inside a pcc_sub mark the sub as doing a
1603 * sub call; the sub is in r[0] of the first ins
1605 r1
= IMCC_INFO
(interp
)->cur_unit
->instructions
->symregs
[0];
1606 if
(r1
&& r1
->pcc_sub
)
1607 r1
->pcc_sub
->calls_a_sub |
= 1;
1614 PCC_END
{ $$
= 0; IMCC_INFO
(interp
)->cur_call
= NULL
; }
1618 /* empty */ { $$
= NULL
; IMCC_INFO
(interp
)->cur_call
->pcc_sub
->label
= 0; }
1619 | label
'\n' { $$
= NULL
; IMCC_INFO
(interp
)->cur_call
->pcc_sub
->label
= 1; }
1623 /* empty */ { $$
= NULL
; }
1624 | INVOCANT var
'\n' { $$
= NULL
; IMCC_INFO
(interp
)->cur_call
->pcc_sub
->object
= $2; }
1628 /* empty */ { $$
= 0; }
1634 | sub_proto_list proto
{ $$
= $1 |
$2; }
1638 LOAD
{ $$
= P_LOAD
; }
1639 | INIT
{ $$
= P_INIT
; }
1640 | MAIN
{ $$
= P_MAIN
; }
1641 | IMMEDIATE
{ $$
= P_IMMEDIATE
; }
1642 | POSTCOMP
{ $$
= P_POSTCOMP
; }
1643 | ANON
{ $$
= P_ANON
; }
1644 | NEED_LEX
{ $$
= P_NEED_LEX
; }
1655 PCC_CALL var COMMA var
'\n'
1657 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, $2);
1658 add_pcc_cc
(IMCC_INFO
(interp
)->cur_call
, $4);
1662 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, $2);
1666 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, $2);
1667 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->flags |
= isNCI
;
1669 | METH_CALL target
'\n'
1671 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, $2);
1673 | METH_CALL STRINGC
'\n'
1675 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, mk_const
(interp
, $2, 'S'));
1677 | METH_CALL target COMMA var
'\n'
1679 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, $2);
1680 add_pcc_cc
(IMCC_INFO
(interp
)->cur_call
, $4);
1682 | METH_CALL STRINGC COMMA var
'\n'
1684 add_pcc_sub
(IMCC_INFO
(interp
)->cur_call
, mk_const
(interp
, $2, 'S'));
1685 add_pcc_cc
(IMCC_INFO
(interp
)->cur_call
, $4);
1691 /* empty */ { $$
= 0; }
1692 | pcc_args pcc_arg
'\n' { add_pcc_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, $2); }
1696 ARG arg
{ $$
= $2; }
1701 /* empty */ { $$
= 0; }
1702 | pcc_results pcc_result
'\n'
1705 add_pcc_result
(interp
, IMCC_INFO
(interp
)->cur_call
, $2);
1710 RESULT target paramtype_list
{ $$
= $2; $$
->type |
= $3; }
1711 | LOCAL
{ IMCC_INFO
(interp
)->is_def
= 1; } type id_list_id
1713 IdList
* const l
= $4;
1716 ignored
= mk_ident_ur
(interp
, l
->id
, $3);
1718 ignored
= mk_ident
(interp
, l
->id
, $3);
1720 IMCC_INFO
(interp
)->is_def
= 0;
1726 /* empty */ { $$
= 0; }
1727 | paramtype_list paramtype
{ $$
= $1 |
$2; }
1731 ADV_SLURPY
{ $$
= VT_FLAT
; }
1732 | ADV_OPTIONAL
{ $$
= VT_OPTIONAL
; }
1733 | ADV_OPT_FLAG
{ $$
= VT_OPT_FLAG
; }
1734 | ADV_NAMED
{ $$
= VT_NAMED
; }
1735 | ADV_NAMED
'(' STRINGC
')' { adv_named_set
(interp
, $3); $$
= 0; mem_sys_free
($3); }
1736 | ADV_NAMED
'(' USTRINGC
')' { adv_named_set_u
(interp
, $3); $$
= 0; mem_sys_free
($3); }
1737 | UNIQUE_REG
{ $$
= VT_UNIQUE_REG
; }
1738 | ADV_CALL_SIG
{ $$
= VT_CALL_SIG
; }
1743 PCC_BEGIN_RETURN
'\n' { begin_return_or_yield
(interp
, 0); }
1745 PCC_END_RETURN
{ $$
= 0; IMCC_INFO
(interp
)->asm_state
= AsmDefault
; }
1748 IMCC_INFO
(interp
)->asm_state
= AsmDefault
;
1754 PCC_BEGIN_YIELD
'\n' { begin_return_or_yield
(interp
, 1); }
1756 PCC_END_YIELD
{ $$
= 0; IMCC_INFO
(interp
)->asm_state
= AsmDefault
; }
1760 /* empty */ { $$
= 0; }
1764 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $1);
1766 | pcc_returns pcc_return
'\n'
1769 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $2);
1774 /* empty */ { $$
= 0; }
1778 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $1);
1780 | pcc_yields pcc_set_yield
'\n'
1783 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $2);
1788 SET_RETURN var argtype_list
{ $$
= $2; $$
->type |
= $3; }
1792 SET_YIELD var argtype_list
{ $$
= $2; $$
->type |
= $3; }
1798 if
(IMCC_INFO
(interp
)->asm_state
== AsmDefault
)
1799 begin_return_or_yield
(interp
, $1);
1803 IMCC_INFO
(interp
)->asm_state
= AsmDefault
;
1810 | YIELDT
{ $$
= 1; }
1814 /* empty */ { $$
= 0; }
1817 if
(IMCC_INFO
(interp
)->adv_named_id
) {
1818 add_pcc_named_return
(interp
, IMCC_INFO
(interp
)->sr_return
,
1819 IMCC_INFO
(interp
)->adv_named_id
, $1);
1820 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
1823 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $1);
1825 | STRINGC ADV_ARROW var
1827 SymReg
* const name
= mk_const
(interp
, $1, 'S');
1828 add_pcc_named_return
(interp
, IMCC_INFO
(interp
)->sr_return
, name
, $3);
1830 | var_returns COMMA arg
1832 if
(IMCC_INFO
(interp
)->adv_named_id
) {
1833 add_pcc_named_return
(interp
, IMCC_INFO
(interp
)->sr_return
,
1834 IMCC_INFO
(interp
)->adv_named_id
, $3);
1835 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
1838 add_pcc_result
(interp
, IMCC_INFO
(interp
)->sr_return
, $3);
1840 | var_returns COMMA STRINGC ADV_ARROW var
1842 SymReg
* const name
= mk_const
(interp
, $3, 'S');
1843 add_pcc_named_return
(interp
, IMCC_INFO
(interp
)->sr_return
, name
, $5);
1850 | statements statement
1853 /* This is ugly. Because 'instruction' can start with PARAM and in the
1854 * 'pcc_sub' rule, 'pcc_params' is followed by 'statement', we get a
1855 * shift/reduce conflict on PARAM between reducing to the dummy
1856 * { clear_state(); } rule and shifting the PARAM to be used as part
1857 * of the 'pcc_params' (which is what we want). However, yacc syntax
1858 * doesn't propagate precedence to the dummy rules, so we have to
1859 * split out the action just so that we can assign it a precedence. */
1862 { clear_state
(interp
); } %prec LOW_PREC
1867 instruction
{ $$
= $2; }
1868 | MACRO
'\n' { $$
= 0; }
1869 | FILECOMMENT
{ $$
= 0; }
1870 | LINECOMMENT
{ $$
= 0; }
1871 | location_directive
{ $$
= 0; }
1872 | annotate_directive
{ $$
= $1; }
1876 /* none */ { $$
= NULL
; }
1888 Instruction
* const i
= iLABEL
(interp
, IMCC_INFO
(interp
)->cur_unit
, mk_local_label
(interp
, $1));
1897 labels labeled_inst
'\n' { $$
= $2; }
1900 if
(yynerrs >= PARROT_MAX_RECOVER_ERRORS
) {
1901 IMCC_warning
(interp
, "Too many errors. Correct some first.\n");
1911 IdList
* const l
= $1;
1916 | id_list COMMA id_list_id
1918 IdList
* const l
= $3;
1925 IDENTIFIER opt_unique_reg
1927 IdList
* const l
= mem_gc_allocate_n_zeroed_typed
(interp
, 1, IdList
);
1935 /* empty */ { $$
= 0; }
1936 | UNIQUE_REG
{ $$
= 1; }
1942 | conditional_statement
1943 | LOCAL
{ IMCC_INFO
(interp
)->is_def
= 1; } type id_list
1949 mk_ident_ur
(interp
, l
->id
, $3);
1951 mk_ident
(interp
, l
->id
, $3);
1954 mem_sys_free
(l1
->id
);
1957 IMCC_INFO
(interp
)->is_def
= 0; $$
= 0;
1959 | LEXICAL STRINGC COMMA target
1961 if
($4->set
!= 'P') {
1963 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
1964 "Cannot use %c register with .lex", $4->set
);
1968 char *name
= mem_sys_strdup
($2 + 1);
1969 name
[strlen
(name
) - 1] = 0;
1970 n
= mk_const
(interp
, name
, 'S');
1971 set_lexical
(interp
, $4, n
); $$
= 0;
1976 | LEXICAL USTRINGC COMMA target
1978 if
($4->set
!= 'P') {
1980 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
1981 "Cannot use %c register with .lex", $4->set
);
1984 SymReg
*n
= mk_const
(interp
, $2, 'U');
1985 set_lexical
(interp
, $4, n
); $$
= 0;
1989 | CONST
{ IMCC_INFO
(interp
)->is_def
= 1; } type IDENTIFIER
'=' const
1991 mk_const_ident
(interp
, $4, $3, $6, 0);
1992 IMCC_INFO
(interp
)->is_def
= 0;
1997 | GLOBAL_CONST
{ IMCC_INFO
(interp
)->is_def
= 1; } type IDENTIFIER
'=' const
1999 mk_const_ident
(interp
, $4, $3, $6, 1);
2000 IMCC_INFO
(interp
)->is_def
= 0;
2006 IMCC_INFO
(interp
)->cur_call
->pcc_sub
->flags |
= isTAIL_CALL
;
2007 IMCC_INFO
(interp
)->cur_call
= NULL
;
2011 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "branch", 1, $2);
2016 IMCC_INFO
(interp
)->cur_unit
,
2019 IMCC_INFO
(interp
)->regs
,
2020 IMCC_INFO
(interp
)->nargs
,
2021 IMCC_INFO
(interp
)->keyvec
,
2025 | PNULL var
{ $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "null", 1, $2); }
2026 | sub_call
{ $$
= 0; IMCC_INFO
(interp
)->cur_call
= NULL
; }
2027 | pcc_sub_call
{ $$
= 0; }
2030 |
/* none */ { $$
= 0;}
2035 | FLOATV
{ $$
= 'N'; }
2036 | STRINGV
{ $$
= 'S'; }
2037 | PMCV
{ $$
= 'P'; }
2043 /* there'd normally be a mem_sys_strdup() here, but the lexer already
2044 * copied the string, so it's safe to use directly */
2045 if
((IMCC_INFO
(interp
)->cur_pmc_type
= Parrot_pmc_get_type_str
(interp
,
2046 Parrot_str_new
(interp
, $1, 0))) <= 0) {
2047 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
2048 "Unknown PMC type '%s'\n", $1);
2055 { $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "set", 2, $1, $3); }
2056 | target
'=' un_op var
2057 { $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, $3, 2, $1, $4); }
2058 | target
'=' var bin_op var
2059 { $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, $4, 3, $1, $3, $5); }
2060 | target
'=' var
'[' keylist
']'
2061 { $$
= iINDEXFETCH
(interp
, IMCC_INFO
(interp
)->cur_unit
, $1, $3, $5); }
2062 | target
'[' keylist
']' '=' var
2063 { $$
= iINDEXSET
(interp
, IMCC_INFO
(interp
)->cur_unit
, $1, $3, $6); }
2064 /* Removing this line causes test failures in t/compilers/tge/* for
2065 some reason. Eventually it should be removed and the normal handling
2066 of ops should be used for all forms of "new". */
2067 | target
'=' 'new' classname
'[' keylist
']'
2068 { $$
= iNEW
(interp
, IMCC_INFO
(interp
)->cur_unit
, $1, $4, $6, 1); }
2069 /* Subroutine call the short way */
2070 | target
'=' sub_call
2072 add_pcc_result
(interp
, $3->symregs
[0], $1);
2073 IMCC_INFO
(interp
)->cur_call
= NULL
;
2078 $
<i
>$
= IMCC_create_itcall_label
(interp
);
2080 targetlist
')' '=' the_sub
'(' arglist
')'
2082 IMCC_itcall_sub
(interp
, $6);
2083 IMCC_INFO
(interp
)->cur_call
= NULL
;
2090 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "null", 1, $1);
2094 /* C++ hates implicit casts from string constants to char *, so be explicit */
2096 '!' { $$
= (char *)"not"; }
2097 |
'~' { $$
= (char *)"bnot"; }
2098 |
'-' { $$
= (char *)"neg"; }
2102 '-' { $$
= (char *)"sub"; }
2103 |
'+' { $$
= (char *)"add"; }
2104 |
'*' { $$
= (char *)"mul"; }
2105 |
'/' { $$
= (char *)"div"; }
2106 |
'%' { $$
= (char *)"mod"; }
2107 | FDIV
{ $$
= (char *)"fdiv"; }
2108 | POW
{ $$
= (char *)"pow"; }
2109 | CONCAT
{ $$
= (char *)"concat"; }
2110 | RELOP_EQ
{ $$
= (char *)"iseq"; }
2111 | RELOP_NE
{ $$
= (char *)"isne"; }
2112 | RELOP_GT
{ $$
= (char *)"isgt"; }
2113 | RELOP_GTE
{ $$
= (char *)"isge"; }
2114 | RELOP_LT
{ $$
= (char *)"islt"; }
2115 | RELOP_LTE
{ $$
= (char *)"isle"; }
2116 | SHIFT_LEFT
{ $$
= (char *)"shl"; }
2117 | SHIFT_RIGHT
{ $$
= (char *)"shr"; }
2118 | SHIFT_RIGHT_U
{ $$
= (char *)"lsr"; }
2119 | LOG_AND
{ $$
= (char *)"and"; }
2120 | LOG_OR
{ $$
= (char *)"or"; }
2121 | LOG_XOR
{ $$
= (char *)"xor"; }
2122 |
'&' { $$
= (char *)"band"; }
2123 |
'|' { $$
= (char *)"bor"; }
2124 |
'~' { $$
= (char *)"bxor"; }
2131 $
<i
>$
= IMCC_create_itcall_label
(interp
);
2132 $
<i
>$
->type
&= ~ITCALL
;
2133 $
<i
>$
->type |
= ITRESULT
;
2135 '(' targetlist
')' { $$
= 0; }
2141 target assign_op var
2142 { $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, $2, 2, $1, $3); }
2146 PLUS_ASSIGN
{ $$
= (char *)"add"; }
2147 | MINUS_ASSIGN
{ $$
= (char *)"sub"; }
2148 | MUL_ASSIGN
{ $$
= (char *)"mul"; }
2149 | DIV_ASSIGN
{ $$
= (char *)"div"; }
2150 | MOD_ASSIGN
{ $$
= (char *)"mod"; }
2151 | FDIV_ASSIGN
{ $$
= (char *)"fdiv"; }
2152 | CONCAT_ASSIGN
{ $$
= (char *)"concat"; }
2153 | BAND_ASSIGN
{ $$
= (char *)"band"; }
2154 | BOR_ASSIGN
{ $$
= (char *)"bor"; }
2155 | BXOR_ASSIGN
{ $$
= (char *)"bxor"; }
2156 | SHR_ASSIGN
{ $$
= (char *)"shr"; }
2157 | SHL_ASSIGN
{ $$
= (char *)"shl"; }
2158 | SHR_U_ASSIGN
{ $$
= (char *)"lsr"; }
2163 target
'=' PARROT_OP pasm_args
2165 $$
= func_ins
(interp
, IMCC_INFO
(interp
)->cur_unit
, $1, $3,
2166 IMCC_INFO
(interp
) -> regs
,
2167 IMCC_INFO
(interp
) -> nargs
,
2168 IMCC_INFO
(interp
) -> keyvec
, 1);
2174 IDENTIFIER
{ $$
= mk_sub_address
(interp
, $1); mem_sys_free
($1); }
2175 | STRINGC
{ $$
= mk_sub_address_fromc
(interp
, $1); mem_sys_free
($1); }
2176 | USTRINGC
{ $$
= mk_sub_address_u
(interp
, $1); mem_sys_free
($1); }
2181 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
, "Sub isn't a PMC");
2183 | target DOT sub_label_op
2185 /* disallow bareword method names; SREG name constants are fine */
2186 const char * const name
= $3->name
;
2187 if
(!($3->type
& VTREG
)) {
2188 if
(*name
!= '\'' ||
*name
!= '\"')
2189 IMCC_fataly
(interp
, EXCEPTION_SYNTAX_ERROR
,
2190 "Bareword method name '%s' not allowed in PIR",
2194 IMCC_INFO
(interp
)->cur_obj
= $1;
2197 | target DOT USTRINGC
2199 IMCC_INFO
(interp
)->cur_obj
= $1;
2200 $$
= mk_const
(interp
, $3, 'U');
2203 | target DOT STRINGC
2205 IMCC_INFO
(interp
)->cur_obj
= $1;
2206 $$
= mk_const
(interp
, $3, 'S');
2209 | target DOT target
{ IMCC_INFO
(interp
)->cur_obj
= $1; $$
= $3; }
2216 $
<i
>$
= IMCC_create_itcall_label
(interp
);
2217 IMCC_itcall_sub
(interp
, $1);
2219 '(' arglist
')' { $$
= $
<i
>2; }
2223 /* empty */ { $$
= 0; }
2227 if
(IMCC_INFO
(interp
)->adv_named_id
) {
2228 add_pcc_named_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, IMCC_INFO
(interp
)->adv_named_id
, $3);
2229 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
2232 add_pcc_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, $3);
2237 if
(IMCC_INFO
(interp
)->adv_named_id
) {
2238 add_pcc_named_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, IMCC_INFO
(interp
)->adv_named_id
, $1);
2239 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
2242 add_pcc_arg
(interp
, IMCC_INFO
(interp
)->cur_call
, $1);
2244 | arglist COMMA STRINGC ADV_ARROW var
2247 add_pcc_named_arg
(interp
, IMCC_INFO
(interp
)->cur_call
,
2248 mk_const
(interp
, $3, 'S'), $5);
2254 add_pcc_named_arg_var
(interp
, IMCC_INFO
(interp
)->cur_call
, $1, $3);
2256 | STRINGC ADV_ARROW var
2259 add_pcc_named_arg
(interp
, IMCC_INFO
(interp
)->cur_call
,
2260 mk_const
(interp
, $1, 'S'), $3);
2266 var argtype_list
{ $$
= $1; $$
->type |
= $2; }
2270 /* empty */ { $$
= 0; }
2271 | argtype_list argtype
{ $$
= $1 |
$2; }
2275 ADV_FLAT
{ $$
= VT_FLAT
; }
2276 | ADV_NAMED
{ $$
= VT_NAMED
; }
2277 | ADV_CALL_SIG
{ $$
= VT_CALL_SIG
; }
2279 /* don't free $3 here; adv_named_set uses the pointer directly */
2280 | ADV_NAMED
'(' USTRINGC
')' { adv_named_set_u
(interp
, $3); $$
= 0; }
2281 | ADV_NAMED
'(' STRINGC
')' { adv_named_set
(interp
, $3); $$
= 0; }
2285 target paramtype_list
{ $$
= $1; $$
->type |
= $2; }
2289 targetlist COMMA result
2292 if
(IMCC_INFO
(interp
)->adv_named_id
) {
2293 add_pcc_named_result
(interp
, IMCC_INFO
(interp
)->cur_call
, IMCC_INFO
(interp
)->adv_named_id
, $3);
2294 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
2297 add_pcc_result
(interp
, IMCC_INFO
(interp
)->cur_call
, $3);
2299 | targetlist COMMA STRINGC ADV_ARROW target
2301 add_pcc_named_result
(interp
, IMCC_INFO
(interp
)->cur_call
,
2302 mk_const
(interp
, $3, 'S'), $5);
2308 if
(IMCC_INFO
(interp
)->adv_named_id
) {
2309 add_pcc_named_result
(interp
, IMCC_INFO
(interp
)->cur_call
, IMCC_INFO
(interp
)->adv_named_id
, $1);
2310 IMCC_INFO
(interp
)->adv_named_id
= NULL
;
2313 add_pcc_result
(interp
, IMCC_INFO
(interp
)->cur_call
, $1);
2315 | STRINGC ADV_ARROW target
2317 add_pcc_named_result
(interp
, IMCC_INFO
(interp
)->cur_call
, mk_const
(interp
, $1, 'S'), $3);
2320 |
/* empty */ { $$
= 0; }
2323 conditional_statement:
2324 if_statement
{ $$
= $1; }
2325 | unless_statement
{ $$
= $1; }
2329 UNLESS var relop var GOTO label_op
2331 $$
=MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, inv_op
($3), 3, $2, $4, $6);
2333 | UNLESS PNULL var GOTO label_op
2335 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "unless_null", 2, $3, $5);
2337 | UNLESS var comma_or_goto label_op
2339 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "unless", 2, $2, $4);
2344 IF var comma_or_goto label_op
2346 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "if", 2, $2, $4);
2348 | IF var relop var GOTO label_op
2350 $$
=MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, $3, 3, $2, $4, $6);
2352 | IF PNULL var GOTO label_op
2354 $$
= MK_I
(interp
, IMCC_INFO
(interp
)->cur_unit
, "if_null", 2, $3, $5);
2364 RELOP_EQ
{ $$
= (char *)"eq"; }
2365 | RELOP_NE
{ $$
= (char *)"ne"; }
2366 | RELOP_GT
{ $$
= (char *)"gt"; }
2367 | RELOP_GTE
{ $$
= (char *)"ge"; }
2368 | RELOP_LT
{ $$
= (char *)"lt"; }
2369 | RELOP_LTE
{ $$
= (char *)"le"; }
2378 /* empty */ { $$
= NULL
; }
2379 | _vars
{ $$
= $1; }
2383 _vars COMMA _var_or_i
{ $$
= IMCC_INFO
(interp
)->regs
[0]; }
2388 var_or_i
{ IMCC_INFO
(interp
)->regs
[IMCC_INFO
(interp
)->nargs
++] = $1; }
2389 | target
'[' keylist
']'
2391 IMCC_INFO
(interp
) -> regs
[IMCC_INFO
(interp
)->nargs
++] = $1;
2392 IMCC_INFO
(interp
) -> keyvec |
= KEY_BIT
(IMCC_INFO
(interp
)->nargs
);
2393 IMCC_INFO
(interp
) -> regs
[IMCC_INFO
(interp
)->nargs
++] = $3;
2396 |
'[' keylist_force
']'
2398 IMCC_INFO
(interp
) -> regs
[IMCC_INFO
(interp
)->nargs
++] = $2;
2404 | STRINGC
{ $$
= mk_sub_address_fromc
(interp
, $1); mem_sys_free
($1); }
2405 | USTRINGC
{ $$
= mk_sub_address_u
(interp
, $1); mem_sys_free
($1); }
2409 IDENTIFIER
{ $$
= mk_sub_address
(interp
, $1); mem_sys_free
($1); }
2410 | PARROT_OP
{ $$
= mk_sub_address
(interp
, $1); mem_sys_free
($1); }
2414 IDENTIFIER
{ $$
= mk_label_address
(interp
, $1); mem_sys_free
($1); }
2415 | PARROT_OP
{ $$
= mk_label_address
(interp
, $1); mem_sys_free
($1); }
2430 IMCC_INFO
(interp
)->nkeys
= 0;
2434 $$
= link_keys
(interp
,
2435 IMCC_INFO
(interp
)->nkeys
,
2436 IMCC_INFO
(interp
)->keys
, 0);
2442 IMCC_INFO
(interp
)->nkeys
= 0;
2446 $$
= link_keys
(interp
,
2447 IMCC_INFO
(interp
)->nkeys
,
2448 IMCC_INFO
(interp
)->keys
, 1);
2453 key
{ IMCC_INFO
(interp
)->keys
[IMCC_INFO
(interp
)->nkeys
++] = $1; }
2456 IMCC_INFO
(interp
)->keys
[IMCC_INFO
(interp
)->nkeys
++] = $3;
2457 $$
= IMCC_INFO
(interp
)->keys
[0];
2469 IREG
{ $$
= mk_symreg
(interp
, $1, 'I'); }
2470 | NREG
{ $$
= mk_symreg
(interp
, $1, 'N'); }
2471 | SREG
{ $$
= mk_symreg
(interp
, $1, 'S'); }
2472 | PREG
{ $$
= mk_symreg
(interp
, $1, 'P'); }
2473 | REG
{ $$
= mk_pasm_reg
(interp
, $1); mem_sys_free
($1); }
2477 INTC
{ $$
= mk_const
(interp
, $1, 'I'); mem_sys_free
($1); }
2478 | FLOATC
{ $$
= mk_const
(interp
, $1, 'N'); mem_sys_free
($1); }
2479 | STRINGC
{ $$
= mk_const
(interp
, $1, 'S'); mem_sys_free
($1); }
2480 | USTRINGC
{ $$
= mk_const
(interp
, $1, 'U'); mem_sys_free
($1); }
2488 /* I need this prototype somewhere... */
2489 char *yyget_text
(yyscan_t yyscanner
);
2491 /* I do not like this function, but, atm, it is the only way I can
2492 * make the code in yyerror work without segfault on some specific
2495 /* int yyholds_char(yyscan_t yyscanner); */
2497 int yyerror(void *yyscanner
, PARROT_INTERP
, const char *s
)
2499 /* If the error occurr in the end of the buffer (I mean, the last
2500 * token was already read), yyget_text will return a pointer
2501 * outside the bison buffer, and thus, not "accessible" by
2502 * us. This means it may segfault. */
2503 const char * const chr
= yyget_text
((yyscan_t
)yyscanner
);
2505 /* IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR, s); */
2506 /* --- This was called before, not sure if I should call some
2507 similar function that does not die like this one. */
2509 /* Basically, if current token is a newline, it mean the error was
2510 * before the newline, and thus, line is the line *after* the
2511 * error. Instead of duplicating code for both cases (the 'newline' and
2512 * non-newline case, do the test twice; efficiency is not important when
2513 * we have an error anyway. */
2514 if
(!at_eof
(yyscanner
)) {
2515 IMCC_warning
(interp
, "error:imcc:%s", s
);
2517 /* don't print the current token if it is a newline */
2519 IMCC_warning
(interp
, " ('%s')", chr
);
2521 IMCC_print_inc
(interp
);
2524 /* scanner is at EOF; just to be sure, don't print "current" token */
2526 IMCC_warning
(interp
, "error:imcc:%s", s
);
2527 IMCC_print_inc
(interp
);
2540 * c-file-style: "parrot"
2542 * vim: expandtab shiftwidth=4: