adda/translate/oop'ish return param's:
2.6:
. to promote a system that includes both exceptions
and that simplifies garbage collection for functions,
all adda functions should be impl'd as procedures
in which one of the param's is expecting a pointer to
where the return should go .
. any function f:x->y
is translated in c, then,
to f: (x, rtn.ptr.out) -> exception code .
2.13:
. a common problem found in oop lang's,
is keeping track of who's responsible for
deallocating an object;
the primary reason for this is an efficiency trick:
. every oop value is, for the sake of modularity,
represented by a dynamically allocated obj'
(a pointer out to some place on the heap) .
. when wanting to send a value,
the modular way is to copy the value,
and send that copy's pointer;
but the efficient way is to minimize copying of values,
by copying and sending pointers
so there are multiple pointers
sharing the same obj' representing a value .
. however,
now there has to be a system for knowing
whether an obj' is being shared or not;
because if it's not, and you have the only pointer to an obj'
then you should deallocate the obj'
before you dealocate your pointer to it .
. conversely, if the obj' is being shared,
then it's important that you not dealocate the obj'
because that would leave its other pointers dangling .
. another source of sharing is not efficiency
but just because the routine way to operate
is to have a function accept 1 or more arg's
and then return a value to some other obj' .
. to avoid this case of unnecessary sharing
a function that is not sharing
should indicate so requesting one of the parameters be
a pointer to an obj' owned by the caller,
so then the caller knows in this case
that it owns the obj',
and will be the one to deallocated it .
. yet another cause of uncontroled dealloc's
is when the function is returning the value to an assignment,
which in many bolt-on versions of oop,
means the function is wiping out a pointer
that the assignment's destination.obj was already holding .
. the way around this is to not use the usual
assignment.stmt(dstination.out, src.in)
and instead have each type`mgt
define its own assignment dstination.INout, src.in)
which asks that the param' for the destination obj'
be of mode inout so that
not only can the destination be written to,
but it can also be read, and with that reading,
the destination's current pointer can be deallocated by
the assignment operator .
2.14:
. it would be a lot easier to get more out a c compiler
if adda functions did translate to
similar functions in c .
. there does need to be a param
for caller to say where to put the return;
but, the retun should be passed by return vs out.mode param .
. a recent note thought exceptions could be done through the return,
but prior notes had ways that used globals .
2010-02-28
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment