[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 998e8e8bb614ca464dbe1ecd0431a3e8d80f4ab1
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date:   Fri Aug 7 12:51:46 2009 +0200

    more in BACKEND

diff --git a/src/code_life/call_slot.li b/src/code_life/call_slot.li
index 0996592..11a449c 100644
--- a/src/code_life/call_slot.li
+++ b/src/code_life/call_slot.li
@@ -417,94 +417,17 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  ( + val:WRITE;
-    + arg:LOCAL;
-    + wrt:WRITE_LOCAL;
-    + np:INTEGER;
-    + low:INTEGER;
-    + back:INTEGER;
-    
+  (
     (cop_argument != NULL).if {
-      (
-        (argument_list.count >=1) && 
-        {argument_list.first != NULL} && 
-        {argument_list.first.variable.name = ALIAS_STR.variable_self}
-      ).if {
-        low := 1;
-      };
-      (argument_list.count-low > 0).if {        
-        back := buffer.count;
-        buffer.append "pthread_mutex_lock (&(";
-        cop_argument.genere buffer;        
-        buffer.append "->thread.mutex));\n";                
-        (low).to (argument_list.upper) do { j:INTEGER; 
-          val := argument_list.item j;        
-          (val != NULL).if {	           
-            buffer.append indent;
-            cop_argument.genere buffer;
-            buffer.append "->param_";
-            np.append_in buffer;
-            buffer.append "=(int)";
-            val.genere_value buffer;	  
-            buffer.append ";\n";          
-            np := np + 1;
-          } else {
-            "arg null\n".print;
-          };
-        };        
-        buffer.append indent;
-        (np = 0).if {
-          buffer.keep_head back;
-        };
-      };            
-      cop_argument.genere buffer;
-      buffer.append "->thread.procedure = COP_";
-      buffer.append (profil.name);
-      buffer.append ";\n";
-      buffer.append indent;
-      (is_cop_return).if {
-        buffer.append "return";
-      } else {
-        buffer.append "run_procedure";
-      };
-      buffer.append "((lith_object *)";
-      cop_argument.genere buffer;
-      buffer.add_last ')';
-    } else {    
-      (result_list.is_empty).if_false {
-        wrt ?= result_list.first.write;
-        wrt.genere_first_result buffer;      
-      };
-      buffer.append (profil.name);
-      (is_interrupt || {is_external}).if {
+      backend.generate_cop_call_slot Self in buffer;
+    } else {
+      ((is_interrupt) || {is_external}).if {
         (argument_list.first != NULL).if {
           semantic_error (argument_list.first.position,
           "Impossible `Self' argument for External or Interrupt slot.");
         };
       };
-      (! is_interrupt).if {
-        buffer.add_last '(';	
-        (argument_list.lower).to (argument_list.upper) do { j:INTEGER; 
-          val := argument_list.item j;
-          arg := profil.argument_list.item j;
-          (val != NULL).if {	 
-            (buffer.last != '(').if {
-              buffer.add_last ',';
-            };
-            val.genere_value buffer;	  
-          };
-        };
-        (result_list.count > 1).if {
-          (result_list.lower+1).to (result_list.upper) do { j:INTEGER;
-            (buffer.last != '(').if {
-              buffer.add_last ',';
-            };
-            wrt ?= result_list.item j.write;
-            wrt.genere_argument_result buffer;	  
-          };
-        };
-        buffer.add_last ')';
-      };
+      backend.generate_call_slot Self in buffer;
     };
   );
     
diff --git a/src/code_life/cop_lock.li b/src/code_life/cop_lock.li
index 7d3a921..8ab33dd 100644
--- a/src/code_life/cop_lock.li
+++ b/src/code_life/cop_lock.li
@@ -78,53 +78,7 @@ Section Public
   
   - genere buffer:STRING <-
   (
-    buffer.append "// Pre thread.\n";
-    //  buffer.append "print_char('(');\n";
-    //  buffer.append "print_char('\\n');\n";
-    buffer.append indent;
-    buffer.append "{ lith_node node,*n;\n";
-    indent.append "  ";    
-    buffer.append indent;
-    buffer.append "lith_object *obj;\n";
-    buffer.append indent;
-    buffer.append "void *thread_save;\n";    
-    buffer.append indent;
-    buffer.append "obj = &((";
-    data.genere buffer;
-    buffer.append ")->thread);\n";    
-    buffer.append indent;
-    buffer.append "node.next = NULL;\n";
-    buffer.append indent;
-    buffer.append "pthread_mutex_init(&node.mutex,NULL);\n";
-    buffer.append indent;
-    buffer.append "pthread_mutex_lock(&obj->mutex);\n";    
-    buffer.append indent;
-    buffer.append "n = obj->last;\n";
-    buffer.append indent;
-    buffer.append "if (n == NULL) {\n";
-    buffer.append indent;
-    buffer.append "  obj->first = &node;\n";
-    buffer.append indent;
-    buffer.append "} else {\n";
-    buffer.append indent;
-    buffer.append "  n->next = &node;\n";
-    buffer.append indent;
-    buffer.append "  pthread_mutex_lock(&node.mutex);\n";
-    buffer.append indent;
-    buffer.append "};\n";
-    buffer.append indent;
-    buffer.append "obj->last = &node;\n";      
-    buffer.append indent;
-    buffer.append "pthread_mutex_unlock(&obj->mutex);\n";
-    //
-    buffer.append indent;    
-    buffer.append "pthread_mutex_lock (&node.mutex);\n";
-    buffer.append indent;    
-    buffer.append "thread_save=pthread_getspecific(current_thread);\n";
-    buffer.append indent;
-    buffer.append "pthread_setspecific(current_thread,";
-    data.genere buffer;
-    buffer.add_last ')';    
+    backend.generate_cop_lock Self in buffer;
   );
   
   //
diff --git a/src/code_life/cop_unlock.li b/src/code_life/cop_unlock.li
index ff69c56..d12cfeb 100644
--- a/src/code_life/cop_unlock.li
+++ b/src/code_life/cop_unlock.li
@@ -75,28 +75,7 @@ Section Public
   
   - genere buffer:STRING <-
   (
-    buffer.append "pthread_mutex_lock(&(obj->mutex));\n"; 
-    buffer.append indent;
-    buffer.append "n = obj->first->next;\n";
-    buffer.append indent;
-    buffer.append "if (n != NULL) {\n";
-    buffer.append indent;
-    buffer.append "  pthread_mutex_unlock(&n->mutex);\n";
-    buffer.append indent;
-    buffer.append "} else {\n";
-    buffer.append indent;
-    buffer.append "  obj->last = NULL;\n";
-    buffer.append indent;
-    buffer.append "};\n";
-    buffer.append indent;
-    buffer.append "obj->first = n;\n";
-    buffer.append indent;
-    buffer.append "pthread_mutex_unlock(&obj->mutex);\n";     
-    buffer.append indent;
-    buffer.append "pthread_setspecific(current_thread,thread_save);\n";    
-    indent.remove_last 2;
-    buffer.append indent;
-    buffer.add_last '}';
+    backend.generate_cop_unlock Self in buffer;
   );
   
   //
diff --git a/src/code_life/instr.li b/src/code_life/instr.li
index a8122c4..197dea5 100644
--- a/src/code_life/instr.li
+++ b/src/code_life/instr.li
@@ -73,8 +73,9 @@ Section Public
   - genere buffer:STRING <- 
   (
     // BUG.
-    display buffer;
-    buffer.append " /* INSTR.genere :: Not genere ! */";
+    backend.generate_instruction_deferred Self in buffer;
+    //display buffer;
+    //buffer.append " /* INSTR.genere :: Not genere ! */";
     // FIN BUG.
     //deferred;
   );
diff --git a/src/code_life/list.li b/src/code_life/list.li
index f8489a7..b84b328 100644
--- a/src/code_life/list.li
+++ b/src/code_life/list.li
@@ -253,15 +253,10 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  (         
-    buffer.append "{\n";
-    indent.append "  ";
-    
+  (
+    backend.generate_function_header_in buffer;
     genere_body buffer;
-    
-    indent.remove_last 2;    
-    buffer.append indent;
-    buffer.add_last '}';
+    backend.generate_function_footer_in buffer;
   );
     
   - genere_extern buffer:STRING <-
@@ -311,7 +306,12 @@ Section Public
 Section Private  
   
   - genere_body buffer:STRING <-
-  ( + old_count,j:INTEGER;
+  (
+    lower.to (upper) do { i:INTEGER;
+      backend.generate_function_instruction (item i) in buffer;
+    };
+   /*
+    + old_count,j:INTEGER;
     j := lower;
     {j <= upper}.while_do {
       buffer.append indent;
@@ -321,36 +321,14 @@ Section Private
         j := j + 1;
       }.do_while {(j <= upper) && {old_count = buffer.count}};      
       buffer.append ";\n";
-    };        
+    };
+    */
   );
   
   - add_local tab:FAST_ARRAY[LOCAL] in buf:STRING <-
-  ( + loc:LOCAL;
-    + t:TYPE_FULL;
-    + cur:INTEGER;
-    
+  (
     (! tab.is_empty).if {
-      (tab.lower).to (tab.upper) do { j:INTEGER;
-	loc := tab.item j;	
-        loc.is_result.if_false {
-          (((buf.count + loc.intern_name.count - cur) > 70) || {t != loc.type}).if {
-            // New line
-            (t != NULL).if {
-              buf.append ";\n";
-            };
-            cur := buf.count;
-            t := loc.type;
-            buf.append indent;
-            t.genere_declaration buf;
-            buf.add_last ' ';
-          } else {
-            buf.add_last ',';
-          };
-          t.genere_star_declaration buf;
-          buf.append (loc.intern_name);
-        };
-      };
-      buf.append ";\n";
+      backend.generate_function_locals tab in buf;
       tab.clear;
     };
   );
diff --git a/src/code_life/loop.li b/src/code_life/loop.li
index 9e55bda..484b8d6 100644
--- a/src/code_life/loop.li
+++ b/src/code_life/loop.li
@@ -177,10 +177,7 @@ Section Public
   - genere buffer:STRING <-
   (         
     (! genere_while buffer).if {
-      buffer.append name;
-      buffer.append ":\n";
-      buffer.append indent;
-      body.genere buffer;
+      backend.generate_loop Self in buffer;
     };
   );
   
@@ -214,32 +211,23 @@ Section Public
 	  // While (...) do {...}.
 	  //
 	  result := TRUE;
-	  inverse.if {
-	    buffer.append "while (!";	    
-	  } else {
-	    buffer.append "while (";	    
-	  };
-	  switch.expr.genere buffer;
-	  //
-	  buffer.append ") ";
-	  lst_true.remove_last; 
-	  lst_true.genere buffer;
+          lst_true.remove_last; 
+          backend.generate_loop_while_do Self
+                  condition   (switch.expr)
+                  inverse     inverse
+                  body        lst_true
+                  in          buffer;
 	}.elseif {lst_true.count = 1} then {
 	  //
 	  // Do {...} while (...).
 	  //
 	  result := TRUE;
-	  buffer.append "do ";
-	  body.remove_last;
-	  body.genere buffer;
-	  inverse.if {
-	    buffer.append " while (!";	    
-	  } else {
-	    buffer.append " while (";	    
-	  };	  
-	  //
-	  switch.expr.genere buffer;
-	  buffer.add_last ')';
+          body.remove_last;
+          backend.generate_loop_do_while Self
+                  condition   (switch.expr)
+                  inverse     inverse
+                  body        body
+                  in          buffer;
 	};	
       };
     };
diff --git a/src/code_life/loop_end.li b/src/code_life/loop_end.li
index 44ad2ce..39c94c3 100644
--- a/src/code_life/loop_end.li
+++ b/src/code_life/loop_end.li
@@ -104,8 +104,7 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  (             
-    buffer.append "goto ";
-    buffer.append (loop.name);
+  (
+    backend.generate_loop_end Self in buffer;
   );
   
diff --git a/src/code_life/push.li b/src/code_life/push.li
index 107ea18..725b1f9 100644
--- a/src/code_life/push.li
+++ b/src/code_life/push.li
@@ -122,29 +122,16 @@ Section Public
     
   - genere buffer:STRING <-
   ( + id:UINTEGER_32;
+
     add_var_size context;
-    (is_first).if {      
-      buffer.append "push_first(&";
-    } else {
-      buffer.append "push(&";
-    };
-    buffer.append (context.intern_name);
-    buffer.add_last ',';
     id := position.code;
     (debug_with_code).if {
       (! source_line.fast_has id).if {
 	source_line.fast_put (position.extract_line) to id;
       };
-      buffer.add_last 'L';
     };
-    id.append_in buffer;
-    buffer.add_last ')';    
-    
-    buffer.append "; // L";
-    position.line.append_in buffer;
-    buffer.add_last ' ';
-    buffer.append (position.prototype.name);    
-    
+
+    backend.generate_push Self id id in buffer;
   );
 
   //
diff --git a/src/code_life/switch.li b/src/code_life/switch.li
index e579601..3065015 100644
--- a/src/code_life/switch.li
+++ b/src/code_life/switch.li
@@ -249,12 +249,11 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  ( + lst:LIST;
-    + first_case:INTEGER;
+  ( + first_case:INTEGER;
     + typ_first:TYPE;
-    + typ_id:TYPE_ID;
     + wrt:WRITE;
     + i:INTEGER;
+    + gen_else_end:BOOLEAN;
     
     (
       (list.first.id = TYPE_NULL) && 
@@ -277,65 +276,30 @@ Section Public
     //
     (list.is_empty).if_false {
       typ_first := list.first.id;
-      typ_id ?= typ_first;    
+
+      //
+      // Generate If
+      //  - when there is a test for NULL
+      //  - when there are at most two cases
+      //
       ((list.count <= 2) || {typ_first = TYPE_NULL}).if {
-        buffer.append "if (";
-        //                        
-        ((expr.static_type.raw.is_block) && {typ_first = TYPE_NULL}).if {
-          expr.genere buffer;	
-          buffer.append ".__id==0";
-        } else {
-          typ_first.put_access_id expr in buffer;      
-          (expr.static_type.raw != type_boolean).if {
-            buffer.append "==";
-            typ_first.put_id buffer;	
-          } else {
-            ? {typ_first.shortname = ALIAS_STR.prototype_true};
-          };
-        };
-        buffer.append ") ";
-        //
-        list.first.genere buffer;             
-        first_case := 1;
-        //
-        (list.count = 2).if {
-          lst := list.second.code;          
-          buffer.append " else ";
-            
-          buffer.append "/* ";
-          buffer.append (list.second.id.name);
-          buffer.append " */ ";
-            
-          list.second.genere buffer;          
-          first_case := 2;
-        }.elseif {list.count > 2} then {
-          buffer.append " else {\n";
-          indent.append "  ";
-          buffer.append indent;          
+        first_case := backend.generate_if Self in buffer;
+        (list.count > 2).if {
+          backend.generate_if_else_begin Self in buffer;
+          gen_else_end := TRUE;
         };
       };
+
+      //
+      // Generate switch
+      //
       (first_case <= list.upper).if {
-        polymorphic_counter := polymorphic_counter + 1;            
-        buffer.append "switch (";      
-        list.item first_case.id.put_access_id expr in buffer;
-        buffer.append ") {\n";
-        (first_case).to (list.upper) do { j:INTEGER;
-          buffer.append indent; 
-          buffer.append "case ";
-          list.item j.id.put_id buffer;
-          buffer.append ": ";          
-          list.item j.genere buffer;        
-          buffer.add_last ' ';	
-          buffer.append "break;\n";
-        };	
-        buffer.append indent;
-        buffer.add_last '}';
-        (first_case != 0).if {
-          buffer.add_last '\n';
-          indent.remove_last 2;    
-          buffer.append indent;
-          buffer.add_last '}';
-        };
+        polymorphic_counter := polymorphic_counter + 1;
+        backend.generate_switch Self first_case first_case in buffer;
+      };
+
+      gen_else_end.if {
+        backend.generate_if_else_end Self in buffer;
       };
     };
   );
diff --git a/src/external/call_null.li b/src/external/call_null.li
index 7a0251d..b758b46 100644
--- a/src/external/call_null.li
+++ b/src/external/call_null.li
@@ -55,19 +55,8 @@ Section Public
   //
   
   - genere buffer:STRING <-
-  ( + code:STRING_CONSTANT;
-    (debug_level_option != 0).if {
-      code := 
-      "stack_print(top_context); \
-      \print_string(\"Call on NULL\\n\"); \
-      \die_with_code(1)";
-    } else {
-      code := 
-      "print_string(\"Call on NULL\\n\
-      \(Use `-D' option)\\n\"); \ 
-      \die_with_code(1)";
-    };
-    buffer.append code;
+  (
+    backend.generate_call_on_null_in buffer;
     is_necessary := TRUE;
   );
   
diff --git a/src/external/put_to.li b/src/external/put_to.li
index dfb39bb..a736e0b 100644
--- a/src/external/put_to.li
+++ b/src/external/put_to.li
@@ -130,13 +130,15 @@ Section Public
   - genere buffer:STRING <-
   ( + type_generic:TYPE_GENERIC;
     + first_type:TYPE_FULL;
-    
+    type_generic ?= receiver.static_type.raw;
+    first_type := type_generic.generic_list.first;
+
+    backend.generate_put_to Self for_type first_type in buffer;
+    /*
     receiver.genere buffer;
     buffer.add_last '[';
     index.genere buffer;
     buffer.append "]=";    
-    type_generic ?= receiver.static_type.raw;
-    first_type := type_generic.generic_list.first;
     ((first_type.is_expanded) && {! first_type.is_expanded_c}).if {
       (value.static_type.is_expanded_ref).if {
 	buffer.append "*(";
@@ -148,6 +150,7 @@ Section Public
     } else {
       value.genere buffer;
     };
+    */
   );
   
   //
diff --git a/src/tools/backend.li b/src/tools/backend.li
index fb4b6a8..785e53d 100644
--- a/src/tools/backend.li
+++ b/src/tools/backend.li
@@ -93,6 +93,66 @@ Section Public
   );
 
   //
+  // Functions
+  //
+
+  - generate_function_header_in buffer:STRING <-
+  (
+    buffer.append "{\n";
+    indent.append "  ";
+  );
+
+  - generate_function_locals tab:FAST_ARRAY[LOCAL] in buf:STRING <-
+  [
+    -? { ! tab.is_empty };
+  ]
+  ( + loc:LOCAL;
+    + t:TYPE_FULL;
+    + cur:INTEGER;
+
+    (tab.lower).to (tab.upper) do { j:INTEGER;
+      loc := tab.item j;
+      loc.is_result.if_false {
+        (((buf.count + loc.intern_name.count - cur) > 70) || {t != loc.type}).if {
+          // New line
+          (t != NULL).if {
+            buf.append ";\n";
+          };
+          cur := buf.count;
+          t   := loc.type;
+          buf.append indent;
+          t.genere_declaration buf;
+          buf.add_last ' ';
+        } else {
+          buf.add_last ',';
+        };
+        t.genere_star_declaration buf;
+        buf.append (loc.intern_name);
+      };
+    };
+    buf.append ";\n";
+  );
+
+  - generate_function_instruction i:INSTR in buffer:STRING <-
+  ( + count:INTEGER;
+    buffer.append indent;
+    count := buffer.count;
+    i.genere buffer;
+    (buffer.count = count).if {
+      buffer.remove_last (indent.count);
+    } else {
+      buffer.append ";\n";
+    };
+  );
+
+  - generate_function_footer_in buffer:STRING <-
+  (
+    indent.remove_last 2;
+    buffer.append indent;
+    buffer.add_last '}';
+  );
+
+  //
   // Read and Write
   //
 
@@ -110,6 +170,384 @@ Section Public
   );
 
   //
+  // Other instructions
+  //
+
+  - generate_instruction_deferred i:INSTR in buf:STRING <-
+  (
+    buf.append "#error \"";
+    buf.append "INSTR: can't generate instruction: ";
+    i.display buf;
+    buf.add_last '"';
+  );
+
+  - generate_call_on_null_in buffer:STRING <-
+  (
+    (debug_level_option != 0).if {
+      buffer.append
+        "stack_print(top_context); \
+        \print_string(\"Call on NULL\\n\"); \
+        \die_with_code(1)";
+    } else {
+      buffer.append
+        "print_string(\"Call on NULL\\n\
+        \(Use `-D' option)\\n\"); \
+        \die_with_code(1)";
+    };
+  );
+
+  - generate_put_to put_to:PUT_TO for_type t:TYPE_FULL in buffer:STRING <-
+  (
+    put_to.receiver.genere buffer;
+    buffer.add_last '[';
+    put_to.index.genere buffer;
+    buffer.append "]=";
+
+    ((t.is_expanded) && {! t.is_expanded_c} &&
+     {put_to.value.static_type.is_expanded_ref}).if
+    {
+      buffer.append "*(";
+      put_to.value.genere buffer;
+      buffer.add_last ')';
+    } else {
+      put_to.value.genere buffer;
+    };
+  );
+
+  - generate_loop_while_do l:LOOP
+    condition   e:EXPR
+    inverse     inverse:BOOLEAN
+    body        lst:LIST
+    in          buffer:STRING <-
+  (
+    buffer.append "while (";
+    inverse.if { buffer.add_last '!'; };
+    e.genere buffer;
+    buffer.append ") ";
+    lst.genere buffer;
+  );
+
+  - generate_loop_do_while l:LOOP
+    condition   e:EXPR
+    inverse     inverse:BOOLEAN
+    body        lst:LIST
+    in          buffer:STRING <-
+  (
+    buffer.append "do ";
+    lst.genere buffer;
+    buffer.append " while (";
+    inverse.if { buffer.add_last '!'; };
+    e.genere buffer;
+    buffer.add_last ')';
+  );
+
+  - generate_loop l:LOOP in buffer:STRING <-
+  (
+    buffer.append (l.name);
+    buffer.append ":\n";
+    buffer.append indent;
+    l.body.genere buffer;
+  );
+
+  - generate_loop_end l:LOOP_END in buffer:STRING <-
+  (
+    buffer.append "goto ";
+    buffer.append (l.loop.name);
+  );
+
+  - generate_if sw:SWITCH in buffer:STRING :INTEGER <-
+  ( + first_case:INTEGER;
+    + typ_first:TYPE;
+    + typ_id:TYPE_ID;
+    typ_first := sw.list.first.id;
+    typ_id    ?= typ_first;
+
+    //
+    // If Condition
+    //
+    buffer.append "if (";
+    ((sw.expr.static_type.raw.is_block) && {typ_first = TYPE_NULL}).if {
+      sw.expr.genere buffer;
+      buffer.append ".__id==0";
+    } else {
+      typ_first.put_access_id (sw.expr) in buffer;
+      (sw.expr.static_type.raw != type_boolean).if {
+        buffer.append "==";
+        typ_first.put_id buffer;
+      } else {
+        ? {typ_first.shortname = ALIAS_STR.prototype_true};
+      };
+    };
+    buffer.append ") ";
+
+    //
+    // If Block
+    //
+    sw.list.first.genere buffer;
+    first_case := 1;
+
+    //
+    // Else
+    //
+    (sw.list.count = 2).if {
+      buffer.append " else ";
+      buffer.append "/* ";
+      buffer.append (sw.list.second.id.name);
+      buffer.append " */ ";
+      sw.list.second.genere buffer;
+      first_case := 2;
+    };
+
+    first_case
+  );
+
+  - generate_if_else_begin sw:SWITCH in buffer:STRING <-
+  (
+    buffer.append " else {\n";
+    indent.append "  ";
+    buffer.append indent;
+  );
+
+  - generate_if_else_end sw:SWITCH in buffer:STRING <-
+  (
+    buffer.add_last '\n';
+    indent.remove_last 2;
+    buffer.append indent;
+    buffer.add_last '}';
+  );
+
+  - generate_switch sw:SWITCH first_case first_case:INTEGER in buffer:STRING <-
+  (
+    //
+    // Switch
+    //
+    buffer.append "switch (";
+    sw.list.item first_case.id.put_access_id (sw.expr) in buffer;
+    buffer.append ") {\n";
+
+    //
+    // Each case
+    //
+    (first_case).to (sw.list.upper) do { j:INTEGER;
+      buffer.append indent;
+      buffer.append "case ";
+      sw.list.item j.id.put_id buffer;
+      buffer.append ": ";
+      sw.list.item j.genere buffer;
+      buffer.add_last ' ';
+      buffer.append "break;\n";
+    };
+
+    buffer.append indent;
+    buffer.add_last '}';
+  );
+
+
+  - generate_cop_lock l:COP_LOCK in buffer:STRING <-
+  (
+    buffer.append "// Pre thread.\n";
+    //  buffer.append "print_char('(');\n";
+    //  buffer.append "print_char('\\n');\n";
+    buffer.append indent;
+    buffer.append "{ lith_node node,*n;\n";
+    indent.append "  ";
+    buffer.append indent;
+    buffer.append "lith_object *obj;\n";
+    buffer.append indent;
+    buffer.append "void *thread_save;\n";
+    buffer.append indent;
+    buffer.append "obj = &((";
+    l.data.genere buffer;
+    buffer.append ")->thread);\n";
+    buffer.append indent;
+    buffer.append "node.next = NULL;\n";
+    buffer.append indent;
+    buffer.append "pthread_mutex_init(&node.mutex,NULL);\n";
+    buffer.append indent;
+    buffer.append "pthread_mutex_lock(&obj->mutex);\n";
+    buffer.append indent;
+    buffer.append "n = obj->last;\n";
+    buffer.append indent;
+    buffer.append "if (n == NULL) {\n";
+    buffer.append indent;
+    buffer.append "  obj->first = &node;\n";
+    buffer.append indent;
+    buffer.append "} else {\n";
+    buffer.append indent;
+    buffer.append "  n->next = &node;\n";
+    buffer.append indent;
+    buffer.append "  pthread_mutex_lock(&node.mutex);\n";
+    buffer.append indent;
+    buffer.append "};\n";
+    buffer.append indent;
+    buffer.append "obj->last = &node;\n";
+    buffer.append indent;
+    buffer.append "pthread_mutex_unlock(&obj->mutex);\n";
+    //
+    buffer.append indent;
+    buffer.append "pthread_mutex_lock (&node.mutex);\n";
+    buffer.append indent;
+    buffer.append "thread_save=pthread_getspecific(current_thread);\n";
+    buffer.append indent;
+    buffer.append "pthread_setspecific(current_thread,";
+    l.data.genere buffer;
+    buffer.add_last ')';
+  );
+
+  - generate_cop_unlock l:COP_UNLOCK in buffer:STRING <-
+  (
+    buffer.append "pthread_mutex_lock(&(obj->mutex));\n";
+    buffer.append indent;
+    buffer.append "n = obj->first->next;\n";
+    buffer.append indent;
+    buffer.append "if (n != NULL) {\n";
+    buffer.append indent;
+    buffer.append "  pthread_mutex_unlock(&n->mutex);\n";
+    buffer.append indent;
+    buffer.append "} else {\n";
+    buffer.append indent;
+    buffer.append "  obj->last = NULL;\n";
+    buffer.append indent;
+    buffer.append "};\n";
+    buffer.append indent;
+    buffer.append "obj->first = n;\n";
+    buffer.append indent;
+    buffer.append "pthread_mutex_unlock(&obj->mutex);\n";
+    buffer.append indent;
+    buffer.append "pthread_setspecific(current_thread,thread_save);\n";
+    indent.remove_last 2;
+    buffer.append indent;
+    buffer.add_last '}';
+  );
+
+  - generate_cop_call_slot call:CALL_SLOT in buffer:STRING <-
+  ( + val:WRITE;
+    + np:INTEGER;
+    + low:INTEGER;
+    + back:INTEGER;
+
+    (
+      (call.argument_list.count >=1) &&
+      {call.argument_list.first != NULL} &&
+      {call.argument_list.first.variable.name = ALIAS_STR.variable_self}
+    ).if {
+      low := 1;
+    };
+    (call.argument_list.count-low > 0).if {
+      back := buffer.count;
+      buffer.append "pthread_mutex_lock (&(";
+      call.cop_argument.genere buffer;
+      buffer.append "->thread.mutex));\n";
+      (low).to (call.argument_list.upper) do { j:INTEGER;
+        val := call.argument_list.item j;
+        (val != NULL).if {
+          buffer.append indent;
+          call.cop_argument.genere buffer;
+          buffer.append "->param_";
+          np.append_in buffer;
+          buffer.append "=(int)";
+          val.genere_value buffer;
+          buffer.append ";\n";
+          np := np + 1;
+        } else {
+          "arg null\n".print;
+        };
+      };
+      buffer.append indent;
+      (np = 0).if {
+        buffer.keep_head back;
+      };
+    };
+    call.cop_argument.genere buffer;
+    buffer.append "->thread.procedure = COP_";
+    buffer.append (call.profil.name);
+    buffer.append ";\n";
+    buffer.append indent;
+    (call.is_cop_return).if {
+      buffer.append "return";
+    } else {
+      buffer.append "run_procedure";
+    };
+    buffer.append "((lith_object *)";
+    call.cop_argument.genere buffer;
+    buffer.add_last ')';
+  );
+
+  - generate_call_slot call:CALL_SLOT in buffer:STRING <-
+  ( + val:WRITE;
+    + arg:LOCAL;
+    + wrt:WRITE_LOCAL;
+
+    //
+    // Get the return value
+    //
+    (call.result_list.is_empty).if_false {
+      wrt ?= call.result_list.first.write;
+      wrt.genere_first_result buffer;
+    };
+
+    //
+    // Function Call
+    //
+    buffer.append (call.profil.name);
+    (! call.is_interrupt).if {
+      buffer.add_last '(';
+
+      //
+      // Argument List
+      //
+      (call.argument_list.lower).to (call.argument_list.upper) do { j:INTEGER;
+        val := call.argument_list.item j;
+        arg := call.profil.argument_list.item j;
+        (val != NULL).if {
+          (buffer.last != '(').if {
+            buffer.add_last ',';
+          };
+          val.genere_value buffer;
+        };
+      };
+
+      //
+      // Result List
+      //
+      (call.result_list.count > 1).if {
+        (call.result_list.lower+1).to (call.result_list.upper) do { j:INTEGER;
+          (buffer.last != '(').if {
+            buffer.add_last ',';
+          };
+          wrt ?= call.result_list.item j.write;
+          wrt.genere_argument_result buffer;
+        };
+      };
+
+      //
+      // End
+      //
+      buffer.add_last ')';
+    };
+  );
+
+  - generate_push p:PUSH id id:UINTEGER_32 in buffer:STRING <-
+  (
+    p.is_first.if {
+      buffer.append "push_first(&";
+    } else {
+      buffer.append "push(&";
+    };
+    buffer.append (p.context.intern_name);
+    buffer.add_last ',';
+    (debug_with_code).if {
+      buffer.add_last 'L';
+    };
+    id.append_in buffer;
+    buffer.add_last ')';
+    buffer.append "; // L";
+    p.position.line.append_in buffer;
+    buffer.add_last ' ';
+    buffer.append (p.position.prototype.name);
+  );
+
+  //
   // Misc Code
   //
 
diff --git a/src/tools/backend_c.li b/src/tools/backend_c.li
index ee855b9..9735541 100644
--- a/src/tools/backend_c.li
+++ b/src/tools/backend_c.li
@@ -342,7 +342,6 @@ Section Public
   );
 
 
-
   - append_null_value_in buf:STRING <-
   (
     buf.append "NULL";

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list