DEADSOFTWARE

Что-то там тестировалось с массивами...
[dsw-obn.git] / generator.c
index e4970fd995b0e5af87d12cb93f5c6d36bfe24359..673ac3381818c09270f17e002b26b8d1b29ad24c 100644 (file)
@@ -79,6 +79,23 @@ oberon_generator_init_type(oberon_context_t * ctx, oberon_type_t * type)
        {
                gcc_type = gcc_jit_context_get_type(gcc_context, GCC_JIT_TYPE_BOOL);
        }
+       else if(type -> class == OBERON_TYPE_ARRAY)
+       {
+               gen_type_t * gen_base = type -> base -> gen_type;
+               gcc_jit_type * gcc_base = gen_base -> gcc_type;
+               gcc_type = gcc_jit_context_new_array_type(gcc_context, NULL, gcc_base, type -> size);
+       }
+       else if(type -> class == OBERON_TYPE_RECORD)
+       {
+               gcc_struct = gcc_jit_context_new_opaque_struct(gcc_context, NULL, "");
+               gcc_type = gcc_jit_struct_as_type(gcc_struct);
+       }
+       else if(type -> class == OBERON_TYPE_POINTER)
+       {
+               gen_type_t * gen_base = type -> base -> gen_type;
+               gcc_jit_type * gcc_base = gen_base -> gcc_type;
+               gcc_type = gcc_jit_type_get_pointer(gcc_base);
+       }
        else if(type -> class == OBERON_TYPE_PROCEDURE)
        {
                int num_params = type -> num_decl;
@@ -98,45 +115,42 @@ oberon_generator_init_type(oberon_context_t * ctx, oberon_type_t * type)
                        gcc_context, NULL, result_type, num_params, params, 0
                );
        }
-       else if(type -> class == OBERON_TYPE_ARRAY)
-       {
-               if(type -> dim != 1)
-               {
-                       oberon_error(ctx, "multidimension and open arrays not supported");
-               }
-               
-               gen_type_t * gen_base = type -> base -> gen_type;
-               gcc_jit_type * gcc_base = gen_base -> gcc_type;
-
-               gcc_type = gcc_jit_context_new_array_type(gcc_context, NULL, gcc_base, type -> size);
-       }
-       else if(type -> class == OBERON_TYPE_RECORD)
-       {
-               // TODO type exstension
-
-               int num_fields = type -> num_decl;
-               gcc_jit_field * fields[num_fields];
-               oberon_object_t * o = type -> decl;
-               for(int i = 0; i < num_fields; i++)
-               {
-                       assert(o -> class == OBERON_CLASS_FIELD);
-                       gen_var_t * var = o -> gen_var;
-                       fields[i] = var -> gcc_field;
-                       o = o -> next;
-               }
-
-               gcc_struct = gcc_jit_context_new_struct_type(gcc_context, NULL, "", num_fields, fields);
-               gcc_type = gcc_jit_struct_as_type(gcc_struct);
-       }
        else
        {
                oberon_error(ctx, "oberon_generator_init_type: invalid type class %i", type -> class);
        }
 
+       assert(gcc_type);
        gen_type -> gcc_type = gcc_type;
        gen_type -> gcc_struct = gcc_struct;
 }
 
+void
+oberon_generator_init_record(oberon_context_t * ctx, oberon_type_t * type)
+{
+       assert(type -> class == OBERON_TYPE_RECORD);
+
+       gen_type_t * gen_type = type -> gen_type;
+       gcc_jit_struct * gcc_struct = gen_type -> gcc_struct;
+
+       // TODO type exstension
+
+       int num_fields = type -> num_decl;
+       gcc_jit_field * fields[num_fields];
+       oberon_object_t * o = type -> decl;
+       for(int i = 0; i < num_fields; i++)
+       {
+               assert(o -> class == OBERON_CLASS_FIELD);
+               gen_var_t * var = o -> gen_var;
+               fields[i] = var -> gcc_field;
+               o = o -> next;
+       }
+
+       gcc_jit_struct_set_fields (gcc_struct, NULL, num_fields, fields);
+
+       //gcc_struct = gcc_jit_context_new_struct_type(gcc_context, NULL, "", num_fields, fields);
+}
+
 void
 oberon_generator_init_var(oberon_context_t * ctx, oberon_object_t * var)
 {