comp.lang.ada
 help / color / mirror / Atom feed
* implementation of Bounded_String
@ 2018-01-18 14:10 Mehdi Saada
  2018-01-18 14:42 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mehdi Saada @ 2018-01-18 14:10 UTC (permalink / raw)


I suppose it's obvious but...
If I want to reimplement IO of Bounded_String without relying on Unbounded_String, can I do without getting reading input one character after another ? Has it to do with streams ?

Where can I read GNAT'S implementation of those package ? What's their filename ? I suppose it's the same in mac, linux and windows version.

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

* Re: implementation of Bounded_String
  2018-01-18 14:10 implementation of Bounded_String Mehdi Saada
@ 2018-01-18 14:42 ` Dmitry A. Kazakov
  2018-01-18 22:24 ` Simon Wright
  2018-01-19  1:25 ` Randy Brukardt
  2 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2018-01-18 14:42 UTC (permalink / raw)


On 18/01/2018 15:10, Mehdi Saada wrote:
> I suppose it's obvious but...
> If I want to reimplement IO of Bounded_String without relying on
> Unbounded_String, can I do without getting reading input one character
> after another ? Has it to do with streams ?

It has to do with whether string bounds is a part of I/O. Stream 
attributes are subdivided into 'Read/'Write and 'Input/'Output. The 
former are without bounds (constraints).

Text I/O is a completely different story because it is related to text. 
You implement Put this way:

    type Bounded_String (Length : Natural := 0) is record
       Current_Length : Natural := 0;
       Data : String (1..Length);
    end record;

    procedure Put (X : Bounded_String) is
    begin
       Put (X.Data (1..X.Current_Length));
    end Put;

There is no reasonable Get to have, but Get_Line could have sense

    procedure Get_Line (X : out Bounded_String) is
    begin
       Get_Line (X.Data, X.Current_Length);
    end Get_Line;

Similarly you can always implement stream attributes decomposed into 
stream operations of other objects.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: implementation of Bounded_String
  2018-01-18 14:10 implementation of Bounded_String Mehdi Saada
  2018-01-18 14:42 ` Dmitry A. Kazakov
@ 2018-01-18 22:24 ` Simon Wright
  2018-01-19  1:25 ` Randy Brukardt
  2 siblings, 0 replies; 7+ messages in thread
From: Simon Wright @ 2018-01-18 22:24 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> Where can I read GNAT'S implementation of those package ? What's their
> filename ? I suppose it's the same in mac, linux and windows version.

(where your compiler is installed is referred to as $prefix:
e.g. /usr/local/gnat2017 perhaps)

The source is in $prefix/lib/gcc/*/*/adainclude/

e.g. for me

   /opt/gnat-gpl-2017/lib/gcc/x86_64-apple-darwin14.5.0/6.3.1/adainclude/

The file names are compressed: you can find out which contains which
package using gnatkr:

   $ gnatkr ada.strings.unbounded.ads
   a-strunb.ads

If you want to explore the library using GPS (a good idea, it's large &
complex), you could write a GPR (don't try building with it!) like

   project Ada_Library is
      Loc := "/opt/gnat-gpl-2017/lib/gcc/x86_64-apple-darwin14.5.0/6.3.1/";
      for Source_Dirs use (Loc & "adainclude");
      for Object_Dir use Loc & "adalib";
   end Ada_Library;

And yes, aside from a few low-level packages, it's the same on all OSs.


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

* Re: implementation of Bounded_String
  2018-01-18 14:10 implementation of Bounded_String Mehdi Saada
  2018-01-18 14:42 ` Dmitry A. Kazakov
  2018-01-18 22:24 ` Simon Wright
@ 2018-01-19  1:25 ` Randy Brukardt
  2018-01-19 11:54   ` Mehdi Saada
  2 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2018-01-19  1:25 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:2eaf6de3-ce95-4c69-b22b-441a7ed6d5c9@googlegroups.com...
>I suppose it's obvious but...
> If I want to reimplement IO of Bounded_String without relying on
> Unbounded_String, can I do without getting reading input one character
> after another ? Has it to do with streams ?

Are you talking about the language-defined Bounded_Strings or something 
else? There is a package specifically for Text_IO of (language-defined) 
Bounded_Strings called Ada.Text_IO.Bounded_IO.

(There's a similar package for Unbounded_Strings, called 
Ada.Text_IO.Unbounded_IO. And of course Ada.Text_IO directly contains 
operations for the predefined type String.)

                           Randy.



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

* Re: implementation of Bounded_String
  2018-01-19  1:25 ` Randy Brukardt
@ 2018-01-19 11:54   ` Mehdi Saada
  2018-01-19 12:57     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 7+ messages in thread
From: Mehdi Saada @ 2018-01-19 11:54 UTC (permalink / raw)


I just wonder what's the lowest level (besides assembly) at which in Ada, one can implement characters input-output.
But since Text_io is language-defined, I suppose there's nothing closer to the hardware ?


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

* Re: implementation of Bounded_String
  2018-01-19 11:54   ` Mehdi Saada
@ 2018-01-19 12:57     ` Dmitry A. Kazakov
  2018-01-19 18:26       ` Niklas Holsti
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2018-01-19 12:57 UTC (permalink / raw)


On 19/01/2018 12:54, Mehdi Saada wrote:

[Trying to make sense from kind of meaningless questions]

> I just wonder what's the lowest level (besides assembly) at which in
> Ada, one can implement characters input-output.

You cannot do I/O in assembly in any way different to a higher level 
language. With an OS in place all I/O is queuing a request to some 
device driver.

> But since Text_io is language-defined, I suppose there's nothing
> closer to the hardware ?

Among Ada standard means stream and direct I/O are the closest to the 
hardware in the sense that they add least to the data being read and 
written. [However that can depend on the OS which can translate streams 
and blocks into something else below]

Calls to the native OS I/O facilities follow. There is nothing closer 
unless you are in the system kernel.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: implementation of Bounded_String
  2018-01-19 12:57     ` Dmitry A. Kazakov
@ 2018-01-19 18:26       ` Niklas Holsti
  0 siblings, 0 replies; 7+ messages in thread
From: Niklas Holsti @ 2018-01-19 18:26 UTC (permalink / raw)


On 18-01-19 14:57 , Dmitry A. Kazakov wrote:
> On 19/01/2018 12:54, Mehdi Saada wrote:
>
> [Trying to make sense from kind of meaningless questions]
>
>> I just wonder what's the lowest level (besides assembly) at which in
>> Ada, one can implement characters input-output.
>
> You cannot do I/O in assembly in any way different to a higher level
> language. With an OS in place all I/O is queuing a request to some
> device driver.
>
>> But since Text_io is language-defined, I suppose there's nothing
>> closer to the hardware ?
>
> Among Ada standard means stream and direct I/O are the closest to the
> hardware in the sense that they add least to the data being read and
> written. [However that can depend on the OS which can translate streams
> and blocks into something else below]
>
> Calls to the native OS I/O facilities follow. There is nothing closer
> unless you are in the system kernel.

Or running "bare machine", without an OS, and with direct access to the 
I/O HW -- which means that you are, in some sense, part of the "system 
kernel", such as it is.

In a bare machine environment, Text_IO.Put (Item : in Character) is 
often implemented like this (in Ada, usually):

    while UART_Tx_Register.Busy loop null; end loop;

    UART_Tx_Register.Data := Item;

where UART_Tx_Register is mapped to the transmission register of the 
UART peripheral.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

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

end of thread, other threads:[~2018-01-19 18:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18 14:10 implementation of Bounded_String Mehdi Saada
2018-01-18 14:42 ` Dmitry A. Kazakov
2018-01-18 22:24 ` Simon Wright
2018-01-19  1:25 ` Randy Brukardt
2018-01-19 11:54   ` Mehdi Saada
2018-01-19 12:57     ` Dmitry A. Kazakov
2018-01-19 18:26       ` Niklas Holsti

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