Code Generation: Variable declaration: --------------------------------------------------- Eiffel: a_int:INTEGER Generated C: unsigned int tmp = get_class_id("INTEGER"); unsigned int tmp1 = get_new_object_id(); object_info * mec_a_int = get_new_object(tmp,tmp1); Routine Definition --------------------------------------------------- Eiffel: a_routine is ... ... end Generated C: object_info * a_routine(){ ... ... return MEC_VOID; } Description: Every feature is represented as a function at the C level. Since a routine does not return a value in Eiffel, in C it will return void. Note that in Eiffel analysis code such as a:=routine will be detected. Function Definition --------------------------------------------------- Eiffel: a_function:STRING is do ... ... end Generated C: object_info * a_function(){ ... ... } Description: Although the type of the function and its parameters are lost in the c code, it is stored in the Class structure. Attribute Definition --------------------------------------------------- Eiffel: a_attribute:INTEGER Generated C: object_info * mec_a_attribute; object_info * a_attribute(){ return mec_a_attribute; } Description: The mec_a_attribute is a private field. The value is always retrieved via the function call. Constant Definition --------------------------------------------------- Eiffel: a_constant:INTEGER is 10 Generated C: object_info * mec_a_constant; object_info * a_constant(){ if (mec_a_constant==null){ mec_a_constant = create_integer_constant (10); } return mec_a_constant; } Description: A constant is an attribute with the value initialized to 10. Unqualified Call --------------------------------------------------- Eiffel: print_text Generated C: unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "print_text"); MEC_function * tmp3 = create_mec_function(tmp1); object_info * tmp4 = run_function(tmp3); Description: At the moment the function is executed by the run-time system so that it can do some checking on the parameter types, handle exceptions and so on. But in the future more code should be generated to handle these issues. Unqualified Call with parameter --------------------------------------------------- Eiffel: print_text (str) Generated C: unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "print_text"); MEC_function * tmp3 = create_mec_function(tmp1); add_parameter(tmp3,str); object_info * tmp4 = run_function(tmp3); Description: Qualified Call --------------------------------------------------- Eiffel: a.b.print_text Generated C: // Get object a tmp4 unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "a"); MEC_function * tmp3 = create_mec_function(tmp1); object_info * tmp4 = run_function(tmp3); // Get object b tmp8 unsigned int tmp5 = get_object_dynamic_type_id(tmp4); unsigned int tmp6 = get_function_id(tmp5, "b"); MEC_function * tmp7 = create_mec_function(tmp6); object_info * tmp8 = run_function(tmp7); // get print_text unsigned int tmp9 = get_object_dynamic_type_id(tmp8); unsigned int tmp10 = get_function_id(tmp9, "print_text"); MEC_function * tmp11 = create_mec_function(tmp10); // Run print_text object_info * tmp12 = run_function(tmp11); Description: Every field is a function. Thus, we have to create a function representation to get the object back and derive its type in order to lookup for the next field (function) If print_text had parameters they could be added just before the run_function was called. Constant Assignment --------------------------------------------------- Eiffel: a := "Hello" Generated C: // Get object a tmp4 unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "a"); MEC_function * tmp3 = create_mec_function(tmp1); object_info * tmp4 = run_function(tmp3); object_info * tmp5 = create_string_constant ("Hello"); MEC_assign(tmp4,tmp5); Description: The constant is transformed into an object for the assignment. Object Assignment --------------------------------------------------- Eiffel: a := b Generated C: // Get object a tmp4 unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "a"); MEC_function * tmp3 = create_mec_function(tmp1); object_info * tmp4 = run_function(tmp3); // Get object b tmp4 unsigned int tmp5 = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp6 = get_function_id(tmp5, "b"); MEC_function * tmp7 = create_mec_function(tmp6); tmp8 = run_function(tmp7); MEC_assign(tmp4,tmp8); Description: Note that there is a lot of optmizations that can be done. But at the moment it is not being considered. Unqualified Call Assignment --------------------------------------------------- Eiffel: a := get_text Generated C: same as above... Description: Since a field is representad as a function the generated code will be tha same with exception of the get_function_id(tmp5, "get_text"); Qualified Call Assignment --------------------------------------------------- Eiffel: c := a.b.get_text Generated C: // Get object a tmp4 unsigned int tmp = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp1 = get_function_id(tmp, "a"); MEC_function * tmp3 = create_mec_function(tmp1); tmp4 = run_function(tmp3); // Get object b tmp8 unsigned int tmp5 = get_object_dynamic_type_id(tmp4); unsigned int tmp6 = get_function_id(tmp5, "b"); MEC_function * tmp7 = create_mec_function(tmp6); tmp8 = run_function(tmp7); // get print_text unsigned int tmp9 = get_object_dynamic_type_id(tmp8); unsigned int tmp10 = get_function_id(tmp9, "print_text"); MEC_function * tmp11 = create_mec_function(tmp10); // Run print_text tmp12 = run_function(tmp11); // Get object c unsigned int tmp13 = get_object_dynamic_type_id(MEC_THIS); unsigned int tmp14 = get_function_id(tmp13, "a"); MEC_function * tmp15 = create_mec_function(tmp14); tmp16 = run_function(tmp15); MEC_assign(tmp15,tmp12); // tmp15 is C and tmp12 is the result of get_text Description: At the end of the Qualified call we will have a variable holding the value of the result. This variable is then assigned to our target variable c. Solution for the built-in functions. The system shall include a built_in.h file that contains the built in functions. The operators shall be mapped to a long name which will be used by the compiler. Unary not | + | - Binary + | - | * | / | < | > | <= | >= | // | \\ | ^ | and | or | xor | and then | or else | implies