From: Jean Privat Date: Mon, 17 Aug 2009 19:55:21 +0000 (-0400) Subject: clib: new raw_alloc and register_static_object services X-Git-Tag: v0.3~48 X-Git-Url: http://nitlanguage.org clib: new raw_alloc and register_static_object services Currently, these services are very simples or noop. However, alternatives GC can provide more complex ones. Signed-off-by: Jean Privat --- diff --git a/clib/nit_common.h b/clib/nit_common.h index 2d4f9df..8a7ca0c 100644 --- a/clib/nit_common.h +++ b/clib/nit_common.h @@ -116,7 +116,11 @@ extern bigint object_id_counter; #define VAL_ISA(e, c, i) (VAL2VFT((e))[(c)].cid == (cid_t)(i)) -void * alloc(size_t); +/* GC and memory management */ +void *alloc(size_t); /* allocate memory to store an object with an object header */ +void *raw_alloc(size_t); /* allocate raw memory to store a raw stram of byte */ +void register_static_object(val_t*); /* mark that something is a global or once object */ + extern val_t G_args; extern val_t G_stdin; extern val_t G_stdout; diff --git a/clib/nit_main.c b/clib/nit_main.c index 24216f8..6169787 100644 --- a/clib/nit_main.c +++ b/clib/nit_main.c @@ -23,6 +23,16 @@ enum gc_option { large, boehm } gc_option; #include #endif +void *raw_alloc(size_t s0) +{ + return alloc(s0); +} + +void register_static_object(val_t *o) +{ + return; +} + void *large_alloc(size_t s0) { static char * alloc_pos = NULL; diff --git a/src/compiling/compiling_global.nit b/src/compiling/compiling_global.nit index 2a686f2..e878a30 100644 --- a/src/compiling/compiling_global.nit +++ b/src/compiling/compiling_global.nit @@ -463,6 +463,7 @@ redef class MMModule else var mainm = sys.select_method(name) v.add_instr("G_sys = NEW_Sys();") + v.add_instr("register_static_object(&G_sys);") v.add_instr("{mainm.cname}(G_sys);") end end diff --git a/src/compiling/compiling_icode.nit b/src/compiling/compiling_icode.nit index e41e277..b996468 100644 --- a/src/compiling/compiling_icode.nit +++ b/src/compiling/compiling_icode.nit @@ -701,6 +701,7 @@ redef class IOnce body.compile_to_c(v) var e = v.register(result.as(not null)) v.add_instr("once_value_{i} = {e};") + v.add_instr("register_static_object(&once_value_{i});") if res.stype.is_nullable then v.add_instr("once_bool_{i} = true;") v.unindent v.add_instr("} else {e} = once_value_{i};") diff --git a/src/syntax/icode_generation.nit b/src/syntax/icode_generation.nit index e63a2f9..f545cb5 100644 --- a/src/syntax/icode_generation.nit +++ b/src/syntax/icode_generation.nit @@ -586,7 +586,7 @@ redef class AInternMethPropdef s = "NEW_NativeArray(UNTAG_Int(@@@), sizeof(val_t))" else if n == once "calloc_string".to_symbol then p[0] = p[1] - s = "BOX_NativeString((char*)malloc((UNTAG_Int(@@@) * sizeof(char))))" + s = "BOX_NativeString((char*)raw_alloc((UNTAG_Int(@@@) * sizeof(char))))" end if s == null then v.visitor.error(self, "Fatal error: unknown intern method {method.full_name}.")