From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:410f:: with SMTP id q15mr11884641qtl.192.1579351756809; Sat, 18 Jan 2020 04:49:16 -0800 (PST) X-Received: by 2002:aca:4b46:: with SMTP id y67mr7104884oia.121.1579351756580; Sat, 18 Jan 2020 04:49:16 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no9347556qtd.0!news-out.google.com!w29ni1657qtc.0!nntp.google.com!g89no9347550qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 18 Jan 2020 04:49:16 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=47.136.24.151; posting-account=o_Y23woAAACPYGlDsFV1OivhygPNSoRn NNTP-Posting-Host: 47.136.24.151 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> Subject: Re: Creating several types from a base type and conversion From: Ken Roberts Injection-Date: Sat, 18 Jan 2020 12:49:16 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57870 Date: 2020-01-18T04:49:16-08:00 List-Id: On Saturday, January 18, 2020 at 4:16:20 AM UTC-8, Simon Wright wrote: > Ken Roberts writes: > > > So the next question is how to convert between CharWord/BaseWord? > > Possibly using Ada.Unchecked_Conversion. Hidden inside a function with a > helpful-in-six-months name. > > It takes very little time to compile code nowadays, I'd strongly suggest > you start with the basics (e.g. BaseWord) and build up from there, > checking as you go (there are a _lot_ of syntax errors in your example > code). > > You can't say > > type DataWord is new BaseWord with record > Upper : array 00 .. 8#77777# of Boolean; > Lower : array 00 .. 8#77777# of Boolean; > end record; > > because BaseWord isn't a tagged type, and even if it was you don't want > to add extra information, you're looking for an alternative view. > And that's not the syntax for an array declaration. > And you can't declare an anonymous array in a record. > And that's two large arrays (I think you're aiming for representations). > > ---------- > > I was wondering whether an Unchecked Union (ARM B.3.3[1]) might serve, > but (30) says "The use of an unchecked union to obtain the effect of an > unchecked conversion results in erroneous execution". > > [1] http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-B-3-3.html Don't know about the syntax errors - gnatmake seems to like it. But then, the example is in a package spec with no body yet. Still working on the basics first. Just now getting serious about Ada, I'm sure I'll run into a lot of learning curve on these little details. The concept is emulating a 30-bit computer from olden days. It was my understanding that a boolean array would be better than an integer in order to do some of the bit manipulations that the old computer was designed for. One example: ADD LP : L[Y*(Q)]+(A) -> A Take the logical product of Y and Q register, then add A register, place results in A register. (LP being boolean AND of 2 registers) I think I tried doing tagged records and subtypes, but kept getting errors like 'Bits already mapped' when trying to extend the BaseWord (30 bit) into a data word ( 2 separate 15-bit fields) and instruction word (5 separate bit-mapped fields) while still being able to easily convert between BaseWord and others (think pulling next instruction from memory array, then pulling data from arbitrary location in memory array). Functionally, it would be relatively easy to just ignore the hardware aspect of the emulation, but I'm trying to set it up so I can emulate the hardware later as a learning tool to how this old computer actually did things (like 1's complement subtractive addition). The real fun will be programming the timing (1MHz clock split into 4 phases, with interesting interrupt handling). I know - _very_ ambitious project for a beginner in the language (not to programming), but I figure might as well have an interesting project to work on while learning rather than the basic "Hello World" style that seems to be prevalent.