[SCM] Lisaac compiler branch, mildred-backend, updated. lisaac-0.12-531-ge265846

Mildred Ki'Lya silkensedai at online.fr
Tue Aug 25 22:08:09 UTC 2009


The following commit has been merged in the mildred-backend branch:
commit e2658467e3fdf34ab797c728803f6b8676367d6c
Merge: 7710f7687c4c5185b71b8c118ec413275b7a093b bcfd7ae27bd2d1b125ce07a0255f27cbd44df676
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date:   Wed Aug 26 00:03:40 2009 +0200

    Merge commit 'origin/master' into mildred-backend

diff --combined make.lip
index 853d8d8,64658a0..8203772
--- a/make.lip
+++ b/make.lip
@@@ -57,51 -57,14 +57,51 @@@ Section Privat
    
    + target:STRING := "unix";
    
 +  + lib_std :PROJECT;
 +  + parent_project :PROJECT;
 +
 +  //
 +  // Code
 +  //
 +
 +  - default_init prj:PROJECT <-
 +  // Initialize the library
 +  (
 +    "Initialize project ".print; Self.print;
 +    prj.if { " from ".print; prj.print; };
 +    "\n".print;
 +
 +    parent_project := prj;
 +    parent_project.if {
 +      lisaac          := parent_project.lisaac;
 +      target          := parent_project.target;
 +      debug_level     := parent_project.debug_level;
 +      debug_with_code := parent_project.debug_with_code;
 +      is_all_warning  := parent_project.is_all_warning;
 +      is_optimization := parent_project.is_optimization;
 +      inline_level    := parent_project.inline_level;
 +      is_java         := parent_project.is_java;
 +      is_cop          := parent_project.is_cop;
 +      is_statistic    := parent_project.is_statistic;
 +      is_quiet        := parent_project.is_quiet;
 +    };
 +  );
 +
 +  - init prj:PROJECT <-
 +  // Initialize the library
 +  (
 +    default_init prj;
 +  );
 +  
    //
    // Directory.
    //
    
    - standard_path <-
    // Standard library.
 -  ( 
 -    path (lisaac + "lib/*");    
 +  (
 +    lib_std := lib_std.create("STD");
 +    lib_std := lib_std.load("lib.lip");
    );
    
    //
@@@ -110,18 -73,31 +110,18 @@@
    
    - unix_target <-
    (
 -    path (lisaac + "lib_os/unix/system/");
 -    path (lisaac + "lib_os/unix/file_system/");
 -    path (lisaac + "lib_os/unix/video/");
    );
    
    - windows_target <-
    (
 -    path (lisaac + "lib_os/unix/system/");
 -    path (lisaac + "lib_os/windows/file_system/");
 -    path (lisaac + "lib_os/unix/file_system/");  // BSBS: ??
 -    path (lisaac + "lib_os/windows/video/");
    );
  
    - dos_target <-
    (
 -    path (lisaac + "lib_os/unix/system/");
 -    path (lisaac + "lib_os/unix/file_system/"); // BSBS: ??    
 -    path (lisaac + "lib_os/dos/file_system/");
 -    path (lisaac + "lib_os/dos/video/");
    );
    
    - java_target <-
    (
 -    path (lisaac + "lib_os/java/system/");
 -    path (lisaac + "lib_os/java/file_system/");
    );
    
    - get_target <-
@@@ -140,21 -116,33 +140,33 @@@
      };
      (target = "").if {
        "Target code needed.\n".print;
 -      exit;
 +      exit 1;
      };
    );
        
    - add_lib lib:STRING <-
    (
-     run "echo \"int main(){ return(1); }\" > __tmp__.c";    
-     (run ("gcc __tmp__.c -o __tmp__ " + lib + " 2> /dev/null") = 0).if {
-       lib_gcc := lib_gcc + " " + lib;
-       run "rm __tmp__.c __tmp__";
+     (target = "windows").if {
+       run "echo int main(){ return(1); } > __tmp__.c";    
+       (run ("gcc __tmp__.c -o __tmp__ " + lib + " > NUL") = 0).if {
+         lib_gcc := lib_gcc + " " + lib;
+         run "del __tmp__.c __tmp__.exe";
+       } else {
+         "\nERROR: `" + lib + "' library for GCC not found.\n".print;
+         run "del __tmp__.c";
+         exit;
+       };    
      } else {
-       "\nERROR: `" + lib + "' library for GCC not found.\n".print;
-       run "rm __tmp__.c";
-       exit;
-     };    
+       run "echo \"int main(){ return(1); }\" > __tmp__.c";    
+       (run ("gcc __tmp__.c -o __tmp__ " + lib + " 2> /dev/null") = 0).if {
+         lib_gcc := lib_gcc + " " + lib;
+         run "rm __tmp__.c __tmp__";
+       } else {
+         "\nERROR: `" + lib + "' library for GCC not found.\n".print;
+         run "rm __tmp__.c";
+         exit;
+       };    
+     };
    );
    
    - execute cmd:STRING <-
@@@ -203,7 -191,7 +215,7 @@@
        (is_cop).if {
          lib_gcc := lib_gcc + " -lpthread";
        };
-       execute ("gcc " + input_file + ".c -o " + input_file + " -lm -lX11 " + option_gcc + lib_gcc);
+       execute ("gcc " + input_file + ".c -o " + input_file + " -lm " + option_gcc + lib_gcc);
      };
    );
    
@@@ -218,12 -206,6 +230,12 @@@
    (
      general_back_end;
    );
 +
 +  - print_info <-
 +  // Print information about the project
 +  (
 +    info_project.print;
 +  );
    
  Section Public
    
@@@ -309,15 -291,7 +321,15 @@@
    //
    // Other.
    //
 -  
 +
 +  - info <-
 +  // Information about the project
 +  (
 +    front_end;
 +    print_info;
 +    exit;
 +  );
 +
    - q <-
    // Quiet operation.
    (
diff --combined src/tools/backend_c.li
index 7f85b18,0000000..030b4b8
mode 100644,000000..100644
--- a/src/tools/backend_c.li
+++ b/src/tools/backend_c.li
@@@ -1,660 -1,0 +1,655 @@@
 +///////////////////////////////////////////////////////////////////////////////
 +//                             Lisaac Compiler                               //
 +//                                                                           //
 +//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
 +//                                                                           //
 +//   This program is free software: you can redistribute it and/or modify    //
 +//   it under the terms of the GNU General Public License as published by    //
 +//   the Free Software Foundation, either version 3 of the License, or       //
 +//   (at your option) any later version.                                     //
 +//                                                                           //
 +//   This program is distributed in the hope that it will be useful,         //
 +//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
 +//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
 +//   GNU General Public License for more details.                            //
 +//                                                                           //
 +//   You should have received a copy of the GNU General Public License       //
 +//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
 +//                                                                           //
 +//                     http://isaacproject.u-strasbg.fr/                     //
 +///////////////////////////////////////////////////////////////////////////////
 +Section Header
 +
 +  + name        := BACKEND_C;
 +
 +  - copyright   := "2009 Mildred Ki'Lya";
 +
 +  - author      := "Mildred Ki'Lya (http://ki.lya.online.fr)";
 +  - comment     := "C Backend";
 +
 +Section Inherit
 +
 +  + parent_backend: Expanded BACKEND;
 +
 +Section Public
 +
 +  - source_extension :STRING_CONSTANT := ALIAS_STR.ext_c;
 +
 +  - generate_type_typedef_for t:TYPE in buf:STRING <-
 +  ( + alias:TYPE;
 +
 +    buf.append "typedef ";
 +    (t.type_c != NULL).if {
 +      buf.append (t.type_c);
 +    } else {
 +      alias := t;
 +      {alias.alias_slot = NULL}.until_do {
 +	alias := alias.alias_type;
 +      };
 +      buf.append "struct ";
 +      append_type_struct_name_for alias in buf;
 +    };
 +    buf.add_last ' ';
 +    append_type_name_for t in buf;
 +    buf.add_last ';';
 +    ((t.type_c = NULL) && {t.alias_slot != NULL}).if {
 +      output_decl.append " // ALIAS with ";
 +      output_decl.append (t.alias_type.intern_name);
 +    };
 +    buf.add_last '\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
 +      "// NULL\n\
 +      \#ifndef NULL\n\
 +      \#define NULL ((void *)0)\n\
 +      \#endif\n\n";
 +  );
 +  
 +  - generate_type_struct_for_context_in buf:STRING <-
 +  (
 +    buf.append
 +      "// ___CONTEXT\n\
 +      \typedef struct ___CONTEXT_struct _____CONTEXT; \n\
 +      \struct ___CONTEXT_struct {\n\
 +      \  unsigned long code; \n\
 +      \  _____CONTEXT *back; \n\
 +      \};\n\
 +      \_____CONTEXT *top_context; \n\n";
 +  );
 +
 +  - generate_type_struct_for t:TYPE in buf:STRING <-
 +  (
 +    (t.alias_slot = NULL).if {
 +
 +      //
 +      // Start the struct declaration
 +      //
 +      buf.append "struct ";
 +      append_type_struct_name_for t in buf;
 +      buf.append " {\n";
 +
 +      //
 +      // Struct Contents
 +      //
 +      generate_type_struct_contents_for t in buf;
 +
 +      //
 +      // End structure declaration
 +      //
 +      (t.prototype.is_mapping).if {
 +	buf.append "} __attribute__ ((packed));\n";
 +      } else {
 +	buf.append "};\n";
 +      };
 +    };
 +  );
 +
 +  - generate_type_struct_boolean_for t:TYPE in buf:STRING <-
 +  (
 +    buf.append "#define ";
 +    append_type_proto_name_for t in buf;
 +    buf.append " ";
 +    buf.add_last ((t.shortname = ALIAS_STR.prototype_true).to_character);
 +    buf.add_last '\n';
 +  );
 +
 +  - generate_type_struct_typeid_for t:TYPE in buf:STRING <-
 +  (
 +    buf.append "#define ";
 +    append_type_typeid_name_for t in buf;
 +    buf.append " ";
 +    t.is_late_binding.if {
 +      TYPE.generate_id_with_type.append_in buf;
 +    } else {
 +      TYPE.generate_id_without_type.append_in buf;
 +    };
 +    buf.add_last '\n';
 +  );
 +
 +  - generate_type_globals_for t:TYPE in buf:STRING <-
 +  (
 +    (t.type_c = NULL).if {
 +      append_type_name_for t in buf;
 +      buf.add_last ' ';
 +      append_type_expanded_proto_name_for t in buf;
 +      t.is_late_binding.if {
 +        buf.append "={";
 +        append_type_typeid_name_for t in buf;
 +        buf.append "}";
 +      };
 +      buf.append ";\n";
 +      buf.append "#define ";
 +      append_type_proto_name_for t in buf;
 +      buf.append " (&";
 +      append_type_expanded_proto_name_for t in buf;
 +      buf.append ")\n\n";
 +    };
 +
 +  );
 +
 +  - 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,tf2:TYPE_FULL;
 +    + t:TYPE;
 +    + add_end:BOOLEAN;
 +    + ptr,ptr2:BOOLEAN;
 +
 +    (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;
 +
 +      t  := read.slot.receiver_type;
 +      (t.alias_slot != NULL).if {
 +	tf2 := read.slot.type;
 +	ptr  := (! tf .is_expanded) || {tf .is_expanded_ref} || {tf .is_strict};
 +	ptr2 := (! tf2.is_expanded) || {tf2.is_expanded_ref} || {tf2.is_strict};
 +	(ptr != ptr2).if {
 +	  add_end := TRUE;
 +	  (ptr).if {
 +	    buf.append "(*(";
 +	  } else {
 +	    buf.append "(&(";
 +	  };
 +	};
 +      };
 +      ((tf.is_strict) || {tf.is_expanded_ref} || {tf.is_expanded}).if {
 +        read.receiver.genere buf;
 +      } else {
 +        buf.append "((";
 +        t.put_reference_declaration buf;
 +        buf.add_last ' ';
 +        t.put_reference_star_declaration buf;
 +        buf.add_last ')';
 +        read.receiver.genere buf;
 +        buf.append ")";
 +      };
 +      (t.alias_slot = NULL).if {
 +        ((tf.is_expanded) && {! tf.is_expanded_ref} && {! tf.is_strict}).if {
 +	  buf.add_last '.';
 +	} else {
 +	  buf.append "->";
 +	};
 +	buf.append (read.variable.intern_name);
 +      }.elseif {add_end} then {
 +	buf.append "))";
 +      };
 +    };
 +  );
 +
 +  - generate_write_slot_for write:WRITE_SLOT in buf:STRING <-
 +  ( + tf:TYPE_FULL;
 +    + t:TYPE;
 +
 +    // Receiver.
-     (write.quiet_generation).if {
-       buf.append "/* WRTOK */";
-     } else {
-       buf.append "/* WRTNO */";
-     };
 +    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).if {
 +      buf.append "// Debug Manager\n";
 +      (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
 +      "int print_string(char *str) \n\
 +      \{ \n\
 +      \  while (*str!=0) {\n\
 +      \    print_char(*str); \n\
 +      \    str++; \n\
 +      \  };\n\
 +      \  return(0);\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 --combined src/tools/backend_java.li
index 917f941,0000000..e599b60
mode 100644,000000..100644
--- a/src/tools/backend_java.li
+++ b/src/tools/backend_java.li
@@@ -1,295 -1,0 +1,290 @@@
 +///////////////////////////////////////////////////////////////////////////////
 +//                             Lisaac Compiler                               //
 +//                                                                           //
 +//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
 +//                                                                           //
 +//   This program is free software: you can redistribute it and/or modify    //
 +//   it under the terms of the GNU General Public License as published by    //
 +//   the Free Software Foundation, either version 3 of the License, or       //
 +//   (at your option) any later version.                                     //
 +//                                                                           //
 +//   This program is distributed in the hope that it will be useful,         //
 +//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
 +//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
 +//   GNU General Public License for more details.                            //
 +//                                                                           //
 +//   You should have received a copy of the GNU General Public License       //
 +//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
 +//                                                                           //
 +//                     http://isaacproject.u-strasbg.fr/                     //
 +///////////////////////////////////////////////////////////////////////////////
 +Section Header
 +
 +  + name        := BACKEND_JAVA;
 +
 +  - copyright   := "2009 Mildred Ki'Lya";
 +
 +  - author      := "Mildred Ki'Lya (http://ki.lya.online.fr)";
 +  - comment     := "Java Backend";
 +
 +Section Inherit
 +
 +  + parent_backend: Expanded BACKEND;
 +
 +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 <-
 +  (
 +  );
 +
 +  - generate_type_struct_for_context_in buf:STRING <-
 +  (
 +    BACKEND_C.generate_type_struct_for_context_in buf;
 +  );
 +
 +
 +  - generate_type_struct_for t:TYPE in buf:STRING <-
 +  ( + count_slot:SLOT_DATA;
 +    + storage_slot:SLOT_DATA;
 +
 +    //
 +    // Start the class declaration
 +    //
 +    buf.append "static class ";
 +    append_type_name_for t in buf;
 +    t.is_late_binding.if {
 +      buf.append " extends __OBJ";
 +    };
 +    buf.append " {\n";
 +
 +
 +    //
 +    // Struct Contents
 +    //
 +    generate_type_struct_contents_for t in buf;
 +
 +    //
 +    // Handle special case where the type is STRING_CONSTANT
 +    // We must generate a special constructor
 +    //
 +    (t = type_string_constant).if {
 +      // STRING_CONSTANT constructor.
 +      buf.append "\n  public ";
 +      append_type_name_for t in buf;
 +      buf.add_last '(';
 +      t.is_late_binding.if {
 +	buf.append "int pid,";
 +      };
 +      storage_slot := t.get_local_slot (ALIAS_STR.slot_storage).slot_data_intern;
 +      count_slot   := t.get_local_slot (ALIAS_STR.slot_count).slot_data_intern;
 +      (count_slot.ensure_count != 0).if {
 +	buf.append "int pcount,";
 +      };
 +      (storage_slot.ensure_count != 0).if {
 +	buf.append "String pstorage,";
 +      };
 +      buf.remove_last 1;
 +      buf.append ")\n  {\n    ";
 +      t.is_late_binding.if {
 +	buf.append "__id = pid;\n";
 +      };
 +      (count_slot.ensure_count != 0).if {
 +	buf.append (count_slot.intern_name);
 +	buf.append " = pcount;\n";
 +      };
 +      (storage_slot.ensure_count != 0).if {
 +	buf.append (storage_slot.intern_name);
 +	buf.append " = pstorage.toCharArray();\n";
 +      };
 +      buf.append "  };\n";
 +    };
 +
 +    //
 +    // Basic Constructor
 +    //
 +    buf.append "\n  public ";
 +    append_type_name_for t in buf;
 +    buf.add_last '(';
 +    t.is_late_binding.if {
 +      buf.append "int pid";
 +    };
 +    buf.append ")\n  {\n    ";
 +    t.is_late_binding.if {
 +      buf.append "__id = pid;\n";
 +    } else {
 +      buf.append "super();\n";
 +    };
 +    buf.append "  };\n";
 +
 +    //
 +    // End class declaration
 +    //
 +    buf.append "};\n";
 +  );
 +
 +  - generate_type_struct_boolean_for t:TYPE in buf:STRING <-
 +  ();
 +
 +  - generate_type_struct_typeid_for t:TYPE in buf:STRING <-
 +  (
 +    buf.append "static private int ";
 +    buf.append (t.intern_name);
 +    append_type_typeid_name_for t in buf;
 +    buf.append " = ";
 +    t.is_late_binding.if {
 +      TYPE.generate_id_with_type.append_in buf;
 +    } else {
 +      TYPE.generate_id_without_type.append_in buf;
 +    };
 +    buf.add_last ';';
 +    buf.add_last '\n';
 +  );
 +
 +  - generate_type_globals_for t:TYPE in buf:STRING <-
 +  (
 +    (t.type_c = NULL).if {
 +      buf.append "private static ";
 +      append_type_name_for t in buf;
 +      buf.add_last ' ';
 +      append_type_expanded_proto_name_for t in buf;
 +      buf.append "=new ";
 +      append_type_name_for t in buf;
 +      buf.add_last '(';
 +      t.is_late_binding.if {
 +        append_type_typeid_name_for t in buf;
 +      };
 +      buf.append ");\n";
 +    };
 +
 +  );
 +
 +  - 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;
 +    //not_yet_implemented;
 +    buf.add_last '.';
 +    buf.append (read.variable.intern_name);
 +  );
 +
 +  - generate_write_slot_for write:WRITE_SLOT in buf:STRING <-
 +  (
 +    // Receiver.
-     (write.quiet_generation).if {
-       buf.append "/* WRTOK */";
-     } else {
-       buf.append "/* WRTNO */";
-     };
 +    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;

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list