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"
45 #include "py-runtime.h"
47 VEC(tree
,gc
) * gpy_fold_primitive( const gpy_symbol_obj
* const sym
)
49 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
53 VEC_safe_push( tree
,gc
,retval
,
54 gpy_builtin_get_fold_int_call( sym
->op_a
.integer
) );
58 fatal_error("invalid primitive type <0x%x>!\n", sym
->op_a_t
);
65 VEC(tree
,gc
) * gpy_process_assign( gpy_symbol_obj
** op_a
, gpy_symbol_obj
** op_b
,
66 VEC(gpy_ctx_t
,gc
) * context
)
68 VEC(tree
,gc
) * retval
= NULL
;
69 gpy_symbol_obj
*opa
, *opb
;
71 if( op_a
&& op_b
) { opa
= *op_a
; opb
= *op_b
; }
73 fatal_error("operands A or B are undefined!\n");
77 if( opa
->type
== SYMBOL_REFERENCE
)
79 int l
= (VEC_length( gpy_ctx_t
, context
));
80 VEC(tree
,gc
) * rhs_tree_vec
= NULL
; tree rhs_tree
= NULL_TREE
;
82 tree decl
= gpy_ctx_lookup_decl( context
, opa
->op_a
.string
, VAR
);
86 gpy_ctx_t x
= VEC_index( gpy_ctx_t
, context
, (l
-1) );
88 decl
= build_decl( opa
->loc
, VAR_DECL
,
89 get_identifier( opa
->op_a
.string
),
90 build_pointer_type( void_type_node
) );
92 if( !(gpy_ctx_push_decl( decl
, opa
->op_a
.string
, x
, VAR
)) )
93 fatal_error("error pushing var decl <%s>!\n", opa
->op_a
.string
);
96 rhs_tree_vec
= gpy_process_expression( opb
, context
);
97 gcc_assert( VEC_length(tree
,rhs_tree_vec
) == 1 );
98 rhs_tree
= VEC_index(tree
,rhs_tree_vec
,0);
100 retval
= VEC_alloc(tree
,gc
,0);
102 tree address
= build_decl( opa
->loc
, VAR_DECL
, create_tmp_var_name("A"),
104 VEC_safe_push( tree
, gc
, retval
, build2( MODIFY_EXPR
, ptr_type_node
,
107 VEC_safe_push( tree
,gc
, retval
, gpy_builtin_get_incr_ref_call( address
) );
108 VEC_safe_push( tree
,gc
, retval
, build2( MODIFY_EXPR
, ptr_type_node
, decl
, address
) );
111 fatal_error("Invalid accessor for assignment <0x%x>!\n", opa
->type
);
116 VEC(tree
,gc
) * gpy_process_bin_expression( gpy_symbol_obj
** op_a
, gpy_symbol_obj
** op_b
,
117 gpy_opcode_t operation
, VEC(gpy_ctx_t
,gc
) * context
)
119 VEC(tree
,gc
) * retval
= NULL
;
120 VEC(tree
,gc
) * t1
= NULL
, * t2
= NULL
;
123 gpy_symbol_obj
*opa
, *opb
;
124 if( op_a
&& op_b
) { opa
= *op_a
; opb
= *op_b
; }
126 fatal_error("operands A or B are undefined!\n");
130 t1
= gpy_process_expression( opa
, context
);
131 t2
= gpy_process_expression( opb
, context
);
133 gcc_assert( (VEC_length(tree
,t1
) == 1) &&
134 (VEC_length(tree
,t2
) == 1) );
136 tree t1_tree
= VEC_index(tree
,t1
,0);
137 tree t2_tree
= VEC_index(tree
,t2
,0);
141 case OP_BIN_ADDITION
:
142 op
= gpy_builtin_get_eval_expression_call( t1_tree
, t2_tree
, operation
);
146 fatal_error("unhandled symbol type <0x%x>!\n", operation
);
152 retval
= VEC_alloc(tree
,gc
,0);
153 VEC_safe_push(tree
,gc
,retval
,op
);