comp.lang.ada
 help / color / mirror / Atom feed
From: Optikos <ZUERCHER_Andreas@outlook.com>
Subject: Re: Creating several types from a base type and conversion
Date: Thu, 23 Jan 2020 13:39:11 -0800 (PST)
Date: 2020-01-23T13:39:11-08:00	[thread overview]
Message-ID: <c9dc4033-5a17-4ded-8f8f-86edb1321d70@googlegroups.com> (raw)
In-Reply-To: <f531cd40-6734-46cb-967e-638cf1004426@googlegroups.com>

On Saturday, January 18, 2020 at 1:32:54 AM UTC-6, Ken Roberts wrote:
> New to ada with a question about types.
> 
> The theory is creating an old computer emulator. Memory is an array of BaseWord's (Older computer had
> 32K of memory, so making an array on a modern computer is peanuts).
> 
> Creating a base type that is stored into the memory array
> 
> <code>
> 
>     type BaseWord is array (00 .. 29) of Boolean;
>     pragma pack (BaseWord);
> 
> </code>
> 
> Creating derived type(s) that can be returned from the memory section
> 
> <code>
> 
>     type DataWord is new BaseWord with record
>         Upper : array 00 .. 8#77777# of Boolean;
>         Lower : array 00 .. 8#77777# of Boolean;
>     end record;
> 
>     for DataWord use record
>         for Upper use 15 .. 29;
>         for Lower use 00 .. 14;
>     end record;
>     pragma pack (DataWord);
> 
>     type InstructionWord is new BaseWord with record;
>         (define field parameters)
>     end record;
>     for InstructionWord use record
>         (define BaseWord fields bit locations)
>     end record;
> 
> </code>
> 
> Defining how characters for display are packed into memory
> 
> <code>
>     type CharByte is array (0 .. 5) of Boolean;  -- Character define
>     type CharWord is record
>         CharArray : array (0 .. 4) of CharByte;
>     end record;
>     for CharWord use record
>         for CharArray (0) use 24 .. 29;
>         for CharArray (1) use 18 .. 23;
>         for CharArray (2) use 12 .. 17;
>         for CharArray (3) use 6 .. 11;
>         for CharArray (4) use 0 .. 5;
>     end record;
> 
> </code>
> 
> So the next question is how to convert between CharWord/BaseWord?
> 
> For most stuff, memory will be returning either DataWord or InstructionWord for each memory access,
> but I'm also looking at an easier way to manage characters for text display on the emulated monitors.

Many replies to this posting focused on details of using standard Ada itself or GNAT-specific extensions of Ada itself as the total solution to portability, such as via record-representation clauses (which aren't always portable to Janus/Ada) and/or Scalar_Storage_Order (which is GNAT-only, absent in all other Ada compilers).

Instead of depending on a big-language solution of a very-feature-rich compiler, there is a common industrial practice in both Ada and other languages that I mentioned in my 2 replies:  use 2 different packages with same-named identifiers (especially functions or procedures) to link in either the little-endian implementation or big-endian implementation (or any other nonportability that is peculiar to a target ISA or target OS).  This solution is at the heart of VIPER and MVVM software architectures for taming the portability beast quite well (going so far as to tame even radical philosophical departures among the very divergent GUIs/window-managers:  Gnome/GTK, Windows UWP, Win32, KDE/Qt, Tizen).

The key idea is to utilize the build system on a per-target basis, especially the same build system for all targets (instead of the easier case of a different build system per target OS/ISA/GUI/whatever).  The Project Extension portion of gprbuild is how FSF or AdaCore GNAT would link in the little-endian package of same-named identifiers versus the big-endian package of same-named identifiers (or overcoming any other seemingly troublesome lack of portability within the Ada language itself or of your own ossified source code that oops inadvertently/short-sightedly got modeled in the past for only one of the now-needed targets-of-portability).  Find a layer of identifiers (especially functions or procedures) that can now be a facade of sorts behind/within which you swap in this versus that nonportable implementation peculiar to each target at link-time (and perhaps just don't even compile the other package that is not needed for the current target-of-interest).

The kind of per-target switcheroo just described above is mentioned in the webpage below:
“… Another use case is a large software system with multiple implementations of a common interface; in Ada terms, multiple versions of a package body for the same spec, or perhaps different versions of a package spec that have the same visible part but different private parts. For example, one package might be safe for use in tasking programs, while another might be used only in sequential applications. …”

https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html#project-extension


  parent reply	other threads:[~2020-01-23 21:39 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-18  7:32 Creating several types from a base type and conversion Ken Roberts
2020-01-18 12:16 ` Simon Wright
2020-01-18 12:49   ` Ken Roberts
2020-01-18 14:56     ` Bill Findlay
2020-01-18 16:13       ` Jeffrey R. Carter
2020-01-18 18:20         ` Bill Findlay
2020-01-18 18:32           ` Jeffrey R. Carter
2020-01-18 20:34             ` Simon Wright
2020-01-20 16:38               ` Bill Findlay
2020-01-18 22:20       ` Ken Roberts
2020-01-18 15:09     ` Simon Wright
2020-01-18 22:16       ` Ken Roberts
2020-01-18 22:35         ` Simon Wright
2020-01-18 23:03           ` Ken Roberts
2020-01-18 23:38             ` Simon Wright
2020-01-19  0:12               ` Ken Roberts
2020-01-19  9:37                 ` Simon Wright
2020-01-19 11:48                   ` AdaMagica
2020-01-19 14:51                     ` Simon Wright
2020-01-19 15:24                       ` Niklas Holsti
2020-01-19 16:11                     ` Optikos
2020-01-19  0:33               ` Ken Roberts
2020-01-19  0:07         ` Niklas Holsti
2020-01-18 15:47     ` Simon Wright
2020-01-21 21:35     ` Shark8
2020-01-21 23:06       ` Niklas Holsti
2020-01-22  1:08         ` Ken Roberts
2020-01-22 14:18           ` Ken Roberts
2020-01-22  8:37       ` Simon Wright
2020-01-22 14:32         ` Shark8
2020-01-22 15:40           ` Simon Wright
2020-01-18 14:17   ` Optikos
2020-01-18 17:57 ` Niklas Holsti
2020-01-18 22:59   ` Ken Roberts
2020-01-19  0:30     ` Niklas Holsti
2020-01-19  1:07       ` Ken Roberts
2020-01-19  3:37 ` Ken Roberts
2020-01-23 21:39 ` Optikos [this message]
2020-01-24  9:35   ` Ken Roberts
2020-01-24 10:04     ` AdaMagica
2020-01-24 12:38     ` Optikos
2020-01-24 15:01       ` Ken Roberts
2020-01-24 15:22         ` Simon Wright
2020-01-24 15:40           ` Ken Roberts
2020-01-24 15:54   ` Simon Wright
2020-01-25 10:37 ` Ken Roberts
2020-01-25 10:44   ` Ken Roberts
2020-01-25 20:26   ` Shark8
2020-01-27 14:10 ` Ken Roberts
replies disabled

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