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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ea19776e3073a96,start X-Google-Attributes: gid103376,public From: Geoff Bull Subject: Re: C/C++ programmer giving Ada95 a chance -- writing an emulator. Date: 2000/03/28 Message-ID: <38E05DF5.D9AEC67A@research.canon.com.au>#1/1 X-Deja-AN: 603304852 Content-Transfer-Encoding: 7bit References: <38e148e2.5089627@news.shreve.net> To: jross X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@research.canon.com.au X-Trace: cass.research.canon.com.au 954228185 25257 203.12.174.227 (28 Mar 2000 07:23:05 GMT) Organization: Canon Information Systems Research Australia Mime-Version: 1.0 NNTP-Posting-Date: 28 Mar 2000 07:23:05 GMT Newsgroups: comp.lang.ada Date: 2000-03-28T07:23:05+00:00 List-Id: jross wrote: > > C/C++ is prime for such a low level application. How about Ada? Anything you can write in C you can more or less directly translate to Ada. > 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 following is a direct translation of your code: with Ada.Text_IO; use Ada.Text_IO; procedure Example is type Opcode is range 16#00# .. 16#FF#; type Func_Access is access procedure; type Op_Struct is record Byte : Opcode; Func : Func_Access; end record; procedure Op_U is begin Put_Line ("undefined opcode"); end Op_U; procedure Op_00 is begin Put_Line ("opcode 00"); end Op_00; procedure Op_01 is begin Put_Line ("opcode 01"); end Op_01; procedure Op_02 is begin Put_Line ("opcode 02"); end Op_02; procedure Op_03 is begin Put_Line ("opcode 03"); end Op_03; Op_Table : array (Opcode) of Op_Struct := ((16#00#, Op_00'Access), (16#01#, Op_01'Access), (16#02#, Op_02'Access), (16#03#, Op_03'Access), others => (16#FF#, Op_U'Access) ); Core : array (Natural range <>) of Opcode := (0, 1, 2, 3, 55); IR : Opcode; begin for PA in Core'Range loop IR := Core (PA); Op_Table (IR).Func.all; end loop; end Example;