[SCM] Lisaac compiler branch, mildred-backend, updated. lisaac-0.12-434-g3ee9ebf

Mildred Ki'Lya silkensedai at online.fr
Fri Aug 7 12:08:55 UTC 2009


The following commit has been merged in the mildred-backend branch:
commit 700b339a6cd9b42b366e3d832ca9d18f4ce260c9
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date:   Fri Aug 7 02:11:18 2009 +0200

    Moved many things in the backend [MAY NOT WORK - C CODE DISTURBED]

diff --git a/lib2_os/java/system/system.li b/lib2_os/java/system/system.li
index 555d65e..eb6dce1 100644
--- a/lib2_os/java/system/system.li
+++ b/lib2_os/java/system/system.li
@@ -75,7 +75,7 @@ Section SYSTEM,MEMORY
     0
   );
   
-Section ISAAC  
+Section /*ISAAC  */ Public
   
   - make <-
   // Isaac compatibility.
diff --git a/src/any.li b/src/any.li
index f3d8f00..e733e77 100644
--- a/src/any.li
+++ b/src/any.li
@@ -214,22 +214,7 @@ Section Public
   - output_code:STRING := STRING.create 4000000;
   
   - title txt:STRING_CONSTANT in buf:STRING <-
-  (
-    buf.append "\n//";
-    3.to 28 do { j:INTEGER;
-      buf.add_last '=';      
-    };
-    buf.append "//\n// ";
-    buf.append txt;
-    (txt.count+5).to 28 do { j:INTEGER;
-      buf.add_last ' ';
-    };
-    buf.append " //\n//";
-    3.to 28 do { j:INTEGER;
-      buf.add_last '=';      
-    };
-    buf.append "//\n\n";
-  );
+    backend.generate_title txt in buf;
   
   
   - indent:STRING := STRING.create 128;
diff --git a/src/code_life/push.li b/src/code_life/push.li
index fb46758..107ea18 100644
--- a/src/code_life/push.li
+++ b/src/code_life/push.li
@@ -32,7 +32,7 @@ Section Inherit
   
   + parent_instr:Expanded INSTR;
   
-Section PUSH,LISAAC
+Section PUSH,LISAAC,BACKEND
   
   - source_line:HASHED_DICTIONARY[STRING,UINTEGER_32] := 
   HASHED_DICTIONARY[STRING,UINTEGER_32].create;
diff --git a/src/code_life/read_slot.li b/src/code_life/read_slot.li
index e67deb9..2072706 100644
--- a/src/code_life/read_slot.li
+++ b/src/code_life/read_slot.li
@@ -110,44 +110,8 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  ( + tf:TYPE_FULL;
-    + t:TYPE;
-    
-    (is_java).if {
-      receiver.genere buffer;
-      buffer.add_last '.';
-      buffer.append (variable.intern_name);
-    } else {    
-      (slot.intern_name = ALIAS_STR.slot_self).if {
-        buffer.append "((";
-        tf := slot.type;
-        tf.genere_declaration buffer;	
-        buffer.add_last ' ';
-        tf.genere_star_declaration buffer;	
-        buffer.add_last ')';
-        receiver.genere buffer;
-        buffer.append ".self)";
-      } else {
-        tf := receiver.static_type;    
-        ((tf.is_strict) || {tf.is_expanded_ref}).if {
-          receiver.genere buffer;
-          buffer.append "->";
-        }.elseif {tf.is_expanded} then {      
-          receiver.genere buffer;
-          buffer.add_last '.';          
-        } else {          
-          buffer.append "((";
-          t := slot.receiver_type;
-          t.put_reference_declaration buffer;	
-          buffer.add_last ' ';
-          t.put_reference_star_declaration buffer;	
-          buffer.add_last ')';
-          receiver.genere buffer;
-          buffer.append ")->";
-        };
-        buffer.append (variable.intern_name);
-      };    
-    };
+  (
+    backend.generate_read_slot_for Self in buffer;
   );
   
   //
diff --git a/src/code_life/write.li b/src/code_life/write.li
index b5125dd..74dc53d 100644
--- a/src/code_life/write.li
+++ b/src/code_life/write.li
@@ -196,7 +196,7 @@ Section Public
   ( + loc:LOCAL;
     + slo:SLOT;
     
-    (is_local).if { // BSBS: Pour finir, il faut spécialiser les READ, WRITE avec multiheritage
+    (is_local).if { // BSBS: Pour finir, il faut sp�cialiser les READ, WRITE avec multiheritage
       loc ?= variable;
       add_var_size loc;
     } else {
@@ -204,37 +204,13 @@ Section Public
       slo.receiver_type.add_genere_list;
     };
     (quiet_generation).if_false {
-      genere_access buffer;
-      buffer.add_last '=';    
-      genere_value buffer;
+      backend.generate_write_for Self in buffer;
     };
   );
   
   - genere_value buffer:STRING <-
-  (            
-    (is_java).if {
-      value.genere buffer;    
-    } else {    
-      (
-        (static_type.is_expanded_ref) && 
-        {! value.static_type.is_expanded_ref}
-      ).if {
-        ? {value.static_type.is_expanded};
-        buffer.append "&(";
-        value.genere buffer;    
-        buffer.add_last ')';
-      }.elseif {
-        (static_type.is_expanded) && {! static_type.is_expanded_ref} &&
-        {(! value.static_type.is_expanded) || {value.static_type.is_expanded_ref}} &&
-        {value.static_type.raw != TYPE_NULL} // For Pointer := NULL
-      } then {
-        buffer.append "*(";
-        value.genere buffer;    
-        buffer.add_last ')';
-      } else {
-        value.genere buffer;
-      };
-    };
+  (
+    backend.generate_write_value_for Self in buffer;
   );
     
   //
diff --git a/src/code_life/write_slot.li b/src/code_life/write_slot.li
index f77f6d9..e136b83 100644
--- a/src/code_life/write_slot.li
+++ b/src/code_life/write_slot.li
@@ -98,43 +98,10 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  ( + tf:TYPE_FULL;
-    + t:TYPE;
-                   
+  (
     slot.receiver_type.add_genere_list;    
     (quiet_generation).if_false {
-      // Receiver.
-      (is_java).if {
-        receiver.genere buffer;
-        buffer.add_last '.';          
-      } else {
-        tf := receiver.static_type;    
-        ((tf.is_strict) || {tf.is_expanded_ref}).if {
-          receiver.genere buffer;
-          buffer.append "->";
-        }.elseif {tf.is_expanded} then {      
-          receiver.genere buffer;
-          buffer.add_last '.';          
-        } else {
-          buffer.append "((";
-          t := slot.receiver_type;
-          t.put_reference_declaration buffer;	
-          buffer.add_last ' ';
-          t.put_reference_star_declaration buffer;	
-          buffer.add_last ')';
-          receiver.genere buffer;
-          buffer.append ")->";          
-        };
-      };
-      //
-      buffer.append (variable.intern_name);
-      //
-      ((value.static_type.raw = TYPE_NULL) && {variable.type.raw.is_block}).if {
-        buffer.append ".__id=0";
-      } else {
-        buffer.add_last '=';    
-        genere_value buffer;
-      };
+      backend.generate_write_slot_for Self in buffer;
     };
   );
   
diff --git a/src/constant/string_cst.li b/src/constant/string_cst.li
index d62cfeb..5f2bd28 100644
--- a/src/constant/string_cst.li
+++ b/src/constant/string_cst.li
@@ -34,15 +34,8 @@ Section Inherit
   
 Section Public
    
-  - output:STRING := 
-  ( + result:STRING;
-    
-    result := STRING.create 256;
-    title "STRING CONSTANT" in result;
-    result
-  );
-  
-  - output_count:INTEGER;
+  - output:STRING <- backend.string_constant_declaration;
+  - output_count:INTEGER <- backend.string_constant_count;
   
   //
   // Value.
@@ -86,93 +79,8 @@ Section Public
   //
 
   - genere buffer:STRING <-
-  ( + idx,count,cur:INTEGER;
-//     + count_esc:INTEGER;
-//     + esc_octal:BOOLEAN;
-//     + esc_hexa :BOOLEAN;
-    - is_init:BOOLEAN;
-    - is_storage:BOOLEAN;
-    - is_count:BOOLEAN;
-    
-    (is_init).if_false {
-      is_storage := type_string_constant.get_local_slot (ALIAS_STR.slot_storage)
-      .slot_data_intern.ensure_count != 0;
-      is_count   := type_string_constant.get_local_slot (ALIAS_STR.slot_count)
-      .slot_data_intern.ensure_count != 0;      
-      is_init := TRUE;
-    };
-    
-    count := dico_string.fast_at string;
-    (count >= 0).if {
-      output_count := output_count + 1;
-      idx := output_count;
-      
-      cur := output.count - 1;
-      (is_java).if {
-        output.append "private static ";
-      };
-      output.append "__";
-      output.append (type_string_constant.intern_name);
-      ((output.count - cur) >= 78).if {
-        output.add_last '\n';
-        cur := output.count - 1;
-      } else {
-        output.add_last ' ';
-      };
-      output.append "__string_";
-      idx.append_in output;
-      output.add_last '=';
-      (is_java).if {
-        output.append "new __STRING_CONSTANT(";
-      } else {
-        output.add_last '{';
-        (static_type.is_late_binding).if {
-          output.append "__";
-          output.append (static_type.raw.intern_name);
-          output.append "__,";	
-        };
-      };
-      (is_count).if {
-        count.append_in output;
-        output.add_last ',';
-      };
-      (is_storage).if {
-        ((output.count - cur) >= 78).if {
-          output.add_last '\n';
-          cur := output.count - 1;
-        };
-	output.add_last '\"';
-//         output.append string;
-//         {(output.count - cur) > 78}.while_do {
-//           output.insert_string "\\\n" to (cur+78);
-//           cur := cur + 78;
-//         };
-        backend.append_escaped_string string
-                in                    output
-                split_every           78
-                starting              (output.count - cur);
-	output.add_last '\"';
-      } else {
-        output.remove_last 1;
-      };
-      (is_java).if {
-        output.append ");\n";
-      } else {
-        output.append "};\n";
-      };
-      dico_string.fast_put (-idx) to string;
-    } else {
-      idx := -count;
-    };
-    //
-    (is_java).if {
-      buffer.append "__string_";
-      idx.append_in buffer;      
-    } else {
-      buffer.append "(&__string_";
-      idx.append_in buffer;
-      buffer.add_last ')';
-    };
+  (
+    backend.generate_string_constant Self in buffer;
   );
   
   //
@@ -182,7 +90,7 @@ Section Public
   - display buffer:STRING <- BACKEND_C.append_string string in buffer;
 
   
-Section Private  
+Section BACKEND  
   
   - dico_string:HASHED_DICTIONARY[INTEGER,STRING_CONSTANT] := 
   HASHED_DICTIONARY[INTEGER,STRING_CONSTANT].create;
diff --git a/src/lisaac.li b/src/lisaac.li
index 0437fd2..39da519 100644
--- a/src/lisaac.li
+++ b/src/lisaac.li
@@ -286,12 +286,9 @@ Section Private
       display_usage;
     };
     string_tmp.copy input_name;
-    (is_java).if {
-      string_tmp.append ".java";
-    } else {
-      string_tmp.append ".c";
-    };    
-    output_name := ALIAS_STR.get string_tmp;    
+    string_tmp.append (backend.source_extension);
+    output_name := ALIAS_STR.get string_tmp;
+    // TODO: Mildred: get output_name from lip
   );
   
   - last_index (n:STRING,c:CHARACTER) :INTEGER <-
@@ -365,198 +362,6 @@ Section Private
     project.put_string path_lisaac to (ALIAS_STR.variable_lisaac);
     project.call_init NULL;
   );
-
-  - put_trace_code buf:STRING <-
-  ( + proto:PROTOTYPE;
-    
-    ((debug_level_option != 0) || {CALL_NULL.is_necessary}).if {
-      title "DEBUG MANAGER" in buf;
-      
-      (is_java).if {
-        buf.append 
-        "private static void print_string(String str) \n\
-        \{ \n\
-        \  System.out.print(str);\n\
-        \}\n\
-        \\n";
-      } else {
-        buf.append 
-        "void print_string(char *str) \n\
-        \{ \n\
-        \  while (*str!=0) {\n\
-        \    print_char(*str); \n\
-        \    str++; \n\
-        \  };\n\
-        \}\n\
-        \\n";
-      };
-    };
-
-    (debug_level_option != 0).if {
-      buf.append "char *trace[";
-      buf.append (PROTOTYPE.prototype_list.count.to_string);
-      buf.append "]={\n";
-      (PROTOTYPE.prototype_list.lower).to (PROTOTYPE.prototype_list.upper-1) do { 
-	j:INTEGER;
-	proto := PROTOTYPE.prototype_list.item j;
-	buf.append "  \"";
-	buf.append (proto.name);
-	buf.append " (";
-	buf.append (proto.filename);
-	buf.append ")\",\n";
-      };
-      proto := PROTOTYPE.prototype_list.last;
-      buf.append "  \"";
-      buf.append (proto.name);
-      buf.append " (";
-      buf.append (proto.filename);
-      buf.append ")\"\n};\n\n";
-
-      //
-      // Source Code.
-      //
-            
-      (debug_with_code).if {
-	+ src:HASHED_DICTIONARY[STRING,UINTEGER_32];
-	+ key:UINTEGER_32;
-	
-	output_decl.append 
-	"\n//==========================//\n\
-	\// SOURCE LINE REFERENCE    //\n\
-	\//==========================//\n";
-	
-	buf.append 
-	"struct __source {\n\
-	\  unsigned int pos;\n\
-	\  char *line;\n\
-	\} __src[";
-	src := PUSH.source_line;
-	src.count.append_in buf;
-	buf.append "]={\n";		
-	(src.lower).to (src.upper) do { j:INTEGER;
-	  key := src.key j;
-	  output_decl.append "#define L";
-	  key.append_in output_decl;
-	  output_decl.add_last ' ';
-	  (j-1).append_in output_decl;
-	  output_decl.add_last '\n';
-	  //
-	  buf.append "  {";	 
-	  key.append_in buf;
-	  buf.append ",\"";
-	  buf.append (src.item j);
-	  buf.append "\"},\n";
-	};
-	buf.remove (buf.upper - 1);
-	buf.append "};\n\n";
-      };
-      
-      //
-      // Signal manager.
-      // 
-      
-      (is_ansi).if {
-	buf.append 
-	"// Unix Signal manager:\n\
-	\void interrupt_signal(int sig)  \n\
-	\{                               \n\
-	\  stack_print(top_context);     \n\
-	\  print_string(\"User interrupt.\\n\"); \n\
-	\  die_with_code(1);                     \n\
-	\}                                       \n\n";
-      };
-	
-      //
-      // Stack manager.
-      //
-      
-      buf.append 	
-      "void push_first(_____CONTEXT *path,unsigned long code)\n\
-      \{ \n";
-      (debug_level_option = 20).if {
-	buf.append 
-	"  _____CONTEXT *cur,loop;\n\
-	\  cur = top_context; \n\
-	\  while ((cur != (void *)0) && (cur != path)) cur = cur->back; \n\
-	\  if (cur == path) {\n\
-	\    loop.back = top_context;\n\	
-	\    loop.code = code; \n\
-	\    stack_print(&loop);\n\
-	\    print_string(\"COMPILER : Debug context looping detected !\\n\");\n\
-	\    die_with_code(1);\n\
-	\  };\n";
-      };
-      buf.append
-      "  path->back  = top_context;\n\
-      \  path->code  = code;\n\
-      \  top_context = path;\n\
-      \} \n\
-      \  \n\
-      \void push(_____CONTEXT *path,unsigned long code)\n\
-      \{ \n\      	
-      \  path->code  = code;\n\
-      \  top_context = path;\n\  
-      \} \n\
-      \  \n\
-      \void stack_print(_____CONTEXT *up)      \n\
-      \{ _____CONTEXT *back,*next;             \n\
-      \  int j;	                              \n\
-      \  next = (void *)0;                          \n\  
-      \  while (up != (void *)0) {                  \n\
-      \    back = up -> back;                       \n\
-      \    up -> back = next;                       \n\  
-      \    next = up;                               \n\
-      \    up = back;                               \n\
-      \  };                                         \n\
-      \  print_string(\"\\n============== BOTTOM ==============\\n\"); \n\
-      \  while (next != (void *)0) {                \n";
-      (debug_with_code).if {
-	buf.append
-	"    print_string(\"Line #\");                           \n\
-	\    print_integer(__src[next->code].pos >> 17);         \n\ 
-	\    print_string(\" Column #\");                        \n\
-	\    print_integer((__src[next->code].pos >> 9) & 0xFF); \n\ 
-	\    print_string(\" in \");                             \n\
-	\    print_string(trace[__src[next->code].pos & 0x1FF]); \n\
-	\    print_string(\".\\n\");                             \n\
-\ if ((__src[next->code].pos & 0x1FF) != 0) { \n\
-        \    print_string(__src[next->code].line);               \n\
-	\    print_char('\\n');                                  \n\
-	\    for (j=0;j < ((__src[next->code].pos >> 9) & 0xFF);j++) {\n\
-	\      if (__src[next->code].line[j]=='\\t') print_char('\\t');\n\
-        \      else print_char(' ');\n\
-        \    };                                                  \n\
-        \    print_char('^');    \n\
-	\    print_char('\\n');   \n\
-\ }; \n";	
-	
-      } else {    
-	buf.append
-	"    print_string(\"Line #\");                \n\
-	\    print_integer(next->code >> 17);         \n\
-	\    print_string(\" Column #\");          \n\
-	\    print_integer((next->code >> 9) & 0xFF); \n\ 
-	\    print_string(\" in \");               \n\
-	\    print_string(trace[next->code & 0x1FF]); \n\
-	\    print_string(\".\\n\");                  \n";
-      };
-      buf.append 
-      "    next = next -> back;                     \n\
-      \  };                                         \n\
-      \  print_string(\"================ TOP ===============\\n\"); \n\
-      \  top_context = (void *)0;                   \n\
-      \}                                            \n\
-      \ \n\
-      \void print_integer(unsigned short n) \n\
-      \{ unsigned short val;                \n\
-      \  char car;                          \n\	
-      \  car = (n % 10) + '0';              \n\
-      \  val = n / 10;                      \n\
-      \  if (val != 0) print_integer(val);  \n\
-      \  print_char(car);                   \n\
-      \} \n\n";
-    };
-  );
   
   - load_main_object <-
   ( + type_gen:FAST_ARRAY[ITM_TYPE_MONO];
@@ -629,7 +434,86 @@ Section Private
       STD_ERROR.put_string ")\n";
     };
   );
-  
+
+  - put_trace_code buf:STRING <-
+  (
+    ((debug_level_option != 0) || {CALL_NULL.is_necessary}).if {
+      title "DEBUG MANAGER" in buf;
+      backend.generate_debug_manager_in buf;
+    };
+    (debug_level_option != 0).if {
+      backend.generate_trace_declarations_in buf;
+      (debug_with_code).if {
+        backend.generate_trace_codedata_in buf declarations_in output_decl;
+      };
+      backend.generate_trace_code_in buf;
+    };
+  );
+
+  - compile <-
+  (
+    //
+    // File Header
+    //
+
+    output_decl.clear;
+    backend.append_init_code_in output_decl input_name input_name;
+    title "EXTERNAL" in output_decl;
+
+    //
+    // Load prototype and start compilation
+    //
+
+    load_main_object;
+    type_input.prototype.depend;
+
+    //
+    // Continue declarations
+    //
+
+    title "TYPE" in output_decl;
+    backend.generate_type_struct_for_generic_in output_decl;
+    title "GLOBAL" in output_glob;
+
+    //
+    // Declare functions ahead
+    //
+
+    title "FUNCTION HEADER" in output_code;     // Function header.
+    backend.append_debug_code_in output_code;   // Debug source code.
+    PROFIL_LIST.genere_handler output_code;     // Extern source code.
+
+    //
+    // Source Code: Main Function
+    //
+
+    title "SOURCE CODE" in output_code;         // Source code.
+    backend.append_main_function_in output_code;
+    indent.append "  ";
+    list_main.genere_extern output_code;
+    backend.append_main_return_code_in output_code;
+
+    //
+    // Other Functions
+    //
+
+    PROFIL_LIST.genere output_code;
+
+    //
+    // Finish type declaration
+    //
+
+    TYPE.genere_all_struct;
+    backend.generate_table_type_in output_decl;
+
+    //
+    // End of File
+    //
+
+    put_trace_code output_code; // Trace code
+    backend.append_end_of_file_in output_code;
+  );
+
 Section Public  
 
   //
@@ -640,17 +524,16 @@ Section Public
   ( + file_output:POINTER;
     //+ entry:ENTRY;
     + begin_time,end_time:UINTEGER_64;
-    + time:INTEGER;    
-    + txt:STRING;
+    + time:INTEGER;
     + s:LIP_SLOT_CODE;
 
     ALIAS_STR.make;
-    
     begin_time := SYSTEM.get_universal_time;
-    
+
     //
     // Load Environment. 
     //
+
     read_options;
     is_verbose.if {
       string_tmp.copy "\ninput  file : ";
@@ -665,139 +548,48 @@ Section Public
       };
       string_tmp.print;
     };
-    
-    //
-    // Header C 
-    //    
-    (is_java).if {
-      output_decl.copy "// Java code generated by Lisaac compiler (www.isaacOS.com) //\n";
-      output_decl.append "class ";      
-      output_decl.append input_name;
-      output_decl.append " {\n";
-      output_decl.append "private static String arg[];\n";
-    } else {
-      output_decl.copy "// C code generated by Lisaac compiler (www.isaacOS.com) //\n";
-      // ANSI argument command.
-      (debug_level_option != 0).if {
-        output_decl.append "#include <signal.h>\n";
-      };
-      output_decl.append 
-      "int arg_count;\n\
-      \char **arg_vector;\n";      
-    };    
-    
-    // External.
-    title "EXTERNAL" in output_decl;
+
 
     //
-    // Load prototype constant.
+    // Compile and generate buffers
     //
-    load_main_object;
-    
-    // Compilation.    
-    type_input.prototype.depend;    
-    
-    // Type / Struct.
-    title "TYPE" in output_decl;
-    
-    (is_java).if {
-      output_decl.append 
-      "// Generic Object\n\
-      \class ___OBJ {\n\
-      \  long __id;\n\
-      \};\n\n";          
-    } else {
-      output_decl.append 
-      "// Generic Object\n\
-      \struct ___OBJ {\n\
-      \  unsigned long __id;\n\
-      \};\n\n";          
-    };
-    title "GLOBAL" in output_glob;
-        
-    // Function header.
-    title "FUNCTION HEADER" in output_code;
-    
-    // Debug source code.
-    (is_java).if_false {
-      ((debug_level_option != 0) || {CALL_NULL.is_necessary}).if {
-        output_code.append "// Debug Manager\n"; 
-        output_code.append "void print_string(char *str);\n";
-      };
-      (debug_level_option != 0).if {      
-        (is_ansi).if {
-          output_code.append "void interrupt_signal(int sig);\n";
-        };
-        output_code.append 
-        "void stack_print(_____CONTEXT *up);\n\
-        \void push_first(_____CONTEXT *path,unsigned long code);\n\
-        \void push(_____CONTEXT *path,unsigned long code);\n\
-        \void print_integer(unsigned short n);\n";
-      };
-    };
-    
-    // Extern source code.
-    output_code.append "// Source code\n";
-    PROFIL_LIST.genere_handler output_code;
-    
-    // Source code.
-    title "SOURCE CODE" in output_code;        
-    
-    (is_java).if {
-      output_code.append "public static void main(String parg[])\n";
-    } else {
-      output_code.append "int main(int argc,char **argv)\n";
-    };
-    output_code.append "{\n";
-    indent.append "  ";
-        
-    list_main.genere_extern output_code;    
-        
-    (is_java).if_false {
-      output_code.append "  return(0);\n";
-    };
-    indent.remove_last 2;    
-    output_code.append indent;
-    output_code.append "}\n\n"; 
-        
-    PROFIL_LIST.genere output_code;
-        
-    TYPE.genere_all_struct;        
-    (is_java).if_false {
-      output_decl.append "\nvoid *table_type[";
-      TYPE.id_counter_without_type.append_in output_decl;
-      output_decl.append "];\n";
-    };
-        
-    // String Constant.
 
-    // Trace code.    
-    put_trace_code output_code;
-    
-    (is_java).if {
-      output_code.append "\n} // End class MAIN\n";
-    };
-    
+
+    compile;
+
+
     //
-    // Saving File Output.
-    //    
+    // Saving File Output (create file)
+    //
+
     (! FS_MIN.make_file output_name).if {
       STD_ERROR.put_string "Error: File ";
       STD_ERROR.put_string output_name;
       STD_ERROR.put_string " is not created !\n";
       die_with_code exit_failure_code;
     };
+    file_output := FS_MIN.open_write output_name;
 
-    file_output := FS_MIN.open_write output_name;    
-    FS_MIN.write file_output with output_decl size (output_decl.count);    
+    //
+    // Write Buffers
+    //   - output_decl
+    //   - output_glob
+    //   - output_STRING_CONSTANT
+    //   - output_code
+    //
+
+    FS_MIN.write file_output with output_decl size (output_decl.count);
     FS_MIN.write file_output with output_glob size (output_glob.count);
     (STRING_CST.output_count != 0).if {
-      txt := STRING_CST.output;
-      FS_MIN.write file_output with txt size (txt.count);
-    };    
+      FS_MIN.write file_output with (STRING_CST.output) size (STRING_CST.output.count);
+    };
     FS_MIN.write file_output with output_code size (output_code.count);
     FS_MIN.close file_output;
+
+    //
+    // Compute time spent
     //
+
     end_time := SYSTEM.get_universal_time;
     (is_quiet).if_false {
       STD_ERROR.put_string " => ";
@@ -816,7 +608,11 @@ Section Public
 	STD_ERROR.put_string " warning(s).\n";
       };
     };
-    
+
+    //
+    // Statistics
+    //
+
     (is_statistic).if {            
       print "  Null call score      : " stat null_counter for late_binding_counter;            
       print "  Polymorphic call     : " stat polymorphic_counter for late_binding_counter;
@@ -824,17 +620,17 @@ Section Public
 	"  Invariant loop score : ".print; count_invariant.print; '\n'.print;      
       };
     };
-        
+
     //
-    // Execute finality command (front end).
+    // Executing `back_end'
     //
-    // Executing `front_end':
+
     project.put_boolean is_cop to (ALIAS_STR.slot_is_cop);
     s := project.get_method (ALIAS_STR.slot_back_end);
     (s = NULL).if {
       "Warning: Slot `back_end' not found in *.lip file.\n".print;      
     } else {
       s.run_with NULL;
-    };    
+    };
   );
 
diff --git a/src/parser.li b/src/parser.li
index 5735af8..754b799 100644
--- a/src/parser.li
+++ b/src/parser.li
@@ -2358,101 +2358,7 @@ Section Private
             (is_java).if {
               semantic_error (current_position,"COP not yet implemented.");
             } else {
-              output_decl.append 
-              "#include <pthread.h>\n\
-              \#include <limits.h>\n\n\
-              \void print_char(char car);\n\
-              \int die_with_code(int code);\n\n\
-              \static pthread_key_t current_thread;\n\
-              \static pthread_attr_t thread_attr;\n\
-              \pthread_t c_thread;\n\
-              \int thread_counter;\n\n\              
-              \static char thread_stack[512][PTHREAD_STACK_MIN];\n\n\
-              \typedef struct lith_object_struct lith_object;\n\
-              \typedef struct lith_node_struct lith_node;\n\
-              \struct lith_node_struct {\n\
-                \  pthread_mutex_t mutex;\n\
-                \  lith_node *next;\n\
-                \  lith_object *object;\n\
-              \};\n\              
-              \struct lith_object_struct {\n\
-                \  unsigned long __id; // Just for late binding.\n\
-                \  lith_node *first;\n\
-                \  lith_node *last;\n\
-                \  lith_object *(*procedure)(lith_object *obj,pthread_mutex_t *mutex);\n\
-                \  pthread_mutex_t mutex;\n\
-              \};\n\
-              \struct {\n\
-                \  lith_node *first;\n\
-                \  pthread_mutex_t mutex;\n\
-              \} pool;\n\n\
-              \void *thread_life(void *ptr)\n\
-              \{ lith_node node,*n;\n\
-                \  lith_object *obj,*new_obj;\n\n\    
-                \  pthread_mutex_init(&node.mutex,NULL);\n\
-                \  pthread_mutex_lock(&node.mutex);\n\
-                \  node.object = (lith_object *)ptr;\n\
-                \  do {\n\
-                  \    // Append fifo object.\n\
-                  \    obj = node.object;\n\
-                  \    node.next = NULL;\n\
-                  \    n = obj->last;\n\
-                  \    if (n == NULL) {\n\
-                    \      obj->first = &node;\n\
-                    \      pthread_mutex_unlock(&node.mutex);\n\
-                  \    } else {\n\
-                    \      n->next = &node;\n\
-                  \    };\n\
-                  \    obj->last = &node;\n\
-                  \    pthread_setspecific(current_thread,(void *)obj);\n\
-                  \    // Run procedure.\n\
-                  \    new_obj = obj->procedure(obj,&node.mutex);\n\
-                  \    // Remove fifo object.\n\
-                  \    pthread_mutex_lock(&obj->mutex);\n\
-                  \    n = obj->first->next;\n\
-                  \    if (n != NULL) {\n\
-                    \      pthread_mutex_unlock(&n->mutex);\n\
-                  \    } else {\n\
-                    \      obj->last = NULL;\n\
-                  \    };\n\
-                  \    obj->first = n;\n\
-                  \    pthread_mutex_unlock(&obj->mutex);\n\
-                  \    if (new_obj != NULL) {\n\
-                    \      node.object = new_obj;\n\
-                  \    } else {\n\
-                    \      // Add in pool.\n\
-                    \      pthread_mutex_lock(&pool.mutex);\n\
-                    \      node.next = pool.first;\n\
-                    \      pool.first = &node;\n\
-                    \      pthread_mutex_unlock(&pool.mutex);\n\
-                    \      // Sleep.\n\
-                    \      pthread_mutex_lock(&node.mutex);\n\
-                  \    };\n\
-                \  } while (1);\n\
-                \  return NULL;\n\
-              \};\n\n\
-              \void run_procedure(lith_object *obj)\n\
-              \{ lith_node *node;\n\
-                \  char *msg=\"COP Error!\\n\";\n\
-                \  // Pool manager.\n\
-                \  pthread_mutex_lock(&pool.mutex);\n\
-                \  node = pool.first;\n\
-                \  if (node != NULL) {\n\
-                  \    pool.first = node->next;\n\
-                \  };\n\
-                \  pthread_mutex_unlock(&pool.mutex);\n\
-                \  // Run thread.\n\
-                \  if (node == NULL) {\n\                  
-                  \    pthread_attr_setstack(&thread_attr, thread_stack[thread_counter++],PTHREAD_STACK_MIN);\n\
-                  \    if ((thread_counter>512) || pthread_create(&c_thread,&thread_attr, thread_life, (void *)obj)) {\n\
-                    \      while (*msg != 0) print_char(*(msg++));\n\
-                    \      die_with_code(1);\n\
-                  \    };\n\
-                \  } else {\n\
-                  \    node->object = obj;\n\
-                  \    pthread_mutex_unlock(&node->mutex);\n\
-                \  };\n\
-              \};\n\n";
+              backend.append_cop_init_code_in output_decl;
             };
 	  };
 	  
diff --git a/src/tools/alias_str.li b/src/tools/alias_str.li
index b770e09..2d08764 100644
--- a/src/tools/alias_str.li
+++ b/src/tools/alias_str.li
@@ -188,6 +188,8 @@ Section Public
   - path_lisaac      :STRING_CONSTANT := "__PATH_LISAAC_SYSTEM__";
   - short_format     :STRING_CONSTANT := "__SHORT_LISAAC_FORMAT__";
 
+  - ext_c            :STRING_CONSTANT := ".c";
+  - ext_java         :STRING_CONSTANT := ".java";
   - path_current     :STRING_CONSTANT := ".";
   - make_lip         :STRING_CONSTANT := "make.lip";
 
@@ -488,6 +490,8 @@ Section Public
     list.add path_lisaac;
     list.add short_format;
     
+    list.add ext_c;
+    list.add ext_java;
     list.add path_current;
     list.add make_lip;
     
diff --git a/src/tools/backend.li b/src/tools/backend.li
index 5bd39c3..fb4b6a8 100644
--- a/src/tools/backend.li
+++ b/src/tools/backend.li
@@ -33,6 +33,8 @@ Section Inherit
 
 Section Public
 
+  - source_extension :STRING_CONSTANT <- (deferred; NULL);
+
   //
   // Names
   //
@@ -45,7 +47,7 @@ Section Public
 
   - append_type_name_for t:TYPE in buf:STRING <-
   (
-    buf.append "__";
+    buf.append (ALIAS_STR.separate);
     buf.append (t.intern_name);
   );
 
@@ -58,14 +60,14 @@ Section Public
   - append_type_proto_name_for t:TYPE in buf:STRING <-
   (
     buf.append (t.intern_name);
-    buf.append "__";
+    buf.append (ALIAS_STR.separate);
   );
 
   - append_type_typeid_name_for t:TYPE in buf:STRING <-
   (
-    buf.append "__";
+    buf.append (ALIAS_STR.separate);
     buf.append (t.intern_name);
-    buf.append "__";
+    buf.append (ALIAS_STR.separate);
   );
 
   //
@@ -76,9 +78,180 @@ Section Public
   - generate_type_struct_for  t:TYPE in buf:STRING <- deferred;
   - generate_type_globals_for t:TYPE in buf:STRING <- deferred;
 
-  - generate_type_struct_for_null_in buf:STRING    <- deferred;
+  - generate_type_struct_for_generic_in buf:STRING <- deferred;
+  - generate_type_struct_for_null_in    buf:STRING <- deferred;
   - generate_type_struct_for_context_in buf:STRING <- deferred;
 
+  - generate_type_reference_star_declaration_in buf:STRING <- deferred;
+  - generate_type_expanded_declaration_for t:TYPE in buf:STRING <- deferred;
+  - generate_type_generic_declaration_in buf:STRING <- deferred;
+  - generate_type_access_id_for_expr  e:EXPR in buf:STRING <- deferred;
+  - generate_type_access_id_for_block e:EXPR in buf:STRING <-
+  (
+    e.genere buf;
+    //buf.append ".__id";
+  );
+
+  //
+  // Read and Write
+  //
+
+  - generate_read_slot_for   read: READ_SLOT in buf:STRING <- deferred;
+  - generate_write_slot_for write:WRITE_SLOT in buf:STRING <- deferred;
+  - generate_write_for write:WRITE in buf:STRING <-
+  (
+    write.genere_access buf;
+    buf.add_last '=';
+    write.genere_value buf;
+  );
+  - generate_write_value_for write:WRITE in buf:STRING <-
+  (
+    write.value.genere buf;
+  );
+
+  //
+  // Misc Code
+  //
+
+  - append_null_value_in buf:STRING <- deferred;
+  - append_cop_init_code_in buf:STRING <- deferred;
+  - append_init_code_in buf:STRING input_name input_name:STRING_CONSTANT <- deferred;
+  - append_debug_code_in buf:STRING <- deferred;
+  - append_main_function_in buf:STRING <- deferred;
+  - append_main_init_code_in buf:STRING <- deferred;
+  - append_main_return_code_in buf:STRING <- deferred;
+  - append_end_of_file_in buf:STRING;
+
+  - generate_table_type_in buf:STRING <- deferred;
+  - generate_debug_manager_in buf:STRING <- deferred;
+  - generate_trace_declarations_in buf:STRING <- deferred;
+  - generate_trace_codedata_in buf:STRING declarations_in decl:STRING <- deferred;
+  - generate_trace_code_in buf:STRING <- deferred;
+
+  - generate_title txt:STRING_CONSTANT in buf:STRING <-
+  (
+    buf.append "\n//";
+    3.to 28 do { j:INTEGER;
+      buf.add_last '=';
+    };
+    buf.append "//\n// ";
+    buf.append txt;
+    (txt.count+5).to 28 do { j:INTEGER;
+      buf.add_last ' ';
+    };
+    buf.append " //\n//";
+    3.to 28 do { j:INTEGER;
+      buf.add_last '=';
+    };
+    buf.append "//\n\n";
+  );
+
+
+Section STRING_CST
+
+  //
+  // STRING_CONSTANT
+  //
+
+  - string_constant_declaration :STRING :=
+  ( + result:STRING;
+
+    result := STRING.create 256;
+    title "STRING CONSTANT" in result;
+    result
+  );
+
+  - string_constant_count :INTEGER;
+
+Section Public
+
+  - generate_string_constant s:STRING_CST in buffer:STRING <-
+  ( + idx,count,cur:INTEGER;
+    + output :STRING;
+    - is_init:BOOLEAN;
+    - is_storage:BOOLEAN;
+    - is_count:BOOLEAN;
+
+    output := string_constant_declaration;
+    // use a shorter name
+
+    (is_init).if_false {
+      is_storage := type_string_constant.get_local_slot (ALIAS_STR.slot_storage)
+                                        .slot_data_intern
+                                        .ensure_count != 0;
+      is_count   := type_string_constant.get_local_slot (ALIAS_STR.slot_count)
+                                        .slot_data_intern
+                                        .ensure_count != 0;
+      is_init := TRUE;
+    };
+
+    count := s.dico_string.fast_at (s.string);
+    (count >= 0).if {
+      string_constant_count := string_constant_count + 1;
+      idx := string_constant_count;
+
+      cur := output.count - 1;
+      (is_java).if {
+        output.append "private static ";
+      };
+      append_type_name_for type_string_constant in output;
+      ((output.count - cur) >= 78).if {
+        output.add_last '\n';
+        cur := output.count - 1;
+      } else {
+        output.add_last ' ';
+      };
+      output.append "__string_";
+      idx.append_in output;
+      output.add_last '=';
+      (is_java).if {
+        output.append "new ";
+        append_type_name_for type_string_constant in output;
+        output.add_last '(';
+      } else {
+        output.add_last '{';
+        (s.static_type.is_late_binding).if {
+          append_type_typeid_name_for (s.static_type.raw) in output;
+        };
+      };
+      (is_count).if {
+        count.append_in output;
+        output.add_last ',';
+      };
+      (is_storage).if {
+        ((output.count - cur) >= 78).if {
+          output.add_last '\n';
+          cur := output.count - 1;
+        };
+        output.add_last '\"';
+        append_escaped_string (s.string)
+          in                  output
+          split_every         78
+          starting            (output.count - cur);
+        output.add_last '\"';
+      } else {
+        output.remove_last 1;
+      };
+      (is_java).if {
+        output.append ");\n";
+      } else {
+        output.append "};\n";
+      };
+      s.dico_string.fast_put (-idx) to (s.string);
+    } else {
+      idx := -count;
+    };
+    //
+    (is_java).if {
+      buffer.append "__string_";
+      idx.append_in buffer;
+    } else {
+      buffer.append "(&__string_";
+      idx.append_in buffer;
+      buffer.add_last ')';
+    };
+  );
+
   //
   // String Constant
   //
diff --git a/src/tools/backend_c.li b/src/tools/backend_c.li
index 28373c1..ee855b9 100644
--- a/src/tools/backend_c.li
+++ b/src/tools/backend_c.li
@@ -33,6 +33,8 @@ Section Inherit
 
 Section Public
 
+  - source_extension :STRING_CONSTANT := ALIAS_STR.ext_c;
+
   - generate_type_typedef_for t:TYPE in buf:STRING <-
   (
     buf.append "typedef ";
@@ -46,6 +48,15 @@ Section Public
     buf.append ";\n";
   );
 
+  - generate_type_struct_for_generic_in buf:STRING <-
+  (
+    buf.append
+      "// Generic Object\n\
+      \struct ___OBJ {\n\
+      \  unsigned long __id;\n\
+      \};\n\n";
+  );
+
   - generate_type_struct_for_null_in buf:STRING <-
   (
     buf.append
@@ -210,5 +221,479 @@ Section Public
 
   );
 
+  - generate_type_reference_star_declaration_in buf:STRING <-
+  (
+    buf.add_last '*';
+  );
+
+  - generate_type_expanded_declaration_for t:TYPE in buf:STRING <-
+  (
+    append_type_name_for t in buf;
+  );
+
+  - generate_type_generic_declaration_in buf:STRING <-
+  (
+    buf.append (ALIAS_STR.c_void);
+  );
+
+
+  - generate_type_access_id_for_expr e:EXPR in buf:STRING <-
+  (
+    buf.append "((struct ___OBJ *)";
+    e.genere buf;
+    buf.append ")->__id";
+  );
+
+  - generate_read_slot_for read:READ_SLOT in buf:STRING <-
+  ( + tf:TYPE_FULL;
+    + t:TYPE;
+
+    (read.slot.intern_name = ALIAS_STR.slot_self).if {
+      // TODO: Mildred: WHAT IS THAT?
+      // If it's for BLOCKs only, why not test the type ?
+      buf.append "((";
+      tf := read.slot.type;
+      tf.genere_declaration buf;
+      buf.add_last ' ';
+      tf.genere_star_declaration buf;
+      buf.add_last ')';
+      read.receiver.genere buf;
+      buf.append ".self)";
+    } else {
+      tf := read.receiver.static_type;
+      ((tf.is_strict) || {tf.is_expanded_ref}).if {
+        read.receiver.genere buf;
+        buf.append "->";
+      }.elseif {tf.is_expanded} then {
+        read.receiver.genere buf;
+        buf.add_last '.';
+      } else {
+        buf.append "((";
+        t := read.slot.receiver_type;
+        t.put_reference_declaration buf;
+        buf.add_last ' ';
+        t.put_reference_star_declaration buf;
+        buf.add_last ')';
+        read.receiver.genere buf;
+        buf.append ")->";
+      };
+      buf.append (read.variable.intern_name);
+    };
+  );
+
+  - generate_write_slot_for write:WRITE_SLOT in buf:STRING <-
+  ( + tf:TYPE_FULL;
+    + t:TYPE;
+
+    // Receiver.
+    tf := write.receiver.static_type;
+    ((tf.is_strict) || {tf.is_expanded_ref}).if {
+      write.receiver.genere buf;
+      buf.append "->";
+    }.elseif {tf.is_expanded} then {
+      write.receiver.genere buf;
+      buf.add_last '.';
+    } else {
+      buf.append "((";
+      t := write.slot.receiver_type;
+      t.put_reference_declaration buf;
+      buf.add_last ' ';
+      t.put_reference_star_declaration buf;
+      buf.add_last ')';
+      write.receiver.genere buf;
+      buf.append ")->";
+    };
+    //
+    buf.append (write.variable.intern_name);
+    //
+    ((write.value.static_type.raw = TYPE_NULL) &&
+     {write.variable.type.raw.is_block}).if
+    {
+      buf.append ".__id=0";
+    } else {
+      buf.add_last '=';
+      write.genere_value buf;
+    };
+  );
+
+  - generate_write_value_for write:WRITE in buf:STRING <-
+  (
+    (
+      (write.static_type.is_expanded_ref) &&
+      {! write.value.static_type.is_expanded_ref}
+    ).if {
+      ? {write.value.static_type.is_expanded};
+      buf.append "&(";
+      write.value.genere buf;
+      buf.add_last ')';
+    }.elseif {
+      (  write.static_type.is_expanded              ) &&
+      {! write.static_type.is_expanded_ref          } &&
+      { (! write.value.static_type.is_expanded)  ||
+        {  write.value.static_type.is_expanded_ref} } &&
+      {  write.value.static_type.raw != TYPE_NULL   } // For Pointer := NULL
+    } then {
+      buf.append "*(";
+      write.value.genere buf;
+      buf.add_last ')';
+    } else {
+      write.value.genere buf;
+    };
+  );
+
+
+
+  - append_null_value_in buf:STRING <-
+  (
+    buf.append "NULL";
+  );
+
+
+  - append_cop_init_code_in buf:STRING <-
+  (
+    buf.append
+              "#include <pthread.h>\n\
+              \#include <limits.h>\n\n\
+              \void print_char(char car);\n\
+              \int die_with_code(int code);\n\n\
+              \static pthread_key_t current_thread;\n\
+              \static pthread_attr_t thread_attr;\n\
+              \pthread_t c_thread;\n\
+              \int thread_counter;\n\n\
+              \static char thread_stack[512][PTHREAD_STACK_MIN];\n\n\
+              \typedef struct lith_object_struct lith_object;\n\
+              \typedef struct lith_node_struct lith_node;\n\
+              \struct lith_node_struct {\n\
+                \  pthread_mutex_t mutex;\n\
+                \  lith_node *next;\n\
+                \  lith_object *object;\n\
+              \};\n\
+              \struct lith_object_struct {\n\
+                \  unsigned long __id; // Just for late binding.\n\
+                \  lith_node *first;\n\
+                \  lith_node *last;\n\
+                \  lith_object *(*procedure)(lith_object *obj,pthread_mutex_t *mutex);\n\
+                \  pthread_mutex_t mutex;\n\
+              \};\n\
+              \struct {\n\
+                \  lith_node *first;\n\
+                \  pthread_mutex_t mutex;\n\
+              \} pool;\n\n\
+              \void *thread_life(void *ptr)\n\
+              \{ lith_node node,*n;\n\
+                \  lith_object *obj,*new_obj;\n\n\
+                \  pthread_mutex_init(&node.mutex,NULL);\n\
+                \  pthread_mutex_lock(&node.mutex);\n\
+                \  node.object = (lith_object *)ptr;\n\
+                \  do {\n\
+                  \    // Append fifo object.\n\
+                  \    obj = node.object;\n\
+                  \    node.next = NULL;\n\
+                  \    n = obj->last;\n\
+                  \    if (n == NULL) {\n\
+                    \      obj->first = &node;\n\
+                    \      pthread_mutex_unlock(&node.mutex);\n\
+                  \    } else {\n\
+                    \      n->next = &node;\n\
+                  \    };\n\
+                  \    obj->last = &node;\n\
+                  \    pthread_setspecific(current_thread,(void *)obj);\n\
+                  \    // Run procedure.\n\
+                  \    new_obj = obj->procedure(obj,&node.mutex);\n\
+                  \    // Remove fifo object.\n\
+                  \    pthread_mutex_lock(&obj->mutex);\n\
+                  \    n = obj->first->next;\n\
+                  \    if (n != NULL) {\n\
+                    \      pthread_mutex_unlock(&n->mutex);\n\
+                  \    } else {\n\
+                    \      obj->last = NULL;\n\
+                  \    };\n\
+                  \    obj->first = n;\n\
+                  \    pthread_mutex_unlock(&obj->mutex);\n\
+                  \    if (new_obj != NULL) {\n\
+                    \      node.object = new_obj;\n\
+                  \    } else {\n\
+                    \      // Add in pool.\n\
+                    \      pthread_mutex_lock(&pool.mutex);\n\
+                    \      node.next = pool.first;\n\
+                    \      pool.first = &node;\n\
+                    \      pthread_mutex_unlock(&pool.mutex);\n\
+                    \      // Sleep.\n\
+                    \      pthread_mutex_lock(&node.mutex);\n\
+                  \    };\n\
+                \  } while (1);\n\
+                \  return NULL;\n\
+              \};\n\n\
+              \void run_procedure(lith_object *obj)\n\
+              \{ lith_node *node;\n\
+                \  char *msg=\"COP Error!\\n\";\n\
+                \  // Pool manager.\n\
+                \  pthread_mutex_lock(&pool.mutex);\n\
+                \  node = pool.first;\n\
+                \  if (node != NULL) {\n\
+                  \    pool.first = node->next;\n\
+                \  };\n\
+                \  pthread_mutex_unlock(&pool.mutex);\n\
+                \  // Run thread.\n\
+                \  if (node == NULL) {\n\
+                  \    pthread_attr_setstack(&thread_attr, thread_stack[thread_counter++],PTHREAD_STACK_MIN);\n\
+                  \    if ((thread_counter>512) || pthread_create(&c_thread,&thread_attr, thread_life, (void *)obj)) {\n\
+                    \      while (*msg != 0) print_char(*(msg++));\n\
+                    \      die_with_code(1);\n\
+                  \    };\n\
+                \  } else {\n\
+                  \    node->object = obj;\n\
+                  \    pthread_mutex_unlock(&node->mutex);\n\
+                \  };\n\
+              \};\n\n";
+  );
+
+  - append_init_code_in buf:STRING input_name input_name:STRING_CONSTANT <-
+  (
+    buf.append "// C code generated by Lisaac compiler (www.isaacOS.com) //\n";
+    // ANSI argument command.
+    (debug_level_option != 0).if {
+      buf.append "#include <signal.h>\n";
+    };
+    buf.append
+      "int arg_count;\n\
+      \char **arg_vector;\n";
+  );
+
+  - append_debug_code_in buf:STRING <-
+  (
+    ((debug_level_option != 0) || {CALL_NULL.is_necessary}).if {
+      buf.append "// Debug Manager\n";
+      buf.append "void print_string(char *str);\n";
+    };
+    (debug_level_option != 0).if {
+      (is_ansi).if {
+        buf.append "void interrupt_signal(int sig);\n";
+      };
+      buf.append
+        "void stack_print(_____CONTEXT *up);\n\
+        \void push_first(_____CONTEXT *path,unsigned long code);\n\
+        \void push(_____CONTEXT *path,unsigned long code);\n\
+        \void print_integer(unsigned short n);\n";
+    };
+  );
+
+  - append_main_function_in buf:STRING <-
+  (
+    buf.append "int main(int argc,char **argv)\n";
+    buf.append "{\n";
+  );
+
+  - append_main_init_code_in buf:STRING <-
+  (
+    (debug_level_option != 0).if {
+      buf.append "signal(SIGINT,interrupt_signal);\n  ";
+    };
+    buf.append
+      "arg_count  = argc;\n\
+      \  arg_vector = argv;\n\
+      \#ifdef _PTHREAD_H\n\
+      \  pthread_key_create(&current_thread, NULL);\n\
+      \  pthread_attr_init(&thread_attr);\n\
+      \  /*pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);*/\n\
+      \#endif\n  ";
+  );
+
+  - append_main_return_code_in buf:STRING <-
+  (
+    buf.append "  return 0;\n";
+    indent.remove_last 2;
+    buf.append indent;
+    buf.append "}\n\n";
+  );
+
+  - generate_table_type_in buf:STRING <-
+  (
+    buf.append "\nvoid *table_type[";
+    TYPE.id_counter_without_type.append_in buf;
+    buf.append "];\n";
+  );
+
+  - generate_debug_manager_in buf:STRING <-
+  (
+    buf.append
+      "void print_string(char *str) \n\
+      \{ \n\
+      \  while (*str!=0) {\n\
+      \    print_char(*str); \n\
+      \    str++; \n\
+      \  };\n\
+      \}\n\
+      \\n";
+  );
+
+  - generate_trace_declarations_in buf:STRING <-
+  ( + proto:PROTOTYPE;
+
+    buf.append "char *trace[";
+    buf.append (PROTOTYPE.prototype_list.count.to_string);
+    buf.append "]={\n";
+    (PROTOTYPE.prototype_list.lower).to (PROTOTYPE.prototype_list.upper-1) do {
+      j:INTEGER;
+      proto := PROTOTYPE.prototype_list.item j;
+      buf.append "  \"";
+      append_escaped_string (proto.name) in buf;
+      buf.append " (";
+      append_escaped_string (proto.filename) in buf;
+      buf.append ")\",\n";
+    };
+    proto := PROTOTYPE.prototype_list.last;
+    buf.append "  \"";
+    append_escaped_string (proto.name) in buf;
+    buf.append " (";
+    append_escaped_string (proto.filename) in buf;
+    buf.append ")\"\n};\n\n";
+  );
+
+  - generate_trace_codedata_in buf:STRING declarations_in decl:STRING <-
+  ( + src:HASHED_DICTIONARY[STRING,UINTEGER_32];
+    + key:UINTEGER_32;
+
+    //
+    // Source Code.
+    //
+
+    title "SOURCE LINE REFERENCE" in decl;
+
+    buf.append
+      "struct __source {\n\
+      \  unsigned int pos;\n\
+      \  char *line;\n\
+      \} __src[";
+    src := PUSH.source_line;
+    src.count.append_in buf;
+    buf.append "]={\n";
+    (src.lower).to (src.upper) do { j:INTEGER;
+      key := src.key j;
+      decl.append "#define L";
+      key.append_in decl;
+      decl.add_last ' ';
+      (j-1).append_in decl;
+      decl.add_last '\n';
+      //
+      buf.append "  {";
+      key.append_in buf;
+      buf.append ",\"";
+      buf.append (src.item j);
+      buf.append "\"},\n";
+    };
+    buf.remove (buf.upper - 1);
+    buf.append "};\n\n";
+  );
+
+  - generate_trace_code_in buf:STRING <-
+  (
+
+    //
+    // Signal Manager
+    //
+
+    (is_ansi).if {
+      buf.append
+        "// Unix Signal manager:\n\
+        \void interrupt_signal(int sig)  \n\
+        \{                               \n\
+        \  stack_print(top_context);     \n\
+        \  print_string(\"User interrupt.\\n\"); \n\
+        \  die_with_code(1);                     \n\
+        \}                                       \n\n";
+    };
+
+    //
+    // Stack Manager
+    //
+
+    buf.append
+      "void push_first(_____CONTEXT *path,unsigned long code)\n\
+      \{ \n";
+    (debug_level_option = 20).if {
+      buf.append
+        "  _____CONTEXT *cur,loop;\n\
+        \  cur = top_context; \n\
+        \  while ((cur != (void *)0) && (cur != path)) cur = cur->back; \n\
+        \  if (cur == path) {\n\
+        \    loop.back = top_context;\n\
+        \    loop.code = code; \n\
+        \    stack_print(&loop);\n\
+        \    print_string(\"COMPILER : Debug context looping detected !\\n\");\n\
+        \    die_with_code(1);\n\
+        \  };\n";
+    };
+    buf.append
+      "  path->back  = top_context;\n\
+      \  path->code  = code;\n\
+      \  top_context = path;\n\
+      \} \n\
+      \  \n\
+      \void push(_____CONTEXT *path,unsigned long code)\n\
+      \{ \n\
+      \  path->code  = code;\n\
+      \  top_context = path;\n\
+      \} \n\
+      \  \n\
+      \void stack_print(_____CONTEXT *up)      \n\
+      \{ _____CONTEXT *back,*next;             \n\
+      \  int j;                               \n\
+      \  next = (void *)0;                          \n\
+      \  while (up != (void *)0) {                  \n\
+      \    back = up -> back;                       \n\
+      \    up -> back = next;                       \n\
+      \    next = up;                               \n\
+      \    up = back;                               \n\
+      \  };                                         \n\
+      \  print_string(\"\\n============== BOTTOM ==============\\n\"); \n\
+      \  while (next != (void *)0) {                \n";
+    (debug_with_code).if {
+      buf.append
+        "    print_string(\"Line #\");                           \n\
+        \    print_integer(__src[next->code].pos >> 17);         \n\
+        \    print_string(\" Column #\");                        \n\
+        \    print_integer((__src[next->code].pos >> 9) & 0xFF); \n\
+        \    print_string(\" in \");                             \n\
+        \    print_string(trace[__src[next->code].pos & 0x1FF]); \n\
+        \    print_string(\".\\n\");                             \n\
+  \ if ((__src[next->code].pos & 0x1FF) != 0) { \n\
+        \    print_string(__src[next->code].line);               \n\
+        \    print_char('\\n');                                  \n\
+        \    for (j=0;j < ((__src[next->code].pos >> 9) & 0xFF);j++) {\n\
+        \      if (__src[next->code].line[j]=='\\t') print_char('\\t');\n\
+        \      else print_char(' ');\n\
+        \    };                                                  \n\
+        \    print_char('^');    \n\
+        \    print_char('\\n');   \n\
+  \ }; \n";
+
+    } else {
+      buf.append
+        "    print_string(\"Line #\");                \n\
+        \    print_integer(next->code >> 17);         \n\
+        \    print_string(\" Column #\");          \n\
+        \    print_integer((next->code >> 9) & 0xFF); \n\
+        \    print_string(\" in \");               \n\
+        \    print_string(trace[next->code & 0x1FF]); \n\
+        \    print_string(\".\\n\");                  \n";
+    };
+    buf.append
+      "    next = next -> back;                     \n\
+      \  };                                         \n\
+      \  print_string(\"================ TOP ===============\\n\"); \n\
+      \  top_context = (void *)0;                   \n\
+      \}                                            \n\
+      \ \n\
+      \void print_integer(unsigned short n) \n\
+      \{ unsigned short val;                \n\
+      \  char car;                          \n\
+      \  car = (n % 10) + '0';              \n\
+      \  val = n / 10;                      \n\
+      \  if (val != 0) print_integer(val);  \n\
+      \  print_char(car);                   \n\
+      \} \n\n";
+
+  );
 
 
diff --git a/src/tools/backend_java.li b/src/tools/backend_java.li
index 148c141..dda615e 100644
--- a/src/tools/backend_java.li
+++ b/src/tools/backend_java.li
@@ -33,12 +33,22 @@ Section Inherit
 
 Section Public
 
+  - source_extension :STRING_CONSTANT := ALIAS_STR.ext_java;
 
   - generate_type_typedef_for t:TYPE in buf:STRING <-
   (
     BACKEND_C.generate_type_typedef_for t in buf;
   );
 
+  - generate_type_struct_for_generic_in buf:STRING <-
+  (
+    buf.append
+      "// Generic Object\n\
+      \class ___OBJ {\n\
+      \  long __id;\n\
+      \};\n\n";
+  );
+
   - generate_type_struct_for_null_in buf:STRING <-
   (
   );
@@ -239,3 +249,116 @@ Section Public
 
   );
 
+  - generate_type_reference_star_declaration_in buf:STRING <-
+  (
+    buf.append "[]";
+  );
+
+  - generate_type_expanded_declaration_for t:TYPE in buf:STRING <-
+  (
+    (t.type_c != NULL).if {
+      buf.append (t.type_c);
+    } else {
+      append_type_name_for t in buf;
+    };
+  );
+
+  - generate_type_generic_declaration_in buf:STRING <-
+  (
+    buf.append "__OBJ ";
+  );
+
+  - generate_type_access_id_for_expr e:EXPR in buf:STRING <-
+  (
+    e.genere buf;
+    buf.append ".__id";
+  );
+
+
+  - append_null_value_in buf:STRING <-
+  (
+    buf.append "null";
+  );
+
+  - generate_read_slot_for read:READ_SLOT in buf:STRING <-
+  (
+    read.receiver.genere buf;
+    buf.add_last '.';
+    buf.append (read.variable.intern_name);
+  );
+
+  - generate_write_slot_for write:WRITE_SLOT in buf:STRING <-
+  (
+    // Receiver.
+    write.receiver.genere buf;
+    buf.add_last '.';
+    //
+    buf.append (write.variable.intern_name);
+    //
+    ((write.value.static_type.raw = TYPE_NULL) &&
+     {write.variable.type.raw.is_block}).if
+    {
+      buf.append ".__id=0";
+    } else {
+      buf.add_last '=';
+      write.genere_value buf;
+    };
+  );
+
+
+
+  - append_cop_init_code_in buf:STRING <-
+  (
+    not_yet_implemented;
+  );
+
+  - append_init_code_in buf:STRING input_name input_name:STRING_CONSTANT <-
+  (
+    buf.append "// Java code generated by Lisaac compiler (www.isaacOS.com) //\n";
+    buf.append "class ";
+    buf.append input_name;
+    buf.append " {\n";
+    buf.append "private static String arg[];\n";
+  );
+
+  - append_debug_code_in buf:STRING <- ();
+
+  - append_main_function_in buf:STRING <-
+  (
+    buf.append "public static void main(String parg[])\n";
+    buf.append "{\n";
+  );
+
+  - append_main_init_code_in buf:STRING <-
+  (
+    buf.append "arg = parg";
+  );
+
+  - append_main_return_code_in buf:STRING <-
+  (
+    indent.remove_last 2;
+    buf.append indent;
+    buf.append "}\n\n";
+  );
+
+  - append_end_of_file_in buf:STRING <-
+  (
+    buf.append "\n} // End class MAIN\n";
+  );
+
+  - generate_table_type_in buf:STRING <- ();
+
+
+  - generate_debug_manager_in buf:STRING <-
+  (
+    buf.append
+      "private static void print_string(String str) \n\
+      \{ \n\
+      \  System.out.print(str);\n\
+      \}\n\
+      \\n";
+  );
+
+  - generate_trace_declarations_in buf:STRING <- not_yet_implemented;
+  - generate_trace_codedata_in buf:STRING declarations_in decl:STRING <- not_yet_implemented;
+  - generate_trace_code_in buf:STRING <- not_yet_implemented;
diff --git a/src/type/prototype.li b/src/type/prototype.li
index 56ab7cd..3720a91 100644
--- a/src/type/prototype.li
+++ b/src/type/prototype.li
@@ -256,24 +256,10 @@ Section Public
     };
         
     // Command argument.
-    (is_ansi).if {      
-      (is_java).if {
-        cmd := "arg = parg";
-      } else {
-        string_tmp.clear;
-        (debug_level_option != 0).if {
-          string_tmp.copy "signal(SIGINT,interrupt_signal);\n  ";
-        };
-        string_tmp.append
-        "arg_count  = argc;\n\
-        \  arg_vector = argv;\n\
-        \#ifdef _PTHREAD_H\n\
-        \  pthread_key_create(&current_thread, NULL);\n\
-        \  pthread_attr_init(&thread_attr);\n\
-        \  /*pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);*/\n\
-        \#endif\n  ";        
-        cmd := ALIAS_STR.get string_tmp;
-      };
+    (is_ansi).if {
+      string_tmp.clear;
+      backend.append_main_init_code_in string_tmp;
+      cmd := ALIAS_STR.get string_tmp;
       i := EXTERNAL_C.create position text cmd
       access NULL persistant TRUE type (TYPE_VOID.default);
       list_current.add_last i;
diff --git a/src/type/type.li b/src/type/type.li
index 9fbffe4..1c4e13c 100644
--- a/src/type/type.li
+++ b/src/type/type.li
@@ -572,31 +572,21 @@ Section Public
   //
     
   - put_reference_declaration buffer:STRING <-
-  (        
-    buffer.append "__";
-    buffer.append intern_name;        
+  (
+    backend.append_type_name_for Self in buffer;
     add_genere_list;
   );
   
   - put_reference_star_declaration buffer:STRING <-
   (    
     (is_block).if_false { // BSBS: A mettre dans TYPE_BLOCK
-      (is_java).if {
-        buffer.append "[]";
-      } else {
-        buffer.add_last '*';
-      };
+      backend.generate_type_reference_star_declaration_in buffer;
     };
   );
   
   - put_expanded_declaration buffer:STRING <-
-  (    
-    ((is_java) && {type_c != NULL}).if {
-      buffer.append type_c;
-    } else {
-      buffer.append "__";
-      buffer.append intern_name;          
-    };
+  (
+    backend.generate_type_expanded_declaration_for Self in buffer;
     add_genere_list;
   );
   
@@ -605,11 +595,7 @@ Section Public
     (is_block).if { // BSBS: A mettre dans TYPE_BLOCK
       put_expanded_declaration buffer;
     } else {
-      (is_java).if {
-        buffer.append "__OBJ ";    
-      } else {
-        buffer.append (ALIAS_STR.c_void);    
-      };
+      backend.generate_type_generic_declaration_in buffer;
     };
   );
   
@@ -619,9 +605,7 @@ Section Public
   
   - put_id buffer:STRING <-
   (
-    buffer.append (ALIAS_STR.separate); // <=> "__"
-    buffer.append intern_name;
-    buffer.append (ALIAS_STR.separate);
+    backend.append_type_typeid_name_for Self in buffer;
   );
 
   - put_access_id e:EXPR in buffer:STRING <-
@@ -630,26 +614,18 @@ Section Public
     
     t := e.static_type.raw;
     (t = type_boolean).if {
-      e.genere buffer;  
-    }.elseif {t = type_block} then {
+      // TODO: Mildred: find a way to have expanded inheritance
       e.genere buffer;
-      //buffer.append ".__id";
+    }.elseif {t = type_block} then {
+      backend.generate_type_access_id_for_block e in buffer;
     } else {
-      (is_java).if {        
-        e.genere buffer;
-        buffer.append ".__id";
-      } else {
-        buffer.append "((struct ___OBJ *)";
-        e.genere buffer;
-        buffer.append ")->__id";
-      };
+      backend.generate_type_access_id_for_expr  e in buffer;
     };
   );
   
   - put_value buffer:STRING <-
   (
-    buffer.append intern_name;
-    buffer.append (ALIAS_STR.separate);
+    backend.append_type_proto_name_for Self in buffer;
     add_genere_list;
   );
     
diff --git a/src/type/type_generic.li b/src/type/type_generic.li
index f7d678d..632bcc9 100644
--- a/src/type/type_generic.li
+++ b/src/type/type_generic.li
@@ -218,12 +218,8 @@ Section Public
     (
       (prototype.shortname = ALIAS_STR.prototype_native_array) ||
       {prototype.shortname = ALIAS_STR.prototype_native_array_volatile}
-    ).if {      
-      (is_java).if {
-        buffer.append "[]";
-      } else {
-        buffer.add_last '*';
-      };
+    ).if {
+      backend.generate_type_reference_star_declaration_in buffer;
       generic_list.first.genere_star_declaration buffer;
     } else {
       parent_type.put_reference_star_declaration buffer;
diff --git a/src/type/type_null.li b/src/type/type_null.li
index 27922ef..1d65180 100644
--- a/src/type/type_null.li
+++ b/src/type/type_null.li
@@ -114,11 +114,7 @@ Section Public
   - put_access_id e:EXPR in buffer:STRING <- e.genere buffer;   
   
   - put_value buffer:STRING <- 
-  ( 
-    (is_java).if {
-      buffer.append "null";
-    } else {
-      buffer.append name;
-    };
+  (
+    backend.append_null_value_in buffer;
   );
   
\ No newline at end of file

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list