[M3devel] opaque types again
Jay K
jay.krell at cornell.edu
Sun Mar 31 07:10:00 CEST 2013
I don't understand opaque types.
I do understand the notion of fully opaque types. That are fully revealed in one step.
In C this is common:
window.h
struct Window_t;
typedef struct Window_t Window_t;
Window_t* Window_Create();
void Window_Show(Window_*t);
void Window_Close(Window_*t);
long Window_GetHeight(Window_*t);
long Window_GetWidth(Window_*t);
etc.
window.c
struct Window_t { ... } /* reveal */
Back to Modula-3... opaque types must be OBJECTs, right?
1. What do they provide vs. more derived types?
INTERFACE Animal;
TYPE T = OBJECT
METHODS
makeNoise();
END;
INTERFACE AnimalImpl;
TYPE T = Animal.T OBJECT
METHODS
private();
END;
If I had an Animal.T and wanted to call private(),
wouldn't I just NARROW it to AnimalImpl.T?
Is the point that it is more efficient and avoids
a runtime type check?
INTERFACE Animal;
TYPE Public = OBJECT
METHODS
makeNoise();
END;
TYPE T <: Public;
INTERFACE AnimalImpl;
REVEAL Animal.T = Animal.Public OBJECT
METHODS
private();
END;
?
This way I can import AnimalImpl and then just call private()
without a NARROW?
2. Given that the final revelation must be a linear
form of all the declared subtypes, I don't understand
how the offset used by any module w/o a full revelation
could be anything other than zero.
I'd like to fully understand this, so I can make the C backend
provide maximal type information. More pointers to structs, with members/fields,
fewer untyped void*/char*.
Thanks,
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20130331/698fe7c6/attachment-0001.html>
More information about the M3devel
mailing list