comp.lang.ada
 help / color / mirror / Atom feed
* Tasks, Entries, and Variables of a Class-wide type
@ 2010-11-01  5:40 Shark8
  2010-11-01  9:21 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: Shark8 @ 2010-11-01  5:40 UTC (permalink / raw)


I have a problem with tasks and class-wide types, namely the
dissallowance of entries returning a value (as a function would)
combined with the requirement that a variable of a class-wide type be
initialized before use.

The problem came up when I was writing a PostScript interpreter and,
implementing the PostScript type-system as a hierarchy of tagged
types, I wanted to be able so separate the parser from the actual
implementation so that it would be possible to have a single parser
service several PostScript interpreters (the state-machine/execution-
context/whatever-you-want-to-call-it).

I’d originally wanted to have something like this:

Task Type Parser_Task is
 Entry Parse( Input : in out String ) Return PostScript_Object’Class;
End Parser;

but that isn’t allowed, but hey, that’s ok because we have out
parameters. We just rearrange it so that we get:

Task Type Parser_Task is
 Entry Parse( Input : in out String; Object : Out
PostScript_Object’Class );
End Parser;

But this doesn’t work because in the calling-code a class-wide
variable needs to be initialized. {and a tag error is raised if you
try to assign an object with a differing tag to the variable}; so:

Declare
    Parser : Parser_Task;
    Some_Object : PostScript_Object’Class:= PostScript_Dummy_Object;
Begin
    Parser.Parse( “5”,  Some_Object ); – Makes Some_Object into a
PS_Integer w/ value of 5.
End;

is invalid because the tags won’t match. We now have the problem where
the class-wide type needs to know what particular object the parser
will return, and the parser needs that class-wide variable wherein to
store the type in the first place. {A programming Catch-22 or Chicken/
Egg problem}

I figured out how to work around this problem, however. Inside the
Parser_Task we can do something like the following:

Task body Parse_Task is
[...]
Accept Parse( Input : in out String; Object : Out
PostScript_Object’Class ) do
   Declare
      Temp : PostScript_Object’Class:= Parse_Function( Input );
     For Temp’Address use Output’Address;
   Begin
      Null;
   End;
End Parse;
[...]

So, now we’re left with the possible ramifications of overriding the
placement of our output variable. The only one that is immediately
obvious to me is that of the possibility of the original dummy class-
variable being over-written by an object that is actually larger.
(I.e. a null-record dummy-object being over written by an object
containing some data like a date/time stamp or somesuch.)

We *can* compensate with making the Dummy_Object object as large as
the largest object that Parser.Parse might return. But I am wondering
if I am missing something here.

{I’m assuming there are perfectly good reasons we can’t have free-
range class-wide types; like that of knowing how much memory to set
aside for the arbitrary and unknown object. And I assume that the same
is true of Task entries being forbidden from returning values [how
much space would be needed for an “Array (Positive Range <>) of
Integer” within the rendevous?]}



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-11-05 12:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-01  5:40 Tasks, Entries, and Variables of a Class-wide type Shark8
2010-11-01  9:21 ` Dmitry A. Kazakov
2010-11-01 15:30   ` Shark8
2010-11-01 18:50     ` Jeffrey Carter
2010-11-01 19:23       ` Dmitry A. Kazakov
2010-11-01 20:08         ` Georg Bauhaus
2010-11-01 20:56           ` Dmitry A. Kazakov
2010-11-01 19:28       ` Shark8
2010-11-01 20:49         ` Jeffrey Carter
2010-11-05 12:43         ` Robert A Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox