2010-02-28

generics

adda/generics:

2.2:
. what does ada's generic look like as c code?
it's typically a function call that returns a subprogram:
. subGenericInstance`= genericSub(instantiation param's)
. it's setting parameters that will be used by
every subsequent call to subGenericInstance .
. when the generic's param is of type "(type),
that is translated using the fact that
types can be expressed as a collection of pointers to
the operations that impl' that type .
eg, if there exists genericSub(number.type)
then the actual param can be any type that
supports the bi'ops {+, -, *, /}
and the uni'ops {-, /} .
caveat:
. ada generics, due to efficiency concerns,
likely involve some additional semantics .

2.4: translation to c:
. generics can be instantiated numerous times;
each instantiation means setting up a record
containing pointers to generic's instantiation arg's,
and then passing that record with each call to genericInstanceSub(x) .
. say the record would be called [generic instantiation#n's arg's],
then each call would be:
genericInstanceSub([generic instantiation#n's arg's], x) .

2.6:
. if the generic is a package instead of a sub',
then it practically means
the package includes both its own components
plus its generic instantiation record .

2.6:
. a generic instantiation is considered to be first-class,
when it can be treated like any other subprogram;
for this to occur,
a sub', which is usually represented by a pointer,
must include along with that pointer,
a tag indicating whether it's nested,
and whether it's generic
(each means 1bit of the tag) .
--. if c has some restrictions about function typing,
then all dynamic functions can be impl'd as
unary or binary operations over etree .

2.4:
. one of the struct's fields is a pointer to a callable generic .
. this is not really needed because it's statically known
but part of supporting reflection is that
instead of there being just function pointers,
there is an id bundled with the pointer
so that the program has access to the name of a function
along with details known statically about the function
like its signature (req'd param`types, and provided output`types) .
. along with a function'id is the environ.ptr,
for cases where the function is declared nested .
. the generics.ptr
-- for cases where the function is generic --
is pointing at the generic's instantiation record .

how does adda define a generic?
they are functions returning some cstr,
typically a function .
their param's can include types (sets of function ptrs) .
eg,
G(T).(X).Y; -- G is a generic returning a sub' of type (X).Y
f(x).y: G(t) . -- f is a constant function
defined as an instantiation of G .
neat.type: (x).y; -- "(neat) is a constant type name for (x).y .
G(T).neat; -- G returns a function of type neat .
f.neat: G(t) -- f is a constant function
defined as an instantiation of G .

. to become familiar with subtleties of generics,
need to see examples of them in c++ and ada .

No comments:

Post a Comment