[SCM] Lisaac compiler branch, mildred-backend, updated. lisaac-0.12-434-g3ee9ebf
Mildred Ki'Lya
silkensedai at online.fr
Fri Aug 7 12:08:53 UTC 2009
The following commit has been merged in the mildred-backend branch:
commit 9f458962647d760baa6a20b1f01820495051f4b8
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date: Thu Aug 6 22:59:45 2009 +0200
Generate type definitions in BACKEND
diff --git a/src/tools/backend.li b/src/tools/backend.li
index ac0fa59..c90a775 100644
--- a/src/tools/backend.li
+++ b/src/tools/backend.li
@@ -47,9 +47,12 @@ Section Public
buf.add_last '\'';
);
+ - generate_type_typedef_for t:TYPE in buf:STRING <- deferred;
+ - 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_context_in buf:STRING <- deferred;
- append_escaped_character c:CHARACTER in buf:STRING <-
(
diff --git a/src/tools/backend_c.li b/src/tools/backend_c.li
index bab552a..0716834 100644
--- a/src/tools/backend_c.li
+++ b/src/tools/backend_c.li
@@ -33,4 +33,196 @@ Section Inherit
Section Public
+ - generate_type_typedef_for t:TYPE in buf:STRING <-
+ (
+ output_decl.append "typedef ";
+ (t.type_c != NULL).if {
+ output_decl.append (t.type_c);
+ } else {
+ output_decl.append "struct ";
+ output_decl.append (t.intern_name);
+ output_decl.append "_struct";
+ };
+ output_decl.append " __";
+ output_decl.append (t.intern_name);
+ output_decl.append ";\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 <-
+ ( + slot_data:SLOT_DATA;
+ + tab:FAST_ARRAY[SLOT_DATA];
+ + num_slots :INTEGER;
+
+
+ //
+ // Type C
+ //
+
+ (t.type_c != NULL).if {
+ // Define __TRUE and __FALSE constants
+ (is_java).if_false {
+ ((t.shortname = ALIAS_STR.prototype_true) ||
+ {t.shortname = ALIAS_STR.prototype_false}).if
+ {
+ buf.append "#define ";
+ buf.append (t.intern_name);
+ buf.append "__ ";
+ buf.add_last ((t.shortname = ALIAS_STR.prototype_true).to_character);
+ buf.add_last '\n';
+ };
+ };
+
+
+ //
+ // Lisaac defined type
+ //
+
+ } else {
+
+ //
+ // Comment
+ //
+ buf.append "// ";
+ buf.append (t.intern_name);
+ buf.add_last '\n';
+
+ //
+ // Type ID
+ //
+ (is_java).if {
+ buf.append "static private int __";
+ buf.append (t.intern_name);
+ buf.append "__ = ";
+ } else {
+ buf.append "#define __";
+ buf.append (t.intern_name);
+ buf.append "__ ";
+ };
+ t.is_late_binding.if {
+ TYPE.generate_id_with_type.append_in buf;
+ } else {
+ TYPE.generate_id_without_type.append_in buf;
+ };
+ (is_java).if {
+ buf.add_last ';';
+ };
+ buf.add_last '\n';
+
+ //
+ // Start the struct declaration
+ //
+ buf.append "struct ";
+ buf.append (t.intern_name);
+ buf.append "_struct {\n";
+
+ //
+ // Generate extra slots before data slots
+ // - for COP
+ // - type_id for late binding
+ //
+ (t.prototype.style = '-').if {
+ buf.append " lith_object thread;\n";
+ (t.param_count != 0).if {
+ 1.to (t.param_count) do { n:INTEGER;
+ buf.append " int param_";
+ (n-1).append_in buf;
+ buf.append ";\n";
+ num_slots := num_slots + 1;
+ };
+ };
+ }.elseif {t.is_late_binding} then {
+ string_tmp.append " unsigned long __id;\n";
+ num_slots := num_slots + 1;
+ };
+
+ //
+ // Generate data slots ordered by size
+ //
+ ? { t.slot_size.upper = 4 };
+ ? { t.slot_size.lower = 0 };
+ (t.slot_size.upper).downto (t.slot_size.lower) do { j:INTEGER;
+ tab := t.slot_size.item j;
+ (tab.lower).to (tab.upper) do { i:INTEGER;
+ slot_data := tab.item i;
+ ((t.prototype.is_mapping) && {slot_data.type.is_expanded_c}).if {
+ buf.append " volatile ";
+ } else {
+ buf.append " ";
+ };
+ slot_data.genere buf;
+ num_slots := num_slots + 1;
+ };
+ tab.clear;
+ };
+
+ //
+ // Generate extra slots after data slots
+ // - for BLOCK
+ // - dummy slot if no slots were generated
+ //
+ (t = type_block).if {
+ buf.append " void *self;\n";
+ num_slots := num_slots + 1;
+ };
+ (num_slots == 0).if {
+ buf.append " void *Nothing;\n";
+ };
+
+ //
+ // End structure declaration
+ //
+ (t.prototype.is_mapping).if {
+ buf.append "} __attribute__ ((packed));\n";
+ } else {
+ buf.append "};\n";
+ };
+ };
+ );
+
+
+ - generate_type_globals_for t:TYPE in buf:STRING <-
+ (
+ (t.type_c = NULL).if {
+ buf.append "__";
+ buf.append (t.intern_name);
+ buf.add_last ' ';
+ buf.append (t.intern_name);
+ buf.add_last '_';
+ t.is_late_binding.if {
+ buf.append "={__";
+ buf.append (t.intern_name);
+ buf.append "__}";
+ };
+ buf.append ";\n";
+ buf.append "#define ";
+ buf.append (t.intern_name);
+ buf.append "__ (&";
+ buf.append (t.intern_name);
+ buf.append "_)\n\n";
+ };
+
+ );
+
+
diff --git a/src/tools/backend_java.li b/src/tools/backend_java.li
index ac4c7ea..82dc053 100644
--- a/src/tools/backend_java.li
+++ b/src/tools/backend_java.li
@@ -34,4 +34,209 @@ Section Inherit
Section Public
+ - generate_type_typedef_for t:TYPE in buf:STRING <-
+ (
+ BACKEND_C.generate_type_typedef_for t in buf;
+ );
+
+ - 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 <-
+ ( + slot_data:SLOT_DATA;
+ + tab:FAST_ARRAY[SLOT_DATA];
+ + count_slot:SLOT_DATA;
+ + storage_slot:SLOT_DATA;
+ + num_slots :INTEGER;
+
+
+ //
+ // Type C
+ //
+
+ (t.type_c != NULL).if {
+ // Define __TRUE and __FALSE constants
+ // No need to do that for Java code
+
+ //
+ // Lisaac defined type
+ //
+
+ } else {
+
+ (t.prototype.is_mapping).if {
+ semantic_error (t.position,
+ "Mapping is not yet implemented for Java code.");
+ };
+
+ //
+ // Comment
+ //
+ buf.append "// ";
+ buf.append (t.intern_name);
+ buf.add_last '\n';
+
+ //
+ // Type ID
+ //
+ buf.append "static private int __";
+ buf.append (t.intern_name);
+ 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';
+
+ //
+ // Start the class declaration
+ //
+ buf.append "static class __";
+ buf.append (t.intern_name);
+ t.is_late_binding.if {
+ buf.append " extends __OBJ";
+ };
+ buf.append " {\n";
+
+ //
+ // Generate extra slots before data slots
+ // - for COP
+ // - type_id for late binding
+ //
+ (t.prototype.style = '-').if {
+ buf.append " lith_object thread;\n";
+ (t.param_count != 0).if {
+ 1.to (t.param_count) do { n:INTEGER;
+ buf.append " int param_";
+ (n-1).append_in buf;
+ buf.append ";\n";
+ num_slots := num_slots + 1;
+ };
+ };
+ }.elseif {t.is_late_binding} then {
+ buf.append " unsigned long __id;\n";
+ num_slots := num_slots + 1;
+ };
+
+ //
+ // Generate data slots ordered by size
+ //
+ ? { t.slot_size.upper = 4 };
+ ? { t.slot_size.lower = 0 };
+ (t.slot_size.upper).downto (t.slot_size.lower) do { j:INTEGER;
+ tab := t.slot_size.item j;
+ (tab.lower).to (tab.upper) do { i:INTEGER;
+ slot_data := tab.item i;
+ ((t.prototype.is_mapping) && {slot_data.type.is_expanded_c}).if {
+ buf.append " volatile ";
+ } else {
+ buf.append " ";
+ };
+ slot_data.genere buf;
+ num_slots := num_slots + 1;
+ };
+ tab.clear;
+ };
+
+ //
+ // Generate extra slots after data slots
+ // - for BLOCK
+ // - dummy slot if no slots were generated
+ //
+ (t = type_block).if {
+ buf.append " void *self;\n";
+ num_slots := num_slots + 1;
+ };
+ (num_slots == 0).if {
+ buf.append " void *Nothing;\n";
+ };
+
+ //
+ // 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 __";
+ buf.append (t.intern_name);
+ 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 __";
+ buf.append (t.intern_name);
+ 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_globals_for t:TYPE in buf:STRING <-
+ (
+ (t.type_c = NULL).if {
+ buf.append "private static __";
+ buf.append (t.intern_name);
+ buf.add_last ' ';
+ buf.append (t.intern_name);
+ buf.append "_=new __";
+ buf.append (t.intern_name);
+ buf.add_last '(';
+ t.is_late_binding.if {
+ buf.append "__";
+ buf.append (t.intern_name);
+ buf.append "__";
+ };
+ buf.append ");\n";
+ };
+
+ );
diff --git a/src/type/type.li b/src/type/type.li
index eb12366..9fbffe4 100644
--- a/src/type/type.li
+++ b/src/type/type.li
@@ -344,6 +344,20 @@ Section Public
- id_counter_with_type:INTEGER := 4;
- id_counter_without_type:INTEGER := 0;
+
+ - generate_id_with_type :INTEGER <-
+ ( + res :INTEGER;
+ res := id_counter_with_type;
+ id_counter_with_type := id_counter_with_type + 1;
+ res
+ );
+
+ - generate_id_without_type :INTEGER <-
+ ( + res :INTEGER;
+ res := id_counter_without_type;
+ id_counter_without_type := id_counter_without_type + 1;
+ res
+ );
- slot_size:FAST_ARRAY[FAST_ARRAY[SLOT_DATA]] :=
( + result:FAST_ARRAY[FAST_ARRAY[SLOT_DATA]];
@@ -363,10 +377,13 @@ Section Public
+ tab:FAST_ARRAY[SLOT_DATA];
+ action:BLOCK;
+ tg:TYPE_GENERIC;
- + count_slot:SLOT_DATA;
- + storage_slot:SLOT_DATA;
-
- ((slot_run.is_empty) || {slot_run.first != NULL}).if {
+
+ ((slot_run.is_empty) || {slot_run.first != NULL}).if {
+
+ //
+ // Detect recursivity
+ //
+
(detect_recursivity_generation).if {
string_tmp.copy "Compiler limit: Cyclic depending structure definition for ";
append_name_in string_tmp;
@@ -374,298 +391,159 @@ Section Public
semantic_error (position,string_tmp);
};
detect_recursivity_generation := TRUE;
- // Depending.
+
+ //
+ // Depending (generate structs we require)
+ //
+
(slot_run.lower).to (slot_run.upper) do { j:INTEGER;
- slot := slot_run.item j;
- ((slot.style = '+') && {slot.lower_style = 0}).if {
+ slot := slot_run.item j;
+ ((slot.style = '+') && {slot.lower_style = 0}).if {
action := { s:SLOT_DATA;
- (
- (
- (s.ensure_count > 0) ||
- {s.id_section.is_mapping}
- ) &&
- {s.type.raw != Self} &&
- {(s.type.is_expanded) || {s.type.raw.is_block}}
- ).if {
- s.type.raw.genere_struct;
+ (
+ (
+ (s.ensure_count > 0) ||
+ {s.id_section.is_mapping}
+ ) &&
+ {s.type.raw != Self} &&
+ {(s.type.is_expanded) || {s.type.raw.is_block}}
+ ).if {
+ s.type.raw.genere_struct;
};
- };
- (slot.slot_data_list != NULL).if {
- (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
- action.value (slot.slot_data_list.item k);
- };
- };
- action.value (slot.slot_data);
- };
- };
- // Sort slot.
- (slot_run.lower).to (slot_run.upper) do { j:INTEGER;
- slot := slot_run.item j;
- (slot.style = '+').if {
- // In struct.
- (slot.lower_style = 0).if {
- action := { s:SLOT_DATA;
- (
- (s.id_section.is_mapping) ||
- {s.ensure_count > 0}
- ).if {
- add_slot_struct s;
- };
- };
- (slot.slot_data_list != NULL).if {
- (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
- action.value (slot.slot_data_list.item k);
- };
- };
- action.value (slot.slot_data);
- };
- slot_data := slot.slot_id;
- ((slot_data != NULL) && {slot_data.ensure_count > 0}).if {
- add_slot_struct slot_data;
- };
- } else {
- // In global.
- (slot.lower_style = 0).if {
- action := { s:SLOT_DATA;
- (s.ensure_count > 0).if {
- s.genere output_glob;
- };
- };
- (slot.slot_data_list != NULL).if {
- (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
- action.value (slot.slot_data_list.item k);
- };
- };
- action.value (slot.slot_data);
- };
- slot_data := slot.slot_id;
- ((slot_data != NULL) && {slot_data.ensure_count > 0}).if {
- slot_data.slot_id.genere output_glob;
- };
- };
- };
-
- (
- (prototype.shortname = ALIAS_STR.prototype_native_array) ||
- {prototype.shortname = ALIAS_STR.prototype_native_array_volatile}
- ).if {
- tg ?= Self;
- tg.generic_list.first.raw.genere_struct;
- } else {
- (type_c != NULL).if {
- 0.to 4 do { j:INTEGER;
- tab := slot_size.item j;
- // BSBS: A tester sont utilit� !
- (! tab.is_empty).if {
- semantic_error ((tab.first.position),"Slot is not possible with a type C");
- };
};
- (is_java).if_false {
- ((shortname = ALIAS_STR.prototype_true) ||
- {shortname = ALIAS_STR.prototype_false}).if {
- output_decl.append "#define ";
- output_decl.append intern_name;
- output_decl.append "__ ";
- output_decl.add_last ((shortname = ALIAS_STR.prototype_true).to_character);
- output_decl.add_last '\n';
- }.elseif {is_late_binding} then {
- semantic_error ((tab.first.position),"Late binding is not possible with a type C");
- };
- };
- } else {
- output_decl.append "// ";
- output_decl.append intern_name;
- output_decl.add_last '\n';
- (is_java).if {
- output_decl.append "static private int __";
- output_decl.append intern_name;
- output_decl.append "__ = ";
- } else {
- output_decl.append "#define __";
- output_decl.append intern_name;
- output_decl.append "__ ";
- };
- string_tmp.clear;
- (is_late_binding).if {
- id_counter_with_type.append_in output_decl;
- id_counter_with_type := id_counter_with_type + 1;
- (prototype.style != '-').if {
- string_tmp.append " unsigned long __id;\n";
+ (slot.slot_data_list != NULL).if {
+ (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
+ action.value (slot.slot_data_list.item k);
};
- (prototype.is_mapping).if {
- semantic_error ((prototype.position),
- "Late binding is not possible with `mapping' object.");
- };
- } else {
- id_counter_without_type.append_in output_decl;
- id_counter_without_type := id_counter_without_type + 1;
- };
- (is_java).if {
- output_decl.add_last ';';
};
- output_decl.add_last '\n';
- (prototype.style = '-').if {
- string_tmp.append " lith_object thread;\n";
- (param_count != 0).if {
- 1.to param_count do { n:INTEGER;
- string_tmp.append " int param_";
- (n-1).append_in string_tmp;
- string_tmp.append ";\n";
+ action.value (slot.slot_data);
+ };
+ };
+
+ //
+ // Sort slot. (whatever that might mean)
+ //
+
+ (slot_run.lower).to (slot_run.upper) do { j:INTEGER;
+ slot := slot_run.item j;
+ (slot.style = '+').if {
+ // In struct.
+ (slot.lower_style = 0).if {
+ action := { s:SLOT_DATA;
+ (
+ (s.id_section.is_mapping) ||
+ {s.ensure_count > 0}
+ ).if {
+ add_slot_struct s;
};
};
- };
- 4.downto 0 do { j:INTEGER;
- tab := slot_size.item j;
- (tab.lower).to (tab.upper) do { i:INTEGER;
- slot_data := tab.item i;
- ((prototype.is_mapping) && {slot_data.type.is_expanded_c}).if {
- string_tmp.append " volatile ";
- } else {
- string_tmp.append " ";
- };
- slot_data.genere string_tmp;
- };
- tab.clear;
- };
-
- (Self = type_block).if {
- string_tmp.append " void *self;\n";
- };
-
- (string_tmp.is_empty).if {
- string_tmp.append " void *Nothing;\n";
- };
-
- (is_java).if {
- output_decl.append "static class __";
- output_decl.append intern_name;
- (is_late_binding).if {
- output_decl.append " extends __OBJ";
- };
- output_decl.append " {\n";
- output_decl.append string_tmp;
- (prototype.is_mapping).if {
- semantic_error (position,"Mapping is not yet implemented for Java code.");
- };
- (Self = type_string_constant).if {
- // STRING_CONSTANT constructor.
- output_decl.append "\n public __";
- output_decl.append intern_name;
- output_decl.add_last '(';
- (is_late_binding).if {
- output_decl.append "int pid,";
- };
- storage_slot := get_local_slot (ALIAS_STR.slot_storage).slot_data_intern;
- count_slot := get_local_slot (ALIAS_STR.slot_count).slot_data_intern;
- (count_slot.ensure_count != 0).if {
- output_decl.append "int pcount,";
- };
- (storage_slot.ensure_count != 0).if {
- output_decl.append "String pstorage,";
- };
- output_decl.remove_last 1;
- output_decl.append ")\n {\n ";
- (is_late_binding).if {
- output_decl.append "__id = pid;\n";
+ (slot.slot_data_list != NULL).if {
+ (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
+ action.value (slot.slot_data_list.item k);
};
- (count_slot.ensure_count != 0).if {
- output_decl.append (count_slot.intern_name);
- output_decl.append " = pcount;\n";
- };
- (storage_slot.ensure_count != 0).if {
- output_decl.append (storage_slot.intern_name);
- output_decl.append " = pstorage.toCharArray();\n";
- };
- output_decl.append " };\n";
- };
- // Basic Constructor.
- output_decl.append "\n public __";
- output_decl.append intern_name;
- output_decl.add_last '(';
- (is_late_binding).if {
- output_decl.append "int pid";
- };
- output_decl.append ")\n {\n ";
- (is_late_binding).if {
- output_decl.append "__id = pid;\n";
- } else {
- output_decl.append "super();\n";
};
- output_decl.append " };\n};\n";
- } else {
- output_decl.append "struct ";
- output_decl.append intern_name;
- output_decl.append "_struct {\n";
- output_decl.append string_tmp;
- (prototype.is_mapping).if {
- output_decl.append "} __attribute__ ((packed));\n";
- } else {
- output_decl.append "};\n";
+ action.value (slot.slot_data);
+ };
+ slot_data := slot.slot_id;
+ ((slot_data != NULL) && {slot_data.ensure_count > 0}).if {
+ add_slot_struct slot_data;
+ };
+ } else {
+ // In global.
+ // Mildred: is that useful to iterate? The action seems empty
+ (slot.lower_style = 0).if {
+ action := { s:SLOT_DATA;
+ (s.ensure_count > 0).if {
+ };
};
- };
- // Prototype declaration.
- (is_java).if {
- output_glob.append "private static __";
- output_glob.append intern_name;
- output_glob.add_last ' ';
- output_glob.append intern_name;
- output_glob.append "_=new __";
- output_glob.append intern_name;
- output_glob.add_last '(';
- (is_late_binding).if {
- output_glob.append "__";
- output_glob.append intern_name;
- output_glob.append "__";
+ (slot.slot_data_list != NULL).if {
+ (slot.slot_data_list.lower).to (slot.slot_data_list.upper) do { k:INTEGER;
+ action.value (slot.slot_data_list.item k);
+ };
};
- output_glob.append ");\n";
- } else {
- output_glob.append "__";
- output_glob.append intern_name;
- output_glob.add_last ' ';
- output_glob.append intern_name;
- output_glob.add_last '_';
- (is_late_binding).if {
- output_glob.append "={__";
- output_glob.append intern_name;
- output_glob.append "__}";
+ action.value (slot.slot_data);
+ };
+ slot_data := slot.slot_id;
+ ((slot_data != NULL) && {slot_data.ensure_count > 0}).if {
+ };
+ };
+ };
+
+ //
+ // For NATIVE_ARRAY, only generate the generic type, don't bother
+ // to generate the struct for the NATIVE_ARRAY itself
+ //
+
+ ( // TODO: Mildred: don't use prototype name for detection
+ // Possibly, try to find a way to extend that to any prototype
+ (prototype.shortname = ALIAS_STR.prototype_native_array) ||
+ {prototype.shortname = ALIAS_STR.prototype_native_array_volatile}
+ ).if {
+ tg ?= Self;
+ tg.generic_list.first.raw.genere_struct;
+ } else {
+
+ //
+ // Detect errors
+ //
+
+ (type_c != NULL).if {
+ // Forbid data slots when C type is specified
+ 0.to 4 do { j:INTEGER;
+ tab := slot_size.item j;
+ // BSBS: A tester sont utilit� !
+ (! tab.is_empty).if {
+ semantic_error ((tab.first.position),"Slot is not possible with a type C");
};
- output_glob.append ";\n";
- output_glob.append "#define ";
- output_glob.append intern_name;
- output_glob.append "__ (&";
- output_glob.append intern_name;
- output_glob.append "_)\n\n";
};
- };
+ // Raise an error for C types that have a late binding
+ (is_late_binding &&
+ {shortname != ALIAS_STR.prototype_true} &&
+ {shortname != ALIAS_STR.prototype_false}).if
+ {
+ semantic_error (tab.first.position,
+ "Late binding is not possible with a type C");
+ };
+ } else {
+ ((is_late_binding) && {prototype.is_mapping}).if {
+ semantic_error ((prototype.position),
+ "Late binding is not possible with `mapping' object.");
+ };
+ };
+
+ //
+ // Generate code
+ //
+
+ backend.generate_type_struct_for Self in output_decl;
+ backend.generate_type_globals_for Self in output_glob;
+
};
-
- // Flag on:
+
+ // Flag on (don't generate twice the code)
slot_run.force NULL to 0;
- };
+ };
+
);
- genere_typedef <-
- ( + tg:TYPE_GENERIC;
-
- (
+ ( + tg:TYPE_GENERIC;
+
+ //
+ // For NATIVE_ARRAY, only generate the generic type typedef, don't bother
+ // to generate the typedef for the NATIVE_ARRAY itself
+ //
+
+ ( // TODO: Mildred: don't use prototype name for detection
+ // Possibly, try to find a way to extend that to any prototype
(prototype.shortname = ALIAS_STR.prototype_native_array) ||
{prototype.shortname = ALIAS_STR.prototype_native_array_volatile}
).if {
tg ?= Self;
tg.generic_list.first.raw.genere_typedef;
- } else {
- output_decl.append "typedef ";
- (type_c != NULL).if {
- output_decl.append type_c;
- } else {
- output_decl.append "struct ";
- output_decl.append intern_name;
- output_decl.append "_struct";
- };
- output_decl.append " __";
- output_decl.append intern_name;
- output_decl.append ";\n";
- };
+ } else {
+ backend.generate_type_typedef_for Self in output_decl;
+ };
);
Section Private
diff --git a/src/type/type_context.li b/src/type/type_context.li
index 5d57fb6..4e4f2d2 100644
--- a/src/type/type_context.li
+++ b/src/type/type_context.li
@@ -58,13 +58,6 @@ Section Public
- genere_struct <-
(
- output_decl.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";
+ backend.generate_type_struct_for_context_in output_decl;
);
\ No newline at end of file
diff --git a/src/type/type_null.li b/src/type/type_null.li
index a1cac69..27922ef 100644
--- a/src/type/type_null.li
+++ b/src/type/type_null.li
@@ -99,13 +99,7 @@ Section Public
- genere_struct <-
(
- (is_java).if_false {
- output_decl.append
- "// NULL\n\
- \#ifndef NULL\n\
- \#define NULL ((void *)0)\n\
- \#endif\n\n";
- };
+ backend.generate_type_struct_for_null_in output_decl;
);
//
--
Lisaac compiler
More information about the Lisaac-commits
mailing list