unit DEngine;
{$F+,O+}
interface

uses
  d2type,ds2x86,{d2_Asm,}dt2x86;


Const


  Procs : Array [RsvType] Of Procedure =

  { _nil _asm _case _const _continue _cycle _do _else _elsif _end _exit
    _fi _for _if _ifn _in _inline _leave _library _loop _module _next
    _new _of _repeat _return _sub _then _type _until,_use _var _wend _while
  }
  (
       ill,
       {exec_asm}ill,
       exec_case,
       exec_const,
       exec_cont,
       exec_cycle,
       exec_do,
       exec_else,
       exec_elsif,
       exec_elsifn,
       exec_end,
       exec_exit,
       exec_endif,
       exec_for,
       exec_if,
       exec_ifn,
       exec_in,
       exec_inline,
       exec_break,
       exec_library,
       exec_loop,
       exec_module,
       exec_new,
       exec_next,
       exec_of,
       exec_recur,
       exec_repeat,
       exec_return,
       exec_sub,
       exec_then,
       exec_type,
       exec_until,
       exec_usebin,
       exec_vars,
       exec_vect,
       exec_whend,
       exec_while,
       ill
  );

{  EndProcs : Array [RsvType] Of Procedure =
  (
    end_}

Var
   Func : TFunc;

Function Search(Name:String):RsvType;

implementation



type
  p_hash = ^t_hash;
  t_hash = array[byte] of rsvtype;

var
  l_hash,u_hash : t_hash;

procedure init_t_hash;

  procedure herror;
  begin
    errormsg(Input,'(system error) hash collision');
  end;

var
  i:byte;
  r:rsvtype;
begin
  for i:=low(byte) to high(byte) do begin
    l_hash[i]:=_nil;
    u_hash[i]:=_nil;
  end;
  for r:=low(rsvtype) to high(rsvtype) do begin
    i:=hash_func(nameslowercase[r]);
    if l_hash[i]<>_nil then herror;
    l_hash[i]:=r;
    i:=hash_func(namesuppercase[r]);
    if u_hash[i]<>_nil then herror;
    u_hash[i]:=r;
  end;
end;

function hash : p_hash;
begin
  if uprFLG then
    hash:=@u_hash
  else
    hash:=@l_hash
end;

Function search;
var
  r:rsvtype;
begin
  r:=hash^[hash_func(name)];
  if (r=_nil) or (name<>names^[r]) then
    search:=_nil
  else
    search:=r;
  Func:=Procs[r];
end;

begin
  init_t_hash;
end.