1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 You should have received a copy of the GNU General Public License
14 along with GCC; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
20 #include "coretypes.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
41 #include "py-dot-codes.def"
46 #include "py-runtime.h"
48 VEC(tree
,gc
) * gpy_fold_primitive (const gpy_symbol_obj
* const sym
)
50 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
55 tree address
= build_decl (sym
->loc
, VAR_DECL
, create_tmp_var_name("P"),
57 VEC_safe_push (tree
, gc
, retval
,
58 build2 (MODIFY_EXPR
, gpy_object_type_ptr
,
59 address
, gpy_builtin_get_fold_int_call (sym
->op_a
.integer
))
61 VEC_safe_push (tree
, gc
, retval
, address
);
66 fatal_error("invalid primitive type <0x%x>!\n", sym
->op_a_t
);
73 VEC(tree
,gc
) * gpy_fold_call (tree decl
, location_t l
)
75 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
80 VEC(tree
,gc
) * gpy_process_assign (gpy_symbol_obj
** op_a
, gpy_symbol_obj
** op_b
,
81 VEC(gpy_ctx_t
,gc
) * context
)
83 VEC(tree
,gc
) * retval
= NULL
;
84 gpy_symbol_obj
*opa
, *opb
;
86 if( op_a
&& op_b
) { opa
= *op_a
; opb
= *op_b
; }
88 fatal_error("operands A or B are undefined!\n");
92 if( opa
->type
== SYMBOL_REFERENCE
)
94 int l
= (VEC_length( gpy_ctx_t
, context
));
95 VEC(tree
,gc
) * rhs_tree_vec
= NULL
;
97 tree decl
= gpy_ctx_lookup_decl (context
, opa
->op_a
.string
);
101 gpy_ctx_t x
= VEC_index (gpy_ctx_t
, context
, (l
-1));
103 decl
= build_decl (opa
->loc
, VAR_DECL
,
104 get_identifier (opa
->op_a
.string
),
105 gpy_object_type_ptr
);
107 if (!gpy_ctx_push_decl (decl
, opa
->op_a
.string
, x
))
108 fatal_error("error pushing var decl <%s>!\n", opa
->op_a
.string
);
111 rhs_tree_vec
= gpy_process_expression (opb
, context
);
112 tree rhs_tree_res_decl
= VEC_pop (tree
, rhs_tree_vec
);
114 retval
= rhs_tree_vec
;
116 VEC_safe_push (tree
, gc
, retval
, build2 (MODIFY_EXPR
, gpy_object_type_ptr
,
117 decl
,rhs_tree_res_decl
));
118 VEC_safe_push (tree
, gc
, retval
, gpy_builtin_get_incr_ref_call (decl
));
119 VEC_safe_push (tree
, gc
, retval
, gpy_builtin_get_set_decl_call (decl
));
120 VEC_safe_push (tree
, gc
, retval
, decl
);
124 fatal_error("Invalid accessor for assignment <0x%x>!\n", opa
->type
);
130 gpy_process_bin_expression (gpy_symbol_obj
** op_a
, gpy_symbol_obj
** op_b
,
131 gpy_opcode_t operation
, VEC(gpy_ctx_t
,gc
) * context
)
133 VEC(tree
,gc
) * retval
= NULL
;
134 VEC(tree
,gc
) * t1
= NULL
, * t2
= NULL
;
137 gpy_symbol_obj
*opa
, *opb
;
138 if( op_a
&& op_b
) { opa
= *op_a
; opb
= *op_b
; }
140 fatal_error("operands A or B are undefined!\n");
144 t1
= gpy_process_expression (opa
, context
);
145 t2
= gpy_process_expression (opb
, context
);
147 tree t1_res_decl
= VEC_pop (tree
, t1
);
148 tree t2_res_decl
= VEC_pop (tree
, t2
);
152 case OP_BIN_ADDITION
:
153 op
= gpy_builtin_get_eval_expression_call (t1_res_decl
, t2_res_decl
,
158 fatal_error("unhandled symbol type <0x%x>!\n", operation
);
166 int idx
= 0; tree itx
= NULL_TREE
;
167 for ( ; VEC_iterate(tree
,t1
,idx
,itx
); ++idx
)
169 VEC_safe_push (tree
,gc
,retval
,itx
);
172 tree address
= build_decl (opa
->loc
, VAR_DECL
, create_tmp_var_name("T"),
173 gpy_object_type_ptr
);
174 VEC_safe_push (tree
, gc
, retval
,
175 build2 (MODIFY_EXPR
, gpy_object_type_ptr
, address
, op
));
177 VEC_safe_push (tree
,gc
,retval
,address
);