diff options
author | redbrain <redbrain@crules.org> | 2010-08-10 04:17:18 +0100 |
---|---|---|
committer | redbrain <redbrain@crules.org> | 2010-08-10 04:17:18 +0100 |
commit | 3c99b5702f07dbbb06a1ca3223de2bf114826c26 (patch) | |
tree | 071bcf1794a19f89f9a75f191ab98133fcf77420 | |
parent | 79f84bd447e7fe25f84b3182d51f2ec0e44b3abe (diff) | |
download | gcc-3c99b5702f07dbbb06a1ca3223de2bf114826c26.tar.gz |
more garbage collection code
-rw-r--r-- | gcc/python/expression.c | 14 | ||||
-rw-r--r-- | gcc/python/py_builtins.c | 38 | ||||
-rw-r--r-- | gcc/python/pypy.c | 30 | ||||
-rw-r--r-- | gcc/python/runtime.h | 2 | ||||
-rw-r--r-- | libgpython/runtime/obj_integer.c | 16 | ||||
-rw-r--r-- | libgpython/runtime/py_runtime.c | 20 |
6 files changed, 113 insertions, 7 deletions
diff --git a/gcc/python/expression.c b/gcc/python/expression.c index 37d5b62e627..5944ce99c4b 100644 --- a/gcc/python/expression.c +++ b/gcc/python/expression.c @@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "gpy.h" #include "symbols.h" #include "opcodes.def" -#include "y.py.h" +#include "runtime.h" tree gpy_process_assign( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b, tree * block) @@ -75,7 +75,17 @@ tree gpy_process_assign( gpy_symbol_obj ** op_a, gpy_symbol_obj ** op_b, } rhs_tree = gpy_process_expression( opb, block ); - retval = build2( MODIFY_EXPR, ptr_type_node, decl, rhs_tree ); + + tree address = build_decl( opa->loc, VAR_DECL, + create_tmp_var_name("A"), + build_pointer_type( void_type_node ) ); + + append_to_statement_list( build2( MODIFY_EXPR, ptr_type_node, address, rhs_tree ), + block ); + + append_to_statement_list( gpy_builtin_get_incr_ref_call( address ), block ); + + retval = build2( MODIFY_EXPR, ptr_type_node, decl, address ); } else fatal_error("Invalid accessor for assignment <0x%x>!\n", opa->type ); diff --git a/gcc/python/py_builtins.c b/gcc/python/py_builtins.c index 2a880246130..6b1dbe648a4 100644 --- a/gcc/python/py_builtins.c +++ b/gcc/python/py_builtins.c @@ -248,6 +248,44 @@ tree gpy_builtin_get_print_call( int n, tree * args ) ); } +tree gpy_builtin_get_finalize_block_call( int n, tree * args ) +{ + tree params = NULL_TREE; + + chainon( params, tree_cons (NULL_TREE, integer_type_node, NULL_TREE) ); + chainon( params, tree_cons (NULL_TREE, va_list_type_node, NULL_TREE) ); + chainon( params, tree_cons (NULL_TREE, void_type_node, NULL_TREE) ); + + tree fntype = build_function_type( ptr_type_node, params ); + tree gpy_finalize_block_decl = build_decl( UNKNOWN_LOCATION, FUNCTION_DECL, + get_identifier("gpy_rr_finalize_block_decls"), + fntype ); + + tree restype = TREE_TYPE( gpy_finalize_block_decl ); + tree resdecl = build_decl( UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, + restype ); + + DECL_CONTEXT( resdecl ) = gpy_finalize_block_decl; + DECL_RESULT( gpy_finalize_block_decl ) = resdecl; + DECL_EXTERNAL( gpy_finalize_block_decl ) = 1; + TREE_PUBLIC( gpy_finalize_block_decl ) = 1; + + tree * vec = XNEWVEC( tree, n+1 ); + + vec[0] = build_int_cst( integer_type_node, n ); + + int idx = 1, idy = 0; + for( ; idy<n; ++idy ) + { + vec[idx] = args[idy]; + idx++; + } + + return ( build_call_expr_loc_array( UNKNOWN_LOCATION, gpy_finalize_block_decl, + n+1, vec ) + ); +} + tree gpy_builtin_get_eval_accessor_call( tree t1, tree t2 ) { fatal_error("Accessor's not implemented yet!\n"); diff --git a/gcc/python/pypy.c b/gcc/python/pypy.c index d9ec23a7deb..cfa4052a646 100644 --- a/gcc/python/pypy.c +++ b/gcc/python/pypy.c @@ -504,7 +504,7 @@ tree gpy_process_print( gpy_symbol_obj *sym ) t = t->next; } - return ( gpy_builtin_get_print_call( len, args) ); + return ( gpy_builtin_get_print_call( len, args ) ); } else error("print call without any arguments!\n"); @@ -523,6 +523,7 @@ tree gpy_get_tree( gpy_symbol_obj * sym, tree * block ) { sym = gpy_process_AST_Align( &sym ); /*sym = gpy_process_AST_Split_Asigns( &sym );*/ + retval_decl = gpy_process_expression( sym, block ); } else @@ -600,7 +601,7 @@ void gpy_write_globals( void ) for( idx= 0; VEC_iterate(gpy_sym,gpy_decls,idx,it); ++idx ) { - tree x = gpy_get_tree( it , NULL ); + tree x = gpy_get_tree( it , &main_stmts ); gpy_preserve_from_gc( x ); gcc_assert( x ); @@ -615,8 +616,7 @@ void gpy_write_globals( void ) } } - append_to_statement_list( gpy_builtin_get_cleanup_final_call( ), &main_stmts ); - + int block_decl_len = 0; gpy_ident vit = NULL; for( idx = 0; VEC_iterate( gpy_ident,co->var_decl_t, idx, vit ); ++idx ) { @@ -627,8 +627,30 @@ void gpy_write_globals( void ) vit->ident, "main" ); TREE_CHAIN( x ) = declare_vars; declare_vars = x; + block_decl_len++; } + if( block_decl_len > 0 ) + { + tree * block_decl_vec = XNEWVEC( tree, block_decl_len ); + int idy = 0; + + for( idx = 0; VEC_iterate( gpy_ident,co->var_decl_t, idx, vit ); ++idx ) + { + tree x = gpy_ctx_lookup_decl( vit->ident, VAR ); + gcc_assert( TREE_CODE( x ) == VAR_DECL ); + + block_decl_vec[ idy ] = x; + idy++; + } + + append_to_statement_list( gpy_builtin_get_finalize_block_call( block_decl_len, + block_decl_vec ), + &main_stmts ); + } + + append_to_statement_list( gpy_builtin_get_cleanup_final_call( ), &main_stmts ); + tree main_set_ret = build2( MODIFY_EXPR, TREE_TYPE(main_ret), main_ret, build_int_cst(integer_type_node, 0)); TREE_USED(main_set_ret) = true; diff --git a/gcc/python/runtime.h b/gcc/python/runtime.h index f0e02935320..b1bbbbba420 100644 --- a/gcc/python/runtime.h +++ b/gcc/python/runtime.h @@ -35,6 +35,8 @@ extern tree gpy_builtin_get_decr_ref_call( tree ); extern tree gpy_builtin_get_print_call( int , tree * ); +extern tree gpy_builtin_get_finalize_block_call( int , tree * ); + extern tree gpy_builtin_get_eval_expression_call( tree , tree , gpy_opcode_t ); #endif /* __RUNTIME_H__ */ diff --git a/libgpython/runtime/obj_integer.c b/libgpython/runtime/obj_integer.c index 3ac183abba5..96bba0ecf94 100644 --- a/libgpython/runtime/obj_integer.c +++ b/libgpython/runtime/obj_integer.c @@ -35,6 +35,14 @@ struct gpy_obj_integer_t { int Int; }; + +/* Represents a function __init__ of a class: + + class foo: + + def __init__( self, ... ): + <.....> +*/ void * gpy_obj_integer_init( gpy_literal_t * lit ) { struct gpy_obj_integer_t *retval = (struct gpy_obj_integer_t *) @@ -120,6 +128,10 @@ gpy_obj_integer_add( gpy_object_state_t * o1, gpy_object_state_t * o2 ) return retval; } +/* + The member methods table + - member fields can be handle'd in a similar fashion +*/ static gpy_method_def_t gpy_obj_integer_methods[] = { { "whoop_noargs", (gpy_builtin_callback__) &gpy_obj_integer_whoop_noargs, METH_NOARGS }, @@ -130,6 +142,7 @@ static gpy_method_def_t gpy_obj_integer_methods[] = { { NULL, NULL, 0 } }; +/* The binary protocol handles */ static struct gpy_number_prot_t integer_binary_ops = { true, &gpy_obj_integer_add, @@ -157,6 +170,9 @@ static struct gpy_type_obj_def_t integer_obj = { gpy_obj_integer_methods }; +/* + Should be used for handling any Field initilizers! +*/ void gpy_obj_integer_mod_init( gpy_vector_t * const vec ) { gpy_vec_push( vec, &integer_obj ); diff --git a/libgpython/runtime/py_runtime.c b/libgpython/runtime/py_runtime.c index 97a2bd8ee96..b77943c5eef 100644 --- a/libgpython/runtime/py_runtime.c +++ b/libgpython/runtime/py_runtime.c @@ -186,6 +186,24 @@ void gpy_rr_pop_context( void ) gpy_free( popd ); } +void gpy_rr_finalize_block_decls( int n, ... ) +{ + va_list vl; int idx; + va_start( vl,n ); + + /* gpy_object_t is a typedef of gpy_object_state_t * + to keep stdarg.h happy + */ + gpy_object_state_t * it = NULL; + for( idx = 0; idx<n; ++idx ) + { + it = va_arg( vl, gpy_object_t ); + /* no assert this macro auto inserts an assert */ + Gpy_Decr_Ref( it ); + } + va_end(vl); +} + gpy_object_state_t * gpy_rr_eval_dot_operator( gpy_object_state_t * x, gpy_object_state_t * y ) { @@ -210,7 +228,7 @@ gpy_rr_eval_expression( gpy_object_state_t * x, gpy_object_state_t * y, { case OP_BIN_ADDITION: o = binops_l.n_add; - op_str = " + "; + op_str = "+ "; break; default: |