About the Generated C Code



People who want or have to code part of their applications and/or libraries in C should really limit themselves to the clean interfaces provided by Cecil or the external mechanism. This page mentions some facts you should be aware of before you start.

Generated Type Identifiers

First and above all, SmartEiffel generates one unique numeric identifier for each living type1 present in the Eiffel code. A lot of symbols in the generated C code depend on that identifier.

Don't depend on those identifiers! The mangling table is only valid for one specific compilation of one specific application with one specific compiler version and specific libraries...

If xyz is the identifier, then:

Some characters in method names such as "<" or "+" will be replaced with relative ASCII number written as decimal.

For example: STRING has the indentifier 72. Then:

When you compile your application, you can find those identifiers in a file name after the name of the root class, suffixed by .id; the file is structured in entries, each entry being separated from others by a hash character ('#'). This file looks like this:
4 "REAL"
#
12 "HELLO_WORLD"
class-path: "./hello_world.e"
class-name: HELLO_WORLD
parent-count: 0
c-type: T12 reference: yes
ref-status: live id-field: yes 
run-time-set-count: 1
run-time-set:
        HELLO_WORLD (12)
#
9 "NATIVE_ARRAY[CHARACTER]"
class-path: "/lib/se/lib/kernel/native_array.e"
class-name: NATIVE_ARRAY
parent-count: 1 parents: 26
c-type: T9 reference: no
#
21 "COMPARABLE"
class-path: "/lib/se/lib/kernel/comparable.e"
class-name: COMPARABLE
parent-count: 1 parents: 13
#
. . .

You must not depend on the indentifiers values. Indeed, when computing an identifier, collisions may occur, and affect this process. Thus, the number (and name) corresponding to each type depends not only on the type name, but also on the order in which they are compiled. That is, on the application and libraries compiled... They also depend on the compilation mode used, and the version of the compiler you're using. So what is T145 now may become T234 the next time you compile...3

Consequently, do not, ever, rely on the type numbers in the generated C code, because they are not constant! (Except for a few ones which have a fixed, hard-coded name). So don't bother writing in your own C code things such as new123 or T456, because the only thing we guarantee in this case is that your code shall break someday.

The Naming Convention

The previous chapter explains how method names are generated. r7append prototype presented above as void r7append(se_dump_stack*caller,T7* C,T0* a1); shows Current and argument cases. Rules are as follow:

The Mangling Table

OK, so now you understand why you cannot use type numbers, but you still want to know what those things in the mangling table mean. :-)

First, a big caveat. Although it hasn't changed a lot and has been very stable for quite some time now, the mangling table coding may change in the future! We currently have no plans to change it, and we prefer keeping it the way it is. But once again, we do not commit ourselves to the current representation.

Let's look again at the extract of a .id file. The shown part covers quite all the possible cases:

4 "REAL"
#
12 "HELLO_WORLD"
class-path: "./hello_world.e"
class-name: HELLO_WORLD
parent-count: 0
c-type: T12 reference: yes
ref-status: live id-field: yes 
run-time-set-count: 1
run-time-set:
        HELLO_WORLD (12)
#
9 "NATIVE_ARRAY[CHARACTER]"
class-path: "/lib/se/lib/kernel/native_array.e"
class-name: NATIVE_ARRAY
parent-count: 1 parents: 26
c-type: T9 reference: no
#
21 "COMPARABLE"
class-path: "/lib/se/lib/kernel/comparable.e"
class-name: COMPARABLE
parent-count: 1 parents: 13
#
. . .

There is one entry per type (live or not); each entry spans on many lines and finished by a hash symbol ('#').

Each entry comprises many informations. All of them are not always present (in that case, they have default values). Only the first line is compulsory.

The first line contains the type number, and its name (as would return generating_type).

The next lines contain different fields, marked as a keyword, a colon and a value. There may be one or more fields on one line. Those fields are:

class-path The path to the file containing the source of the class. May be omitted if the class has no associated file (e.g., TUPLE or PROCEDURE).
class-name The name of the class, as would return generator.
parent-count The number of parents.
parents On the same line as parent-count if the latter is not null; it gives the parent class identifiers.
c-type The C type, usually in the form Txyz. If omitted, the class has no runnable type.
In that case, the following fields do not appear either.
reference On the same line as c-type, yes for a reference type or no for an expanded type.
ref-status Either live for a living type (i.e. whether instances of this type are ever created at run-time), or dead otherwise.
id-field On the same line as ref-status, yes if the id field is in the generated C structure (as its first element), no otherwise. This field is present if one of these confitions is true:
  • some late binding may occur on targets of that type,
  • or the struct may be accessed by external or Cecil code.
Note that a lot of calls are statically computed; the type inference algorithm used in SmartEiffel increases the number of such types that don't need the id field.
run-time-set-count The number of concrete, live descendants of the type (including itself). It is thus the number of items in the run-time-set below.
run-time-set Contains the live heirs with their identifier. There is one such class per line.
The Dump Stack

When not in boost mode, a stack is managed by the SmartEiffel runtime. This stack can be displayed when an exception not caught is raised. It is also used by the debugger (sedb).

Technically, the SmartEiffel stack is built upon the native (C) stack. It is a se_dump_stack4 usually allocated on the stack. It is made up of several parts:

One macro handles the linking and unlinking of the dump stack frames by setting the caller field of the dump stack top, then changing that top.
The Basic Subsystem

That "basic" subsystem is used by SmartEiffel libraries to provide, at the same time, facility of extension and independance from the backend (C, Java).

Features named basic_something and declared as external "SmartEiffel" are handled by the basic subsystem.

The naming scheme is thus:

feature

   basic_topic_my_feature(args) is
      external "SmartEiffel"
      end

The C backend5 will then search for basic_topic.c and basic_topic.h (those found will be included in good place, one in the generated .c, other in the .h). In those files, a function (or a macro) must be named basic_topic_my_feature() (like the Eiffel feature), and accept the same arguments as its Eiffel counterpart (that is, written the C way). Current is never passed.

Indeed this is a kind of "plugin" system for the SmartEiffel libraries. Some extensions may be foreseen in the future.

For some examples, one may look at BASIC_DIRECTORY and so on.

Notes

1

There is a bijection between the number and the name of the type, including its parameters in the case of generic types. (My_Feature details about this in our research papers).

2

There are some identifiers that are reserved for "basic" types. They are: The root class of the system will then have the 12. Don't rely on that, though (before all those INTEGERs revolution, it was 11).

3

The compiler will do its best not to change the identifiers uselessly. The .id file is loaded at the beginning of the compilation process, and saved again at its end. But clean erases that file.

4

You may find the definition of those structures in the SmartEiffel/sys/runtime/c/no_check.h file.

5

The Java backend is similar. It looks for the class fr.loria.SmartEiffelBasicTopic and the static function basic_topic_my_feature() with the arguments quite similar to the C ones.

[Line]
Copyright © Dominique COLNET and Suzanne COLLIN - <SmartEiffel@loria.fr>
Last modified: Thu Jun 12 10:50:08 CEST 2003