comp.lang.ada
 help / color / mirror / Atom feed
* I don't know what the compiler wants to tell me
@ 2005-11-03 20:47 Thomas Ruschival
  2005-11-03 22:39 ` jimmaureenrogers
  2005-11-04  5:12 ` I don't know what the compiler wants to tell me Jeffrey R. Carter
  0 siblings, 2 replies; 8+ messages in thread
From: Thomas Ruschival @ 2005-11-03 20:47 UTC (permalink / raw)


Hi Group
I just wrote a sample program in which I wanted to understand how it works
with task type and instatiating tasks of that type. 
Now I run into a strange Compiler error I don't understand:

hello2b.adb:48:18: left hand of assignment must not be limited

Basically all I wanted to do is have a task running until another task
does a rendevouz and interrupts exactly that task. I wanted it
configurable so I first chose to configure it in the disciminants which
didn't work. 
Now I pass the task to be controlled at a rendevouz point to
the controller, this should copy it into a local variable to keep the
rendevouz as short as possible and then control the task to which the local
variable points to.... as I write this the question arises: does ada pass
by value or by reference?

I appreciate any comments on how you do rendevous with task you don't know
yet at the time of writing, lets say you just know the access points of
that task type but you want to make rendevous with different instances of
that type, so you need to tell this either at point where you instantiate
the task that calls the entry point or at another point you have to tell
the task which object to meet


Thanks 
Thomas Ruschival


Here is the code: 
with Text_IO, Calendar;
use Calendar;

procedure Hello2b is
    
   task type PrinterTask is
	  entry Interrupt;
   end PrinterTask;
   
   task type ControlTask is
	  entry Start(ToControl : in PrinterTask);
   end ControlTask;
   
------ Hello Task to do the important work of printing "Hello" to
Console task body PrinterTask is
      SamplingTime : Duration := 2.0; 
      NextActivation : Calendar.Time ;
	  irq  : Boolean := False;
   begin
      while Irq = False  -- infinite loop until an external task does 
						 -- a rendevouz to
interrupt loop
		 -- next activation will be SamplingTime from now
		 NextActivation := Clock + SamplingTime; 
		 -- either interrupt occurs or we wait until 
		 -- samplingTime is elapsed and print Hello
		 select 
			accept Interrupt;
			  Irq := True;
		 or  		   
			delay until NextActivation;	
			Text_IO.Put_Line("task running");
		 end select;
      end loop;
   end PrinterTask;

------ ControlTask to interrupt the work of a given Task
   task body ControlTask is 
	  Controlled : PrinterTask; -- task To be controlled
   begin
	  -- Copy into local variable
	  accept Start(ToControl : in PrinterTask) do
		 Controlled := ToControl;
	  end Start;	 
		 
	  delay 60.0; -- wait a minute
	 Controlled.Interrupt; -- Now make a rendevouz with the task we
want to terminate end ControlTask;	  
    
-- tasks   
   Printer :  PrinterTask;
   Controller: ControlTask; 
   
begin
   Text_IO.Put_Line("Procedure running....");
   Controller.Start(Printer);
end Hello2b;



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

* Re: I don't know what the compiler wants to tell me
  2005-11-03 20:47 I don't know what the compiler wants to tell me Thomas Ruschival
@ 2005-11-03 22:39 ` jimmaureenrogers
  2005-11-08  8:43   ` Thomas Ruschival
  2005-11-04  5:12 ` I don't know what the compiler wants to tell me Jeffrey R. Carter
  1 sibling, 1 reply; 8+ messages in thread
From: jimmaureenrogers @ 2005-11-03 22:39 UTC (permalink / raw)


Thomas Ruschival wrote:
> Hi Group
> I just wrote a sample program in which I wanted to understand how it works
> with task type and instatiating tasks of that type.
> Now I run into a strange Compiler error I don't understand:
>
> hello2b.adb:48:18: left hand of assignment must not be limited

There is no pre-defined assignment for limited types. It is therefore
forbidden to attempt to assign to a limited type.

Task types are limited types. You cannot assign one task to another.

>
> Basically all I wanted to do is have a task running until another task
> does a rendevouz and interrupts exactly that task. I wanted it
> configurable so I first chose to configure it in the disciminants which
> didn't work.
> Now I pass the task to be controlled at a rendevouz point to
> the controller, this should copy it into a local variable to keep the
> rendevouz as short as possible and then control the task to which the local
> variable points to.... as I write this the question arises: does ada pass
> by value or by reference?
>
> I appreciate any comments on how you do rendevous with task you don't know
> yet at the time of writing, lets say you just know the access points of
> that task type but you want to make rendevous with different instances of
> that type, so you need to tell this either at point where you instantiate
> the task that calls the entry point or at another point you have to tell
> the task which object to meet
>
>
> Thanks
> Thomas Ruschival
>
>
> Here is the code:
> with Text_IO, Calendar;
> use Calendar;
>
> procedure Hello2b is
>
>    task type PrinterTask is
> 	  entry Interrupt;
>    end PrinterTask;
>
>    task type ControlTask is
> 	  entry Start(ToControl : in PrinterTask);
>    end ControlTask;
>
> ------ Hello Task to do the important work of printing "Hello" to
> Console task body PrinterTask is
>       SamplingTime : Duration := 2.0;
>       NextActivation : Calendar.Time ;
> 	  irq  : Boolean := False;
>    begin
>       while Irq = False  -- infinite loop until an external task does
> 						 -- a rendevouz to
> interrupt loop
> 		 -- next activation will be SamplingTime from now
> 		 NextActivation := Clock + SamplingTime;
> 		 -- either interrupt occurs or we wait until
> 		 -- samplingTime is elapsed and print Hello
> 		 select
> 			accept Interrupt;
> 			  Irq := True;
> 		 or
> 			delay until NextActivation;
> 			Text_IO.Put_Line("task running");
> 		 end select;
>       end loop;
>    end PrinterTask;
>
> ------ ControlTask to interrupt the work of a given Task
>    task body ControlTask is
> 	  Controlled : PrinterTask; -- task To be controlled

The variable Controlled is an instance of a limited type.
The variable Controlled creates a PrinterTask upon elaboration of the
ControlTask body.
That PrinterTask instance begins executing as soon as it is scheduled
after its creation.

>    begin
> 	  -- Copy into local variable
> 	  accept Start(ToControl : in PrinterTask) do
> 		 Controlled := ToControl;
> 	  end Start;
>
> 	  delay 60.0; -- wait a minute
> 	 Controlled.Interrupt; -- Now make a rendevouz with the task we
> want to terminate end ControlTask;
>
> -- tasks
>    Printer :  PrinterTask;
>    Controller: ControlTask;
>
> begin
>    Text_IO.Put_Line("Procedure running....");
>    Controller.Start(Printer);
> end Hello2b;

Instead of passing an instance of a task either through a discriminant,

which is forbidden, or through an entry, which also does not work, you
can create an access to task type and pass that through a discriminant
or entry.

task type PrinterTask is
   entry Interrupt;
end PrinterTask;

type Printer_Access is access PrinterTask;

task type ControlTask(ToControl : Printer_Access);

...

You can then create instances of your tasks as follows:

Printer : Printer_Access := new PrinterTask;
Controller : ControlTask(Printer);

Your ControlTask body will have a statement such as:

     ToControl.Interrupt;

Jim Rogers




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

* Re: I don't know what the compiler wants to tell me
  2005-11-03 20:47 I don't know what the compiler wants to tell me Thomas Ruschival
  2005-11-03 22:39 ` jimmaureenrogers
@ 2005-11-04  5:12 ` Jeffrey R. Carter
  2005-11-04  9:14   ` Lurker
  1 sibling, 1 reply; 8+ messages in thread
From: Jeffrey R. Carter @ 2005-11-04  5:12 UTC (permalink / raw)


Thomas Ruschival wrote:

> hello2b.adb:48:18: left hand of assignment must not be limited

What it means is that assignment (":=") is not defined for limited types. Task 
types are limited types.

>       while Irq = False  -- infinite loop until an external task does 

This (Irq = False) generally indicates a lack of understanding of Booleans. 
Better is

while not Irq loop

That uses negative logic. Positive logic is easier to understand than negative, so

loop
    exit when Irq;

is better still. However, best is to eliminate Irq altogether and have

loop
    ...
    select
       accept Interrupt;

       exit;
    or
    ...
end loop;

Often, naming loops can make them easier to read and understand:

Wait_For_Interrupt : loop
    ...
    exit Wait_For_Interrupt;
    ...
end loop Wait_For_Interrupt;

> 	  Controlled : PrinterTask; -- task To be controlled

Controlled is an object of a task type; an object of a task type is a task.

> 		 Controlled := ToControl;

This is illegal, because Controlled is limited.

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail
07



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

* Re: I don't know what the compiler wants to tell me
  2005-11-04  5:12 ` I don't know what the compiler wants to tell me Jeffrey R. Carter
@ 2005-11-04  9:14   ` Lurker
  2005-11-04 17:55     ` Martin Krischik
  0 siblings, 1 reply; 8+ messages in thread
From: Lurker @ 2005-11-04  9:14 UTC (permalink / raw)


"Jeffrey R. Carter" <spam@spam.com> wrote in message
news:M4Caf.5446$Rl1.4529@newsread1.news.pas.earthlink.net...

> >       while Irq = False  -- infinite loop until an external task does
>
> This (Irq = False) generally indicates a lack of understanding of
Booleans.

Very true, I've even seen some constructs like this:

If x = true then
  y = true
else
  y = false
end

[Not an Ada code of course]





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

* Re: I don't know what the compiler wants to tell me
  2005-11-04  9:14   ` Lurker
@ 2005-11-04 17:55     ` Martin Krischik
  2005-11-07  8:32       ` Maciej Sobczak
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Krischik @ 2005-11-04 17:55 UTC (permalink / raw)


Am 04.11.2005, 11:14 Uhr, schrieb Lurker <nowhere@nothing.com>:

>> >       while Irq = False  -- infinite loop until an external task does
>>
>> This (Irq = False) generally indicates a lack of understanding of
> Booleans.
> Very true, I've even seen some constructs like this:
> If x = true then
>   y = true
> else
>   y = false
> end

Seen thatin C and C++ as well. Such a common supidity.

Martin



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

* Re: I don't know what the compiler wants to tell me
  2005-11-04 17:55     ` Martin Krischik
@ 2005-11-07  8:32       ` Maciej Sobczak
  0 siblings, 0 replies; 8+ messages in thread
From: Maciej Sobczak @ 2005-11-07  8:32 UTC (permalink / raw)


Martin Krischik wrote:

>> Very true, I've even seen some constructs like this:
>> If x = true then
>>   y = true
>> else
>>   y = false
>> end
> 
> Seen thatin C and C++ as well. Such a common supidity.

Stupidity is language-independent, see:

http://www.thedailywtf.com/

;)

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

* Re: I don't know what the compiler wants to tell me
  2005-11-03 22:39 ` jimmaureenrogers
@ 2005-11-08  8:43   ` Thomas Ruschival
  2005-11-08 19:30     ` Ada books (was: I don't know what the compiler wants to tell me) Björn Persson
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Ruschival @ 2005-11-08  8:43 UTC (permalink / raw)


Cool, thanks alot.
It seems worthy to get a good book about ada... I should check out the
library tis afternoon...

Thank you very much 
- Thomas



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

* Ada books (was: I don't know what the compiler wants to tell me)
  2005-11-08  8:43   ` Thomas Ruschival
@ 2005-11-08 19:30     ` Björn Persson
  0 siblings, 0 replies; 8+ messages in thread
From: Björn Persson @ 2005-11-08 19:30 UTC (permalink / raw)


Thomas Ruschival wrote:
> It seems worthy to get a good book about ada... I should check out the
> library tis afternoon...

You might also want to look at Ada World's collection of books and 
tutorials:
http://adaworld.com/learnadamain.html

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



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

end of thread, other threads:[~2005-11-08 19:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-03 20:47 I don't know what the compiler wants to tell me Thomas Ruschival
2005-11-03 22:39 ` jimmaureenrogers
2005-11-08  8:43   ` Thomas Ruschival
2005-11-08 19:30     ` Ada books (was: I don't know what the compiler wants to tell me) Björn Persson
2005-11-04  5:12 ` I don't know what the compiler wants to tell me Jeffrey R. Carter
2005-11-04  9:14   ` Lurker
2005-11-04 17:55     ` Martin Krischik
2005-11-07  8:32       ` Maciej Sobczak

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