clib: new raw_alloc and register_static_object services
authorJean Privat <jean@pryen.org>
Mon, 17 Aug 2009 19:55:21 +0000 (15:55 -0400)
committerJean Privat <jean@pryen.org>
Mon, 17 Aug 2009 20:15:30 +0000 (16:15 -0400)
Currently, these services are very simples or noop.
However, alternatives GC can provide more complex ones.

Signed-off-by: Jean Privat <jean@pryen.org>

clib/nit_common.h
clib/nit_main.c
src/compiling/compiling_global.nit
src/compiling/compiling_icode.nit
src/syntax/icode_generation.nit

index 2d4f9df..8a7ca0c 100644 (file)
@@ -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;
index 24216f8..6169787 100644 (file)
@@ -23,6 +23,16 @@ enum gc_option { large, boehm } gc_option;
 #include <gc/gc.h>
 #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;
index 2a686f2..e878a30 100644 (file)
@@ -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
index e41e277..b996468 100644 (file)
@@ -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};")
index e63a2f9..f545cb5 100644 (file)
@@ -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}.")