comp.lang.ada
 help / color / mirror / Atom feed
From: Juergen Pfeifer <juergen.pfeifer@gmx.net>
Subject: Re: C/C++ programmer giving Ada95 a chance -- writing an emulator.
Date: 2000/03/28
Date: 2000-03-28T00:00:00+00:00	[thread overview]
Message-ID: <38E05E84.BB5507FC@gmx.net> (raw)
In-Reply-To: 38e148e2.5089627@news.shreve.net

jross wrote:
 
> My first question is how do you define and write a dispatching
> mechanism as you would in C++ using function pointers in a table for
> execution speed efficiency,  like this:
> 
> ---------------------------------
> -- the .h file
> ---------------------------------
> 
> class TACpu : public TCpu
> {
>     ? define registers and much stuff  (not shown)
> 
>     struct OpStruct  // define the op code jump table structure
>     {
>         char Byte; // the opcode byte for reference only
>         void (TACpu::*Func)();  // executes opcode
>     };
> 
>     static OpStruct OpTable[];  // the table in the .cpp file
> 
>     void Op_U();  // undefined
>     void Op_00();  // functions that execute the opcodes
>     void Op_01();
>     void Op_02();
>     void Op_03();
>     // ?  thru Op_FF
> };
> 
> ---------------------------------
> -- in the .cpp file
> ---------------------------------
> 
> TACpu::OpStruct TACpu::OpTable[] = {  // opcode table
>     { 0x00, Op_00 },
>     { 0x01, Op_01 },
>     { 0x02, Op_U  },
>     { 0x03, Op_03 },
>     // ?  thru Op_FF
> };
> 
> ... the Op_xx functions would go here
> 
> now the code for calling the opcodes
> 
>    IR = Core[PA++];  // get the opcode, advance the program address
>    (this->*OpTable[IR].Func)();   // execute it
> 
> ----------------
> 
> This is very efficient C++ code (could have been just as easy in plain
> old C without the class encapsulation?)  How would you do this in Ada
> without using a Case Statement?
> 
Ada95 allows the definition of "access to function" or "access to procedure"
types. You obviously can then use these types to build arrays of "function pointers"
or to use it in records.

I recommend Norman H. Cohens "Ada as a second language" (ISBN 0-07-011607-5). It is
an excellent Ada95 textbook for programmers coming from C/C++ or similar languages.
This would have answered your question easily.

Cheers
Juergen




       reply	other threads:[~2000-03-28  0:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <38e148e2.5089627@news.shreve.net>
2000-03-28  0:00 ` Juergen Pfeifer [this message]
2000-03-28  0:00   ` C/C++ programmer giving Ada95 a chance -- writing an emulator Jim Rogers
2000-03-29  0:00     ` Ed Falis
2000-03-29  0:00       ` James S. Rogers
2000-03-29  0:00         ` Robert Dewar
2000-03-29  0:00         ` Jean-Marc Bourguet
2000-03-30  0:00         ` Geoff Bull
2000-03-30  0:00           ` tmoran
2000-04-01  0:00           ` Robert Dewar
2000-03-28  0:00 ` Geoff Bull
2000-03-28  0:00   ` Jean-Marc Bourguet
2000-03-28  0:00 ` Ken Garlington
2000-03-30  0:00 ` Geoff Bull
     [not found]   ` <38e7e951.8384503@news.shreve.net>
2000-04-02  0:00     ` Jean-Pierre Rosen
2000-04-02  0:00       ` Robert Dewar
2000-04-03  0:00         ` Paul Graham
2000-04-06  0:00           ` Robert Dewar
2000-04-06  0:00             ` Larry Kilgallen
2000-04-06  0:00               ` Robert Dewar
2000-04-06  0:00                 ` Gautier
2000-04-07  0:00                   ` Robert Dewar
2000-04-07  0:00                     ` Gautier
     [not found] ` <38e19656.17008608@news.shreve.net>
2000-03-29  0:00   ` swhalen
2000-03-29  0:00     ` Robert Dewar
2000-03-30  0:00       ` swhalen
2000-03-29  0:00   ` Marin D. Condic
2000-03-29  0:00   ` Marc A. Criley
2000-03-29  0:00   ` David Starner
2000-03-29  0:00     ` Robert A Duff
2000-03-30  0:00       ` Geoff Bull
2000-04-01  0:00         ` Robert Dewar
2000-03-29  0:00     ` Robert Dewar
2000-03-29  0:00       ` Jean-Marc Bourguet
2000-03-29  0:00         ` Robert Dewar
2000-03-30  0:00           ` Jean-Marc Bourguet
2000-04-01  0:00             ` Robert Dewar
2000-03-29  0:00       ` Marin D. Condic
2000-03-29  0:00         ` Robert A Duff
2000-03-29  0:00           ` Marin D. Condic
2000-03-30  0:00       ` Geoff Bull
2000-04-01  0:00         ` Robert Dewar
2000-04-02  0:00           ` Geoff Bull
2000-04-02  0:00             ` Robert Dewar
2000-04-02  0:00             ` swhalen
2000-03-30  0:00   ` Samuel T. Harris
2000-04-01  0:00     ` Robert Dewar
2000-04-05  0:00       ` Robert A Duff
2000-03-30  0:00   ` Ken Garlington
     [not found] <38E3DBD7.27F5B246@acenet.com.au>
2000-03-31  0:00 ` tmoran
2000-03-31  0:00   ` Geoff Bull
2000-04-01  0:00     ` Tucker Taft
2000-04-02  0:00       ` Robert Dewar
2000-04-02  0:00         ` Geoff Bull
2000-04-02  0:00       ` Geoff Bull
replies disabled

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