|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Abstract Data TypesHi,
possibly repeating myself, I want to emphasise the fact that information hiding and encapsulation has been applied relatively well in the Aldor compiler. Unfortunately, there are also many violations. First, I would like to show how data abstraction is achieved within the compiler source. As a case study, I will explain how it does so with the Buffer and String datatypes. The Buffer type is used as a serialisation target. Most notably, it is used in byte code storage. Aldor Object files (.ao) contain platform independent byte code. This independence is achieved by using the bufXXX functions. A Buffer is represented by a record containing its data pointer, its current position and its current capacity. The String type is used for text. The file 'strops.h' defines several operations on this type. It also defines a function that can create a String object from a C string literal or a 'char*'. A String is represented by its data pointer. When operating on Buffer objects, the code mostly uses dedicated functions or macros. In some places, however, it does not do so. Instead, it operates directly on the pointee and its internal representation. In almost all cases, unnecessarily. The size of a Buffer is defined as being its current capacity. Buffer's member variable 'argc' represents this attribute. The 'bufSize' macro abstracts this knowledge away. I changed all such direct accesses to macro calls, so now there are no more direct struct member accesses. I want to do this with some more structures, but I ran into trouble while doing that before. Suddenly, things started breaking. I am doing it step by step, very slowly, to improve the compiler code without breaking it. The String object used in the aldor compiler uses a lot of knowledge about its actual representation. There is pointer arithmetic, assignment of C string literals to String objects, index operations, all of which are not possible without knowing that String is actually char*. By abstracting this knowledge away, one opens a lot of room for self checking, flow graphing, diagnostics and even optimisation of the compiler itself. My question now is, should I make String abstract and extend information hiding to this type of objects? What would be disadvantages of such a major change? You may also want to read: http://xinutec.org/~pippijn/en/programming_data-hiding.xhtml http://xinutec.org/~pippijn/en/programming_c_strings.xhtml Pippijn _______________________________________________ Aldor-l mailing list Aldor-l@... http://aldor.org/mailman/listinfo/aldor-l_aldor.org |
| Free embeddable forum powered by Nabble | Forum Help |