
  '==========
  'TRANSLATOR
  '==========

  'tran.inc

  int nsl
  int    nsls[7]   ' nesting depths of control blocks
  int    ctb[99]   ' control block type
  int    hei[99]   ' control block elseif suppressor flag
  int    slc[99]   ' `select` stack cas
  int    slt[99]   ' `select` stack cas type
  int    sle[99]   ' `select` stack enumeration
  string sls[99]   ' `select` stack expression (for switch)

  int   cbrk[99],cbri ' block nests {}


procedure exportadd(string*wn,*ali, int*eord)
=============================================
  '
  if eord>=1000
    ers="too many exports" : ert=400 : exit procedure
  endif
  expwn(eord)=wn
  expal(eord)=ali
  eord++
end procedure


procedure bindrec(string*s,*wr)
===============================
  '
  'LATE BIND
  '---------
  '
  int a,b,d,i,j,k,m,n,q,v,lt
  string wa,wd,we,wp,tt
  i=1
  k=1
  do
    icas=1 : wd=bword(s,i)
    j=swd
    if lenw=0
      exit do
    endif
    if isxn
      we=wd
    elseif (isa(ascn)<>0)or(ascn=42)
      clcase(wd)
      a=identype(wd)
      if a
        '
        'CREATE LINKED VARIABLES INSTEAD OF FUNCTIONS WITH PROCADDRESS
        v=1 : staticvars()
        lt=lent
        d=indt
        wa=""
        do          
          wp=tword(s,i)
          b=swd
          n=0 
          q=1
          while ascw=42
            wa+=wp
            wp=tword(s,i)
            n=1 'POINTER FLAG
          wend 
          if ascn=91 'ARRAYS
            a=instr(i,s,"]")
            q=wdval(s,i+1,0)
            i=a+1
            wp=mid(s,b,i-b)
            skiplspace(s,i)
          endif       
          vars(wd+" "+wp+" at "+wr+" ~ "+memreg(qedi,m)) 'CREATE VAR DIRECTLY
          if n+d>0 'POINTER OR ARRAY
            m+=cpuw
          else
            m=m+(lt*q)
          endif
          roundupc(m,8) '32bit/64bit compat
          skiplspace(s,i)
          if ise(ascn)
            exit do
          endif
          if ascn=44
            i++
          endif
        loop
        continue do
      endif
      'OTHERWISE READ AS FUNCTION NAME ALIAS
      icas=1 : we=noquotes(bword(s,i))
    endif
    clcase(wd)
    '
    if ascn=lbr
      capture(s,b,i,0)
      wp=mid(s,b,i-b)
    else
      b=0
      wp=""
    endif
    if ascn=44
      i++ : skiplspace(s,i) ' skip comma
    endif
    m=lookupm(wd)
    if m
      a=drc(m).a 'GET METATYPE
      if a<=0
        m=0 'OVERRIDE ALL EXCEPT VARIABLES
      endif
    endif
    if m
      wa="" 'NO NEW DECLARATION REQUIRED
    else 'm=0
      wa="!* "+wd+" "+qu+we+qu+" "+wp+" : " 'CREATE NEW DECLARATION
    endif
    wa+="@"+wd+"=getprocaddress "+wr+cm+qu+we+qu+cr
    '
    appbindbuf:
    '----------
    '
    if k+len(wa)>len(tt)
      tt+=space(8000) 'stretch buffer
    endif
    mid(tt,k)=wa
    k+=len(wa)
  loop
  '
  if v
    s=""
  else
    s=left(tt,k-1)
  endif
end procedure



function assieq(string*s, int*i) as int
=======================================
  'change ':=" to ' ='
  if ascn=58
    if asc(s,i+1)=61
      mid(s,i)=" " 'blank ":"
      i++ : ascn=61 ' :=
      return 1
    endif
  endif
end function


function captpreproto(string*s, int*i, string*wr,*w7) as int
============================================================
  string w3,w4,w5
  int a,b,c,d,e
  w7=" "
  '
  if idword(" fpu ", wr)
    w7+=wr+" " : wr="void" : return 3
  endif
  do
    skiplspace(s,i)
    w3=wordahead(s,i)
    e=asc(s,nwd)
    select asc(w3)
    case 42
      wr+=w3 : i=nwd : continue do 'POINTER
    case 91
      wr+="*"  'ARRAY POINTER
      do  '[][]...
        capture(s,0,i,0)
        skiplspace(s,i) 
        if ascn<>91
          exit do
        endif
      loop
      continue do
    case 40
      function=1 : exit do        'long (*foo)(...)
    case 39
      i=nwd : endline(s,i) : continue do
    end select
    select e
    case 40,44,60,61,91,123
      jmp fwd nmacrp
    case else
      c=lookupm(w3)
    endselect
    if c
      d=drc(c).a
      if (d=-18)or(d=-20) 'macros
        'CHECK FILETYPE
        'wing / apientry issues
        'a=len(cfile)-1
        'if asc(cfile,a-1)=46
        'select asc(cfile,a)
        'case 0x43,0x63,0x48,0x68 ' C c H h
        '  a=1
        'case else
        '  a=0
        'end select
        'if a
        w5=mrcso(c,1)
        if w5
          if ise(e)
            jmp fwd nmacrp 'leave name as is
          endif
          i=nwd
          inserts(s,w5+" ",i) 'EXPANDED MACRO
        else 'null macro eg glu.h defs
          i=nwd
        endif        
        continue do
        'endif 'a
      endif
    endif
    '
    nmacrp:
    =======
    '
    if w4=""
      nextinstruct(s,nwd) : c=asc(s,nwd)
      if c=lbr
        function=2 : exit do 'long foo(...)
      endif
      if c=123
        return 123 'COMPACT MULTIASSIGN
      endif
    endif
    '
    captqualif:
    '
    b=dic(" lib 1, alias 2, cdecl 3, stdcall 4, ms64 5, pascal 6, cpu 7, fpu 8, ",w3)
    if b
      i=nwd
      if b<3
        w3+=" "+tword(s,i)
      endif
      w7+=w3+" "
      nextinstruct(s,i)
      '
      if ascn=lbr
        if w4=""
          function=1
        else
          function=2
        endif
        exit do
      endif
    else
      if w4
        exit do
      else
        c=casf : casf=2 : w4=tword(s,i) : casf=c 'no case alteration
        w3=wordahead(s,i)
        goto captqualif
      endif
    endif
  loop
  if w4
    inserts(s,w4+" ",i)
  endif
  skiplspace(s,i)
end function


/*
function translateproto(string*s, int*i, string*w2) as string
=============================================================
  int a,b,c,m
  string w3,w4,w5,w6
  '
  'CAPTURE PROTOTYPE
  '
  w4=""
  ascn=asc(s,i)
  if ascn=lbr
    capture(s,m,i,0)
    w4=mid(s,m,i-m)
  endif
  '
  'CLEANUP PROTOTYPE
  '
  w3=""
  a=1
  '
  do
    w5=tword(w4,a)
    if lenw=0
      exit do
    endif
    b=lookupm(w5)
    if b 
      if drc(b).a=-20
        c=a
        w6=himac(b,w4,c)
        if not w6
          a=c : continue do
        endif
      elseif w5="const"
        continue do 'OMIT
      elseif idword(" struct union enum ",w5) '(STRUCT ST*S ..)
        icas=1 : w6=bword(w4,a)
        if ascn=42
          if w5<>"enum"
            a++ : skiplspace(w4,a)
          endif
        endif
        w5="sys"
      endif
    endif 'b lookupm
    w3+=w5
    if ascn=44
      a++ : w3+=","
    endif
    if ascn<>41
      w3+=" "
    endif
  loop
  if w2
    w2=" as "+w2
  endif
  '
  'CAPTURE MODIFIERS
  '
  skiplspace(s,i)
  a=i
  do
    select ascn
    case 0 to 31  : exit do
    case 58 to 59 : exit do
    case 61       : exit do
    case 123      : exit do
    end select
    w5=tword(s,i)
  loop
  if i>a
    w2+=" "+mid(s,a,i-a)
  endif
  nextinstruct(s,i)
  return w3+w2+cr
end function
*/


'/*
function translateproto(string*s, int*i, string*w2) as string
=============================================================
  int a,b,c,m
  string w3,w4,w5,w6
  '
  'CAPTURE PROTOTYPE
  '
  w4=""
  ascn=asc(s,i)
  if ascn=lbr
    capture(s,m,i,0) : w4=mid(s,m,i-m)
  endif
  '
  'CLEANUP PROTOTYPE
  '
  w3=""
  a=1
  '
  do
    w5=tword(w4,a)
    if isc(ascw)
      endline(w4,a) : continue do 'remove comment
    endif
    if lenw=0
      exit do
    endif
    b=lookupm(w5)
    if b 
      if drc(b).a=-20
        c=a
        w6=himac(b,w4,c)
        if not w6
          a=c : continue do
        endif
      elseif w5="const"
        continue do 'OMIT
      elseif idword(" struct union enum ",w5) '(STRUCT ST*S ..)
        icas=1 : w6=bword(w4,a)
        if ascn=42
          if w5<>"enum"
            a++ : skiplspace(w4,a)
          endif
        endif
        w5="sys"
      endif
    endif
    w3+=w5
    if ascn=44
      a++ : w3+=","
    endif
    if ascn<>41
      w3+=" "
    endif
  loop
  if w2
    w2=" as "+w2
  endif
  '
  'CAPTURE MODIFIERS
  '
  skiplspace(s,i)
  a=i
  do
    select ascn
    case 0 to 31  : exit do
    case 58 to 59 : exit do
    case 61       : exit do
    case 123      : exit do
    end select
    w5=tword(s,i)
  loop
  if i>a
    w2+=" "+mid(s,a,i-a)
  endif
  nextinstruct(s,i)
  return w3+w2+cr
end function
'*/

function casesyntax(string*s, int*i) as int
===========================================
int f=i
string wr
nextinstructla(s,f)
if ascn=44
  i=f+1
  nextinstructla(s,i)
  return 4 'CASE SERIES
else
  wr=wordahead(s,f)
  f=0
  if wr="case"
    f=nwd
    wr=wordahead(s,f)
    if wr<>"else"
      return 2 'CONTIGUOUS CASES
    endif
  elseif wr="to"
    return 3 'RANGE TESTING
  endif
endif
end function


int xep
'
function SolveCaseSym(string*s, int *i,tp,*f,*cp) as string
===========================================================
int a,d,g,p,v,bg,ng
string wr,w1
cp=0
xep=0
'PWORD AUTOMATICALLY STRIPS LEFT '%'
skipspace(s,i)
bg=i
'nextinstruct(s,i)
do
  wr=pword(s,i)
  select ascw
  case 39 ' SINGLE QUOTE OR SKIPPED COMMENT
    if caseval(s,i)=0
      exit do 'COMMENT
    endif
    if ascw<>39
      i=swd 'REPARSE SYMBOL
    endif 
  case 45   : '-'   :
    if isa(ascn)
      ng=1
    else
      exit do
    endif
  case 60   : cp or=1        'case < ...
  case 61   : cp or=2        'case = ...
  case 62   : cp or=4        'case > ...
  case else : exit do        ' 
  end select
loop
'
if isq(ascw)
  typ=cpuw 'ASCII CASE SUPPORTS UP TO 4 CHARS (32 BIT)
  g=1 : p=2 : v=0
  do
    d=asc(wr,p)
    if (d=ascw)or(d=0)
      exit do
    endif
    v=d*g+v
    g*=256
    p++
  loop
  wr=str(v)
elseif nisxn
  '
  if ascn=0x74 't
    if wordahead(s,i)="to"
      goto nsolvecase
    endif
  endif
  '
  a=0
  if ascw=91
    a=1  'variable expression
  elseif ascw=40
    a=1  'variable expression
  elseif mc<-3 '-17 -16 -5 -4
    if mc>-18
      a=1  'functionS etc
    endif
  endif
  if a
    i=bg
    xep=1
    cnd=1
    parx=1024
    op=0
    skiplspace(s,i)
    wr=express(s,i,0)
    cnd=0
    parx=0
    return wr
  else 'CONSTANT EXPRESSION
    inserts(s,wr+" ",i)
    dv=metaval(s,i,wr,d)
    skiplspace(s,i)
  endif
endif
'
nsolvecase:
'
if ng
  int ta=asc(wr)
  if isn(ta)
    wr="-"+wr : ng=0
  else
    'NEGATIVE VARIABLE
    if (typ<0x40)and(tp<0x40)
      g=1
      select typ and 15
      case cpuw : w1=qecx : g=0
      case 4    : w1="ecx"
      case 2    : w1="cx"
      case 1    : w1="cl"
      end select
      if g
        wpfx+="xor "+qecx+cm+qecx+cr 'zero reg
      endif
      wpfx+="mov "+w1+cm+wr+cr
      wpfx+="neg "+qecx+cr
      select tp and 15
      case cpuw : wr=qecx
      case 4    : wr="ecx"
      case 2    : wr="cx"
      case 1    : wr="cl"
      end select
    endif
  endif
endif
if isfloat(tp)
  wpfx+=operi(1,typ,wr)+cvtai(typ,tp)
  if ng
    wpfx+="fchs"+cr 'NEGATIVE VARIABLE
  endif
  wr=""
endif
f=CaseSyntax(s,i)
return wr
end function


  function extractvarname(string*s) as string
  ===========================================
  int a,b,c,i
  b=1
  i=len(s)+1
  while asc(s,b)=42
      b++
  wend 'LEFT STRIP '*'
  if asc(s,i-1)=44
    a=1    'exclude comma
  endif
  return mid(s,b,i-b-a)
  end function




  'RESOLVE HIGH LEVEL EXPRESSION, MACROS ETC INTO ASSEMBLER


  procedure GlobalClear()
  =======================
  '
  int a
  '
  cpa=0
  parx=0
  brc=0
  asce=1
  lclv=0
  wths=""
  wthf=0
  ths=0
  prec=0
  phr=0
  ipe=0
  nsl=0
  fq=0
  fql=1
  dv=0
  asi=0
  cnd=0
  pef=0
  pem=0
  nst=0
  pdr=0
  bref=1 'default byref
  tmnt=0
  libe=1
  dlb=1
  expf=0
  nrs=0
  funi=0
  libr=""
  extn=0
  cas=0
  cnst=0
  cbri=0
  uniq=0
  cpuw=4
  ispr=0
  typk=0
  datc=0
  dati=0
  lnkc=""
  lnkd=""
  stkb=0
  vaf=0
  pakd=0
  ccx=0
  casg=0
  cbi=1
  dimi=0
  cboolf=0
  jn=0
  tmpi=0
  epfx=""
  plp=1
  plq=0
  vwb=0
  vwe=0
  asxp=0
  cpoint=0
  sr2=58
  ct2=59
  lpath=""
  ipath=""
  cfile=""
  opers=""
  nsi=0
  nsk=0
  nsp=0
  rps=0
  hiex=""
  dct=0
  wct=0
  independent=0
  cnsl=0
  eord=0
  impo=0
  uop=0
  opnameu=""
  opns=""
  opnsl=""
  casf=0
  arcm=0
  fpnp=1    'FPNPRECISION DOUBLE
  clsi=0
  rss=""
  atx=0
  etx=0
  etxx=0
  '
  for a=0 to 15  : wva(a)="" : next 'CLEAR DECLARATION BUFFERS
  '
  end procedure



  procedure InitCompiler()
  ========================
  int i
  globalClear()
  '
  cpuw=sizeof sys 'provisional 32/64
  regnames()
  InitDefTables()
  intriset(kernel_funs)
  intriset(x86_registers)
  end procedure

  function cbrencah(string*s, int*i,c) as int
  ===========================================
  int a,b
  skiplspace(s,i)
  a=i : b=ascn
  nextinstruct(s,i)
  if ascn=123
    if cbri>99
      ert=101 : ers="Too many '{' " : exit function
    endif
    cbrk(cbri)=c
    cbri++
    i++
    skiplspace(s,i)
    return 1
  else
    i=a : ascn=b
  endif
  end function


  procedure translate(string*ss)
  ==============================
  '
  $ exei="jmp fwd _end_if"+nsls(1)+cr+"._end_cnd"+nsls(1)+cr  'ELSEIF
  $ exdo="jmp long _do"+nsls(2)+cr+"._end_do"+nsls(2)+cr      'ENDDO
  '
  string exitdo=cr+"exit do"+cr+"endif"+cr         'COND EXIT
  string contdo=cr+"continue do"+cr+"endif"+cr     'COND CONTINUE


  '===========================
  'LOCAL VARIABLES DESCRIPTION
  '===========================

  ' s     source string
  ' fp    include string index
  ' qf    inline quote flag
  ' i     source index
  ' sst() source string buffers for include
  ' a     general ascii value
  ' k     general purpose
  ' m     general purpose
  ' nd    dim code
  ' v     general purpose
  ' w     general purpose
  ' w1.w9 param
  ' wc    case expression
  ' wd    word string
  ' wr    word string
  ' wm    word string
  ' wn    word string
  ' ws    word string
  ' wt    word string
  ' wv    last variable name dim
  ' typo  type definition flag
  ' aoff  offset value for local vars etc
  ' asce  ascending/descending flag
  ' regs  macro used to specify index regs for variables
  ' op1   hold op
  ' opp   proc op
  ' sih   single inheritance
  ' mo    mo flag for subroutines
  '-------------------------
  ' typa  type of variable
  ' typr  type of first variable
  ' typc  type of accumulator in use
  ' typp  return type of procedure
  ' ccp   call convention type of provedure
  ' typl  left hand (assigment type in use
  ' bs    bracketed expression present and skipped
  ' va    hold varf
  ' bv    byval flag
  ' tpt   indirection counter
  ' ali   alias   for imported or expoted functions
  ' lby   library for imported functions
  ' it    identified type
  ' atf   flag indicating exported function
  ' lcl   flag stack params or locals
  ' lcls  flag local/param strings used
  ' blcl   block local ebp code (positions)
  ' tm    t marker for splitting t
  ' fdd   def flag
  ' fro   for flag
  ' noin  noinit flag prevents local vars being set to 0
  ' eord  export ordinal counter
  ' mage  binary image (for pe formatting)
  ' clsi  class record index
  ' reto  tally offset for ret n instruction
  ' retb  tally base offset for ret n instruction
  ' ml    mp lower local boundary holder
  ' tdst  typedef struc flag
  ' unip  union flag
  ' dcp   declared C prototype
  ' deco  C style typedef function function flag
  ' pn    parameter counter for function prototypes
  ' ccx   calling convention extern block default
  ' opa   flag for optional params
  ' typd  inferred type in dim/declare statements
  ' cnsl  console mode flag for PE file SubSytem 3 (normally 2)
  ' bpb   Block param bracket flag
  ' epi   Epilog flag
  ' typf  default type (c style prototype)
  ' df    indirection count (c style prototype)
  ' dg    default type (prototype default type establish flag)
  ' fc    byval/byref spec
  ' bj    mark start of output code block (#show)
  ' pf    pointer function flag
  ' cbj   cbuf position
  ' sw    first word in statement
  ' sln   single line conditional
  ' ttc   class function table entries tally
  ' tuc   class function table inherited entries tally
  ' shf   #show filename
  ' shs   #show source line
  ' dfv   default value flag for prototypes
  ' lnks  proc link instruction
  ' nmth  flag to suppress conversion of procs to methods
  ' hasfun flag to indicate MakeHeader detected funcs/procs

  int a,b,c,d,e,f,g,i,k,m,nd,p,q,u,v,w,qf,typo
  int bs,va,bv,tpt,it,tm,fdd,hasfun
  int op1,typa,typc,lent1
  int opp,fro,tdst,unip,dcp,deco
  int pn,opa,typd
  int bpb,epi,typf,df,dfv,dg,fc,bj,pf
  int cbj,funbr,sln,ttc,tuc,nmth,mo

  int relaxed=0 'AUTODIM OFF

  string s,w1,w2,w3,w4,w5,w6,w7,w8,w9,wd,wm,wn,wr,ws,wt,wv
  string ali,lby,mage,wc,sw,shf,shs,lnks
  string forb,fore,fors,nwe,nws 'in iterations

  '==============
  'INITIALISATION
  '==============
  '
  int lmtp=-30
  '
  start_prep:
  '
  'gsrc global source
  s=ss
  '
  t=space(len(s)*2+1000)
  '
  i=1 : j=1 : cbi=1
  '
  InitCompiler()
  '
  ixb=1 'DEFAULT INDEX BASE

  'FIRST WORD COMMANDS
  w1=wordahead(s,i)
  if w1="#view"
    vew=2 : i=nwd
  endif
  if w1="#prep"
    vew=3 : i=nwd
  endif
  '

  '
  '####################
  '####################
  '
  ' #######    ######                  #
  '  ##    #  #      #                 ##
  '  ##    #  #      #  ###################
  '  ##    #  #      #  ### MAIN ############
  '  ##    #  #      #  ###################
  '  ##    #  #      #                 ##
  ' #######    ######                  #
  '
  '####################
  '####################
  '
  mainstart:
  '=========
  '
  regs=regss 'STATIC REGISTER QEBX
  mest=me    'LOCAL DEFINITIONS FENCE
  mesb=me    'CORE DEFINITIONS FENCE
  '
  epif=0
  newstatvar() 'needed for 64bit
  '
  '========================
  mainloop: 'main line loop
  '========================
  '
  if asc(s,i)=13
    i+=2
  endif
  sttl=i
  newline=1
  typr=0
  '
  '======================
  do 'main statement loop
  '======================
  '
  '
  if ert
    goto exitap
  endif
  sig=""
  op=0
  wr=pword(s,i)
  if ert
    goto exitap
  endif
  '
  if ascn=123
    if mc>0
      inserts(s,"=",i) : ascn=61 : nwd=i 'massign
    endif
  endif
  '
  if newline
    sw=ow
  endif
  '
  '
  select mc
  '
  case 0
  '
  ' --- === comment line
  'also  ... ellipsis
    select ascw
    case 43,45,46,61
      if ascw=asc(s,swd+1)
        if ascw=asc(s,swd+2)
          endline(s,i)
          goto mainloop
        endif
        '++ -- PRE
        if (ascw=43)or(ascw=45)
          inserts(s,wr,i)
          goto generalexp
        endif
      endif
    end select
  '
  '
  if isc(ascw) 'COMMENTS
    a=ascn
    b=asc(s,i+1)
    endline(s,i)
    w1=mid(s,swd,i-swd)
    if a=33
      'CAPTURE METACOMMENTS '!...
    elseif (a=95)and(b=34)
      cfile=mid(w1,3) ' "..."
    elseif a=95 'lnm
      lnmks=mid(w1,3)
    elseif newline=1
      continue do 'OMIT OTHER WHOLE LINE COMMENTS
    endif
    appendt(w1+cr) 'CAPTURE
    goto mainloop
  endif
  '
  select ascw
  '
  case 58 'COLON : 
  '
  appendt(": ") :  goto mainloop 'COLONS AS STATEMENT SEPARATORS OR ASM PREFIXES
  '
  '
  case sr2 'POSSIBLE SEMICOLON AS SEPARATOR; 
  '
  appendt(cr) : goto mainloop
  '
  '
  case 35 'HASH #
  '
  b=asc(wr,2)
  if b=35
    if asc(s,swd+2)=35
      '
      'VIEW MARKERS ###
      '
      if vwb=0
        vwb=1 : w1="#view"
      else
        vwe=1 : w1="#endv"
      endif
      appendt(w1+cr) : goto mainloop
    endif
    '##var runtime binding
    inserts (s,"proc [ebx+40] "+chr(34)+mid(wr,3)+chr(34)+cr,i)
    continue do
  endif
  if mp=0
    ers="Unidentified " : ert=20 : goto exitap
  endif
  '
  '
  case 123 'BRACE START BLOCK {
  '
  i=swd : cbrencah(s,i,0)
  if ert
    goto exitap
  endif
  goto mainloop
  '
  case hasa 'MID-LEVEL CODING MARKER 124 '!'
    endline(s,i)
    appendt(mid(s,swd,i+2-swd))
    goto mainloop
  '
  case 125 'BRACE END BLOCK }
  '
  if cbri>0
    cbri--
    a=cbrk(cbri)
    select a
    case 0
      goto mainloop
    case 1
      b=i
      nextinstruct(s,i)      
      w1=tword(s,i)
      if w1="else"
        md=15 : goto endcons 'ELSE
      endif
      if w1="elseif"
        md=16 : goto endcons 'ELSEIF
      endif
      i=b  : md=17 : goto endcons  'ENDIF
    case 2
      md=18 : goto endcons  'END DO
    case 3
      md=19 : goto endcons  'END WHILE
    case 4
      md=34 : goto endcons  'NEXT
    case 5
      md=20 : goto endcons  'END SELECT
    case 1001 to 1100
      md=a-1000
    case 1101 to 1200
      nd=a-1100 : goto endpro
    end select 'block type a
    '
    goto endings
  endif
  '
  case 101 'e 'END
  '
  if ow="end"
    if isxn
      if funi
        w1="jmp fwd _end_proc"
      else
        w1="jmp fwd _end_prog"
      endif
      appendt(w1+cr)
      goto mainloop
    endif
    'otherwise end something
    wr=tword(s,i)
    nd=0 : md=0
    a=lookupm(wr)
    if a
      mc=drc(a).a
      md=drc(a).f
      '
      select mc
      case -14
        goto endings
      case -13
        if md=7 'WITH
          wthf=0
          wths=""
          goto mainloop
        endif
        if md=23 'NAMESPACE
          endline(s,i)
          SetNamespace(s,i)
          goto mainloop
        endif
      case -18, -20
        'macro constructs with endings
        wr+="_end"
        a=lookupm(wr)
        if a
          inserts(s,wr+" ",i)
          goto mainloop
        endif
      end select
    endif
    ert=201
    ow=wr
    ers="Unknown end" 
    goto exitap
  endif
  '
  case she : '#SHOW END MARKER
    w2=shs+cr+cr+">>>>"+cr+
    cr+mid(t,bj,j-bj)+cr+">>>>"+
    cr+cr+itran(mid(t,bj,j-bj))+cr
    shs=""
    if shf
      putfile shf,w2
      shf=""
    else
      print w2
    endif
    shd=0 '#show flag off
    goto mainloop
    '
  end select 'ascw
  '
  if nfnd
    if lookupc(wr)=-1
      if relaxed
        jmp fwd autodims
      else
        ert=256
        ers="not found"
        goto exitap
      endif
    endif
  endif
  '
  'mc selection continued ...
  '--------------------------
  '
  case -10
    if newline
      typr=typ             'REGISTERS
    endif
  case -13
    goto maino2            'O2 KEYWORDS
  case -14
    newline=0
    goto maino2h           'O2H KEYWORDS
  case -19
    appendt(wr)
    goto mainloop          'TERMINATION MACROS
  case -22
    appendt(mrcso(mp,1))
    continue do            'INTERNAL CODE MACRO
  case -29
    w1=wr : mc=-14 : md=36
    goto gowhere           'SUBROUTINE  'GOSUB IMPLICIT
  'case -30
  '  appendt wr
  '  goto mainloop         'LABEL
  'case -31
  '  appendt wr
  '  goto mainloop         'NUMBER  
  case -32 
    appendt(stodata(wr))
    continue do            'STRING LITERAL
    '
  'case -33
  '  appendt wr
  '  goto mainloop         'NUMBER FROM ENUMERATION
  '
  end select 'mc
  '
  md=0
  '
  '++ -- POST
  '
  if typ
    if ascn=asc(s,i+1)
      a=0
      if ascn=43
        if cnsterr()
          goto exitap
        endif
        a=12
      elseif ascn=45
        if cnsterr()
          goto exitap
        endif
        a=13
      endif
      if a
        w1=wpfx+operi(a,typ,wr) 'itr i++=
        i+=2
        goto cleardown
      endif
    endif
  endif
  '
  '
  'CHECK FIRST WORD IN STATEMENT
  '=============================
  '
  if newline
    '   
    '
    select ascw
    '
    case 36 to 37 '$ % EQUATES
    '
    EncodeEquate(s,i)
    if ert
      goto exitap
    endif
    goto mainloop
    '
    '
    case 48 to 57 'LINE NUMBER LABELS
    '
      if ascn=58
        if i=swd+lenw
          i++
          appendt("._"+wr+cr)
          continue do
        endif
      endif
    '
    case 91 'SQ BRACKET [
    '
    'if (varf=0)and(isxn()<>0)and(typ>0)
    '  ert=100 : ers="Syntax:"+wr : goto exitap
    'endif
    '
    case 44 ' COMMA
    '
    ert=100 : ers="stray comma:" : goto exitap
    '
    '
    'BRACKETS FOR SCOPING
    '
    case 40 ' (
    '
    nest()
    if ert
      goto exitap
    endif
    appendt(sp)
    goto mainloop
    ' 
    '
    case 41 ' )
    '
    if epgi[brc] '#ENDING
      inserts(s,left(epgs(brc),epgi(brc))+ep,i)
      epgi[brc]=0
      goto mainloop
    endif
    unnest()
    if ert
      goto exitap
    endif
    appendt(ep)
    goto mainloop
    '
    case 61
    '
    op=1
    asxp=1
    w1=express(s,i,typr)
    asxp=0
    goto cleardown '=x left in accum
    '
    end select
    '
    '
    'DOT LABELS
    '
    if ascw=46 'COLON LABELS ARE PRE-CONVERTED IN MWORD()
      if asc(wr,2)<>46
        lbw=mid(wr,2)
        newrecord lbw
        drc(me).a=lmtp
        lmtp=-30
        addme
        appendt(ow+cr)
        if ascn=58
          i++
        endif
        goto mainloop
      endif
    endif
    '
    a=0
    '
    if mp
      if ascw=91
        a=1
      elseif (mc>=0)and(typ>0)
        a=1
      endif 
      if a
        if varf=0
          if typ=0
            typ=cpuw
          endif
        endif
        typr=typ
      endif
    else 'mp==0
      if ascw=91
        typ=cpuw : typr=typ
      endif
    endif
    '


  'INSTANTIATIONS 'C STYLE DIM
  '===========================
  a=0
  select mc
  '
  case -16
    if wr="string"
      a=-1          'STRING PRIMITIVE
    endif
  case -33
     a=1            'ENUMERATION
  case -3
    a=1             'UDT/CLASS OBJECT
  case -15 :                    '
    if isn(ascn)
      if wr="int"
        newline=0
        goto addsrc 'ASM INTERRUPT
      endif
    endif
    a=-1            'C PRIMITIVE
    if wr="sys"
      lent=cpuw
      typ=cpuw      'SYSTEM INTEGER/POINTER TYPE
    endif
  case -8
    a=1             'TYPEDEF REFERENCE
    '
  end select
  '
  'CHECK FOR C STYLE DECLARATIONS
  '
  if a
    '
    if ascn=61 'PREVENT ASSIGNING TO A TYPE ETC
      ert=407 : ers="not a variable" : goto exitap
    endif
    '
    a=captpreproto(s,i,wr,w7)
    '
    'IS A VARIABLE (INCL ENUMERATION)
    '
    if (a=0)or(a=123)
      if ascn=44
        i++ : nextinstruct(s,i) 'LINE FOLLOW-ON
      endif
      inserts(s,wr+" ",i)
      pf=0
      nd=4
      goto directdim 'ALL NON-PROCEDURES
    endif
    '
    'OTHERWISE  A PROCEDURE
    '
    '
    fundec: ' ENTRY POINT FOR EG: TYPEDEF INT ( *FUNC) (LONG* pv,...);
    =======
    '
    'FUNCTION OR SUB
    '
    if wr="void"
      w2="" 'NOTE THAT VOID* IS A FUNCTION
    else
      w2=wr
    endif
    '
    w1=""
    if a=1                       'IS PROCEDURE POINTER
      pf=1                       'SET FUNCTION POINTER FLAG
      i++                        'SKIP LEFT BRACKET
      while ascn<>rbr
        icas=1 : wr=bword(s,i)   'DUMPS ANY MACRO OR '*'
        if ascw=lbr
          i=swd : capture(s,m,i,0) 'SKIP INNER BRACKET CONTENT
        endif
      wend
      i++                       'SKIP RIGHT BRACKET
    else 'OTHERWISE DIRECT
      w1=""
      icas=1
      wr=bword(s,i)
    endif
    '
    nextinstruct(s,i)
    '
    w3=w1+wr+w7+translateproto(s,i,w2) 'function*abc() as x
    assieq(s,i)
    '
    nproto:
    =======
    '
    if (ascn<>123)and(ascn<>61)
      nd=18 'DECLARE ONLY
    else
      nd=11
    endif
    inserts(s,w3,i)
    ow="" : goto directdim 'ALL PROCEDURES
    '
  endif 'C declarations
  '
  'END INSTANTIATIONS
  '
  '
  endif 'FIRST WORD IN LINE newline=1
  '
  autodims:
  =========
  '
  newline=0
  '
  if ascn<>61
    goto nrelaxed
  endif
  if isa(ascw)=0
    goto nrelaxed
  endif
  '
  if (mp<>0)or(mc<0)
    goto nrelaxed
  else
    if relaxed=0
      ers="not defined" : ert=42 : goto exitap
    endif
  endif
  '
  enlet:
  '=====
  '
  w3=ow
  if ascn=61
    i++ : nextinstruct(s,i)
  endif
  w2=dimtype(s,i)
  inserts(s,w2+" "+w3+cr+w3+"=",i)
  goto mainLoop


  nrelaxed:
  '========
  '
  '
  'PROCEDURE OR EXPRESSION
  '=======================
  '
  if (varf>=8)or(mc=-17)
    if ascn<>91
      w2=""
      goto procs 'normal procedure (not an array of procedures)
    endif
  endif
  '
  if typ=0
    goto nassign  'SKIP ASSIGNMENT, NOT TYPED, JMP/CALL ...
  endif
  '
  '
  '
  '                    ####          ####
  '                    ##              ##
  'RESOLVED VARIABLES: ##  [reg+offs]  ##
  '                    ##              ##
  '                    ####          ####
  '
  '
  '
  'LEFT SIDE VARIABLE ASSIGNS
  '==========================
  '
  osg=owa
  psg=wpfx 'ASSIGNMENT OPERAND ADDRESS RESOLUTION
  wsg=wr   'ASSIGNMENT OPERAND
  a=ascn
  b=asc(s,i+1)
  if ascn<>61
    if (a=60)and(b=62) '<>' multiassign
      jmp fwd nascn61
    endif
    if nisxn
      w3=wordahead(s,i)
    else
      if rps
        w1=""
        goto cleardown 'NO ASSIGN MACRO FUN
      endif
      nwd=i
    endif
    if (asc(s,nwd)<>61)and(asc(s,nwd+1)<>61)
      if typr
        inserts(s,owa+" ",i) : typr=cpuw
        op=0 : rps=0 : hiex="" : epfx=""
        w1=express(s,i,typr) 'naked statement
        goto cleardown
      endif
      'itr registers, commas etc pass thru
      goto addsrc
    endif
  endif
  '

  ========
  nascn61:
  ========
  '
  '
  wr=tword(s,i)

  '
  '
  '      #
  '      #     ########
  '   #######
  '      #     ########
  '      # 
  '
  '=========
  'leftside:
  '=========
  '
  cpa=identopeq(s,i,w1) 'IDENTIFY OP
  '
  if cnstr
    ers="consts are read-only" : ert=125
    goto exitap
  endif
  '
  'CHECK FOR MULTIPLE ASSIGNMENTS
  'ARRAY ASSIGNMENTS & OBJECT ASSIGNMENTS
  '
  '<> <= => ={ {
  '
  nextinstruct(s,i)
  if (a=60)or(b=62)or(ascn=123)
    massign(s,i) 'MULTIASSIGN
    w1=""
    goto cleardown
  endif
  '
  'CREATE SINGLE ASSIGNMENT CODE
  '
  '
  if mp>0
    if cpoint
      if typ>=typh
        typ=cpuw
        typr=cpuw
      endif
    endif
    '
    'ZSTRING / CHAR POINTER ASSIGN STRING
    'ASSIGN POINTER ONLY
    if iszstra(typr)
      a=ind
      if varf=1
        a=0
      endif
      if (a<>0)or(varf=3) 'exclude direct string member
        if not refaddr(psg)
          ert=725 : ers="unable to get address"
        endif
        w2=pword(s,i) 'LOAD OPERAND
        if nisxn
          ers="must be a string operand" : ert=800
        endif
        if ert
          goto exitap
        endif
        w1=makestrptrfun(w2)+psg+"mov "+wsg+cm+w2+cr
        goto cleardown
      endif 'ptr
    endif 'iszstr
    '
    if asc(psg)=0x6c 'l
      if wsg=qedi
        if left(psg,4)="lea "
          ert=727
          ers="unable to set new address"
          goto exitap
        endif
      endif
    endif
    '
    if typr<typh
      'ASSIGNMENT FOR PRIMITIVE TYPES
      asg=psg+operi(2,typ,wsg)
      '
      'ASSIGNMENT PROCEDURE FOR DYNAMIC STRINGS
      if (typ>=0xe0)and(typ<0x100)
        w2=mid(mrcso(mp,1),3,3)
        if w2="bp-"
          a=asstrla
        else
          a=asstrga 'LOCAL GC / GLOBAL GC
        endif
        if shd
          if a=asstrga
            asg+=cmt+asstrgc+cr
          else
            asg+=cmt+asstrlc+cr
          endif
        endif
        asg+=rtlo(a)
      endif
    endif
  else 'mp=0
    'W1 CONTAINS ASM INSTRUCTION
    asg=psg+w1+wsg+cm+cpua+cr
  endif 'mp>0
  '
  if ert
    goto exitap
  endif
  '
  if iss(ascn)
    w1=asg
    goto cleardown 'NO RIGHT SIDE
  endif
  '
  '
  'RIGHT SIDE
  '==========
  '
  'SIMPLE INTEGER ASSIGNMENTS (OPTIMISATION)
  '
  if compactassign(s,i,typr,w1)
   goto cleardown
  endif
  '
  '
  generalexp:
  '==========
  '
  if cpa>=71
    wr=w1 '&&'  '||'  '^^'
  endif
  '
  string loadh
  '
  if typr>=typh
    asg=""
    '"save" operator defined?
    if findop(typr,"save",w2)
      loadh="save"
    else
      loadh="move"
    endif
    if cpa>2
      w3=wr+"="
      if findop(typr,w3,w2)
        'using osg as accumulator
        'optimization for concatenators
        op=0
        w1=express(s,i,0)
        rps=16
        =================
        if not accg
          if typg=0
          typg=cpuw 'default type
          endif
          if opg<2
            accg=owa
            jmp fwd cpassg
          endif
          accg=newtmpvar(typename(typg))
          wg=mrcso(qme,1)
          'PROCESS AND SAVE IN ADVANCE
          asg=operi(2,typg,wg)
          '
          'ASSIGNMENT PROCEDURE FOR DYNAMIC STRINGS
          if (typg>=0xe0)and(typg<0x100)
            w5=mid(wg,3,3)
            if w5="bp-"
              a=asstrla
            else
              a=asstrga 'LOCAL GC / GLOBAL GC
            endif
            if a=asstrga
              asg+=cmt+asstrgc+cr+rtlo(a)
            else
              asg+=cmt+asstrlc+cr+rtlo(a)
            endif
          endif
        endif  'not accg
        =================
        cpassg:
        =================
        w1=epfx+w1+asg
        hiex+=storecode(w1)
        epfx=""
        hiex+=w2+"("+osg+cm+accg+")"+cr
        goto cleardown '+= *= etc
      endif
    endif
  endif
  '
  if cpa>2
    inserts(s,osg+"="+osg+" "+wr+" ",i)
    goto mainloop 'A+=B' TO:  'A = A + B'
  endif
  '
  op=0
  '
  expract:
  ========
  '
  if typr>=typh
    asg=""
    op=0
  endif
  '
  w1=express(s,i,typr)+asg
  '
  if rps and 8
    a=instrevn(-1,hiex,"#snip")
    if a
      hiex=left(hiex,a-1)
      w1=asg
      goto cleardown
    endif  
  endif
  '
  'ASSIGNMENT BY LOAD/SAVE OPERATOR
  '
  if typg>=typh
    if rps=0
      if typr<typh
        goto cleardown 'address assign etc
      endif
    endif
    if hiex
      if findop(typg,loadh,w2)
        w1=epfx+w1 : epfx=""
        if rps<>16
          if w1
            hiex+=storecode(w1)
            rps=16
          endif
        endif
        if rps<>16
          if loadh="move"
            if asc(accg)=127 'temp accum
              replacewd(hiex,accg,osg,0)
              goto cleardown
            endif
            hiex+=w2+"("+osg+cm+accg+")"+cr
          elseif loadh="save"
            hiex+=w2+"("+osg+")"+cr
          endif
          goto cleardown
        endif 'rps<>16
      endif 'findop loadh
    endif 'hiex
  endif 'typg>=typh
  '
  'typhes:
  '
  if typr>=typh
    'EXPRESSIONS USING HIGHER TYPE OPERANDS
    'RPS
    '
    if typr=typg
      rps=16
      if opg<=1
        w1=""
        w3="@"+owa
      else
        if cpuw=8
          'rax gets used passing params
          w3=qedx
          w1+="mov rdx,rax"+cr
        else
          w3=qeax
        endif
      endif
      '
      m=typr-typh  'record
      nd=drc(m).b 'size
      'itr arrays
      w4=str(nd)
      'DEFAULT ASSIGN BY COPYING FROM VARIABLE
      hiex+=storecode(w1)+"copy @"+osg+cm+w3+cm+w4+cr
    else
      'NOT A SIMPLE COPYING OPERATION
      ert=203
      ers="Unable to assign types "+sog+" "+" to "+osg
      '+" " typr " " typg+ cr+hiex+cr+w1
    endif
    w1=""
  endif
  '
  goto cleardown
  '
  '
  'GENERAL ASSIGNMENT
  '
  goto cleardown
  '
  nassign:
  '=======  
  '
  w2=""
  '
  'ASM CALL/JMP OR IMPLIED PROCEDURE
  '=================================
  '
  c=dic(" call 1, jmp 2, ",wr)
  if c
    typ=0
    b=0
    w4=wr
    w2=wordahead(s,i)
    if w2="far"
      m=i : endline(s,i)
      appendt(w4+" "+mid(s,m,i-m)+cr) 'CALL FAR / JMP FAR
      goto mainloop
    endif
    '
    if idword(" fwd long short ",w2)
      i=nwd
    else
      w2=""
    endif
    '
    'CHECK FOR CALL CALL..
    '
    nobr=1 'prevent '()' brackets being interpreted as array
    do
      wr=pword(s,i)
      if wr="call"
        continue do
      else
        exit do
      endif
    loop
    nobr=0
    '
    if isxn
      if (mc=-5)or(mc=-4) 'obtain vector
        c=4
        if ascw<>91
          w1=pword("@"+wr,1)
          if ascw=91
            wr=w1
          else
            wpfx=""
          endif
          skiplspace(s,i)
        endif
      endif
      appendt(epfx+wpfx+w4+" "+w2+" "+wr+cr) 'itr calling basic proc (compact mode)
      epfx=""
      goto mainloop
    endif
    if varf<8
      varf=8
    endif
    w2="call "
    goto procs
  endif 'c
  '
  '
  if varf<8
    goto nproc
  endif
  '
  '
  procs: 'ALL COMMAND LEVEL PROCEDURES
  '===================================
  '
  '
  w3=owa
  c=instr(w3,".")
  if c
    b=-1
    w4=mid(w3,c+1)+"_"
    findmember(w4,wr,b)
    if b
      if varf>=8
        inserts(s," "+left(w3,c)+w4+" ",i)
        w1="" : rps=0
        goto cleardown
      endif
    endif
  else
    a=lookupm(w3+"_") 'pseudocommands
  endif
  if a
    inserts(s,w3+"_ ",i)
    w1="" : rps=0
    goto cleardown
  endif
  skiplspace(s,i)
  a=ascn
  if a<>lbr
    if wr="print"
      if not isq(a)
        w3+=" "+qu+qu
      endif
    else
      w3+="("+captsr(s,i)+")"
    endif
  endif
  inserts(s,w2+w3+" ",i)
  '
  w1=express(s,i,0)
  '0x74
  '
  'DUMPING RETURN VALUES
  if (typ>=0x40)and(typ<0x80) 'floats
    w1+="fstp st0"+cr 'dump float
  elseif (typ>=0xc0)and(typ<0x100) 'dynamic strings
    w1+=logas() 'mark for deletion
  endif
  '
  '
  cleardown:
  '=========
  '
  if ert
    goto exitap
  endif
  '
  jn=0   'clear string joining flag itr
  if dts>0
    w1+=rtl(deltmpa)
    dts=-1 'deleted temp strings
  endif
  '
  if epfx
    w1=epfx+w1
    epfx=""
  endif
  '
  if rps
    if w1
      hiex+=storecode(w1)
    endif
    inserts(s,hiex,i)
    if shs
      shs+=cr+cr+">>>>"+cr+cr+hiex '#SHOW
    endif
    hiex=""
    rps=0
    dct++ 'code expansion
  else 'rps=0
    dct=0 'resolved code
    appendt(w1) 'FULLY RESOLVED TO ASSEMBLY CODE
  endif
  '
  skiplspace(s,i)
  '
  cnstr=0 : cpa=0 : fpum=0 : nmth=0
  nprec=0 : parx=0 : divi=0
  psg="" : asg="" : osg=""
  '
  goto mainloop
  '
  '
  endings:
  '========
  '
  select md
  case 09 :           goto endpro   '          END 'SUB
  case 10 :           goto endpro   '          END 'FUNCTION
  case 11 :           goto endpro   '          END 'METHOD
  case 34 :           goto endcons  '          NEXT
  case 31 : md=34   : goto endcons  'FOR    to NEXT
  case 13 : md=17   : goto endcons  'IF     to ENDIF
  case 21 : md=18   : goto endcons  'DO     to ENDDO
  case 23 : md=19   : goto endcons  'WHILE  to ENDWHILE
  case 29 : md=20   : goto endcons  'SELECT to ENDSELECT / SWITCH TO ENDSELECT
    '
  case 37 'END METHODS OF  
    '
    'INSERT TABLE BUILDING CODE ETC
    '
    if clsi
      w2=mrcso(clsi,0) 'name
      w1=mrcso(clsi,3)+ep+"|xc "+w2+cr
      wr+=" of "+w2 'label for vew
      clsi=0
    else
      ert=107 : ers="Class not defined" : goto exitap
    endif
    '
    if vew
      if wr="}"
        wr=""
      endif
      w1+="'END "+ucase(wr)+cr+cr
    endif
    '
    endline(s,i)
    inserts(s,w1,i)
    goto mainloop
    '
  case 40 'END SUBROUTINE
    'unnest
    inserts(s,"ret"+ep+"._end_sub_"+cr,i)
    goto mainloop
    '
  case 42 'END SCOPE
    '
    inserts(s,ep,i) 'trigger unnest
    goto mainloop
    '
  case 46  'END EXPORT super
    etxx=0
    goto mainloop
  case 48  'END EXTERN
    '
    atx=etxx : etx=etxx 'export override
    ccx=0 : crg=0 : crgd=0 : libr=""
    goto mainloop
    '
  end select
  '
  '
  ow=wr
  ers="Invalid end"
  ert=99
  goto exitap
  '
  '
  endpro:
  '
  'PROCEDURE EPILOG
  '================
  '
  'CHECK FOR EPILOGS TO INSERT
  if epgi[brc] '#ENDING
    '
  'dual platform code
  w1="
  jmp fwd _end_proc
  _epilogs:
  push rax
  push rdx
  "+left(epgs(brc),epgi(brc))+"
  pop rdx
  pop rax
  ret
  end function
  "
    inserts(s,w1,i)
    epgi(brc)=0
    epif=1
    goto mainloop
  endif
  '
  if atf
    w2=restoreregs
    w3=""
  else
    w2=""
    w3="|xp "+cr 'XP TAG PROCEDURE END
  endif
  '
  if epif=1
    w5="push 0 : call _epilogs : pop rcx"+cr
  else
    w5=""
  endif
  epif=0
  w1=cr+"._end_proc"+cr+
  retvalue()+
  "._return_"+cr+
  w5+
  releaselocalbuffers()+
  managelocalbase()+
  w2+ 'restore regs
  returns()+ep+
  "._over_"+cr+w3+lnks
  appendt(w1)
  lnks=""
  '
  if compact
    '
    a=0
    w1=hex(nsi)+" "+hex(j) 
    'nsi=CURRENT NAMESPACE
    'j=POSITION FOLLOWING FUNCTION ENVELOPE
    if funn=13 'METHOD
      mp=clsi
      w2=fnam
      b=-1
      'locate header record to patch in list position
      do
        findmember(w2,w4,b) 'ALSO ALTERS PLQ (PATCH POSITION)
        if b=0
          exit do 'fail
        endif
        w5=splitsig(sig)
        if w5=fsig
          exit do 'MATCHING PROTOTYPE
        endif
      loop
      if b
        'a=drc(mp).m1+3+plq 'GET PATCH POSITION FOR PROCLIST RECORD POSITION
        a=mrcsp(mp,1,plq) 'GET PATCH POSITION FOR PROCLIST RECORD POSITION
        fnam=mrcso(mp,0)+"."+fnam 'CLASS.METHOD
      endif
    else 'SUBS AND FUNCTIONS <>13
      a=funl
    endif
    '
    if a
      w3=" "+fnam+fsig+" "
      mid(sps,a)=hex(plistend+1) 'PATCH IN LOCATION OF PROCLIST RECORD
      if (atf<>0)or(flbl<>0)
        w2="? "+fnam+" "+w1+cr+"?" 'PROCEDURE CANNOT BE DELETED
      else
        w2="!" '!' PROCEDURE CAN BE DELETED
      endif
      w2+=w3+w1+cr
      appe(proclist,plistend,w2)
    endif
    '
  endif 'COMPACT
  '
  unnest() 'END OF PROCEDURE SCOPE
  staticvars() 'from local to global space
  '
  nepilog:
  '=======
  '
  if ert
    goto exitap
  endif
  funi=0
  ths=0
  shv=0
  goto mainloop
  'END OF PROCEDURE EPILOG
  '
  nproc:
  '=====
  '
  '
  '
  '##############################
  '
  '     #####    #####   #     #
  '    #     #  #     #  #     #
  '    #     #        #  #     #
  '    #     #   #####   #######
  '    #     #  #        #     #
  '    #     #  #        #     #
  '     #####   #######  #     #
  '
  '##############################


  if (mc<>-14)
    goto end_o2h
  endif
  '
  '
  '
  ========
  maino2h:
  ========
  ========
  '
  'O2H KEYWORDS
  '
  md=drc(mp).f
  '
  '
  nd=0
  m=0
  select md
  '
  ======
  case 1 'SHARED
  ======
    '
    if shv=0
      shv=mest
    endif
    '
    if isxn
      goto mainloop 'no symbols given
    endif
    '
    rshared:
    '
    wr=tword(s,i)
    a=lookupm(wr)
    if a=0
      ert=501 : ers="Shared symbol not found: "+wr
      goto exitap
    endif
    newrecord(wr)
    drc(me).a=-1
    drc(me).f=a
    addme
    if ascn=44
      i++
      goto rshared 'more symbols
    endif
    goto mainloop
    '
  ======
  case 2 'LET
  ======
    '
    wr=pword(s,i)
    goto enlet
    '
  ======
  case 7 'OPERATOR CUSTOM OPERATOR
  ======
    '
    uop++
    wr=uword(s,i)     'OPERATOR SYMBOL
    w2=str(0x400+uop) 'OPERATOR NUMBER
    w3=uword(s,i)     'PRECEDENCE LEVEL
    opnameu+=" "+w2+" "+wr+" "+w2+" "+w3+cr
    endline(s,i)
    goto mainloop
    '
    '
    '
    '  ############################
    '
    '  #########   ###  ##       ##
    '   #       #   #   # #     # #
    '   #       #   #   #  #   #  #
    '   #       #   #   #   # #   #
    '   #       #   #   #    #    #
    '   #       #   #   #         #
    '  #########   ###  #         #
    '
    '  ############################
    '  'DIM
    '
  ======
  case 4
  ======
    '
    nd=4 'DIM (GLOBAL/LOCAL)
    if funi
      nd=1
    endif
    w1=wordahead(s,i)
    if w1="static" 'DIM STATIC
      i=nwd
      if funi
        nd=3
      endif
      m=1
    endif
    if w1="local" 'DIM LOCAL
      i=nwd
      if funi
        nd=1
      endif
      'itr if not funi
      m=1
    endif
    '
  ======
  case 5 'LOCAL
  ======
    nd=1
    m=1
    '
  ======
  case 6 'STATIC
  ======
    if funi
      nd=3 'STATIC VARIABLES IN PROCEDURES
    else
      'GLOBAL DEFAULT
      nmth=1 'prevent conversion to method
      goto mainloop
    endif
    m=1
    '
  ======
  case 8  'DECLARE
  ======
    nd=18
    '
  ======
  case 9  'FUNCTION
  ======
    nd=11
    '
  =======
  case 10  'SUB 'PROCEDURE
  =======
    nd=12
    if issub(s,i)=0
      goto addsrc 'assembler sub
    endif
    '
  =======
  case 11 'METHOD
  =======
    nd=13
    '
  end select
  '
  '
  'w=swd 'SET BLANKOUT MARKER ?
  '
  '
  'DISTINGUISH FROM ASSEMBLER sub
  '
  '
  pf=0 'CLEAR FUNCTION POINTER FLAG
  '
  int ndd
  if m=1
    w1=wordahead(s,i)
    if idword(" dyn redim ",w1)
      ndd=nd 'hold nd state
      m=0
      goto mainloop
    endif
  endif
  '
  ==========
  directdim:
  ==========
  '
  if ndd=1
    nd=ndd 'preserved local / static
    ndd=0
  endif
  '
  if nmth=0
    if clsi
      if (nd=11)or(nd=12)
        nd=13 'TREAT AS METHOD
      endif
    endif
  endif
  nmth=0
  '
  if nd=0
    goto notdim
  endif
  '
  'TRANSLATE DIM TO VAR AND INITIALISE
  '
  'clear dim state
  w1="" : w2="" : w4="" : w5="" : w6="" : w7="" : w8=""
  wt="" : wm="" : ws="" : sigs="" : sigd="@"
  q=0 : fdd=0 : pn=0 : typd=0 : typf=0 : df=0 : dg=0 : fc=0
  opa=0
  '
  '
  '    #
  '  ##
  ' ##
  ' ##  PROCESS EACH DECLARATION PARAMETER
  ' ##
  '  ##
  '    #
  '
  if nd>10
    'nd=11,12,13,18
    if nd<=13
      prmf=1
      c=i
      CaptHead(s,i)
      CaptBody(s,i,d,1) 'CHECK FOR INNER PROCS
      if undefpro
        'CAPTURE WHOLE PROC EXCLUDING QUALIFIERS
        w1=defpro+ow+" "+mid(s,c,d-c)+cr+undefpro+cr
        i=d
        inserts(s,w1,i)
        w1="" : defpro="" : undefpro=""
        goto MainLoop 'REPROCESS FOR EXTRACTED INNER FUNCTIONS
      endif
      i=c
    endif
    gosub procedurerecord
    funn=nd
    fnam=wn
    fsig=sigs
  else 'ND<=10
    select nd
    case 1
      if funi=0
        ers="Locals must be inside a procedure block" : ow="" : ert=99
        goto exitap
      endif
    case 3
      if not funi
        nd=4  'PROC STATICS WILL BE MARKED FOR TRANSFER
      endif
    case 4
      if funi
        nd=1 'DIM LOCAL
      endif
      if wr="const"
        cnst=1
      endif
    end select
    '
    gosub ParseDim
    cnst=0
    w1=""
    epfx=""
    rps=0
    'string hlis
    'if rps
    'if asce>0
    '  'putfile
    '  hlis+=hiex
    '  'hiex=""
    'endif
    'endif
    goto cleardown 'MAIN
  endif 'ND<=10
  '
  if ert
    goto exitap
  endif
  if nd=18
    goto mainloop
  endif
  '
  '
  '  #
  '   ##
  '    ##
  '    ##
  '    ##
  '   ##
  '  #
  '
  '
  'PROCEDURE BODY FORMATS
  '======================
  '
  'SHORT FORM FUNCTION() AS TYPE =
  '===============================
  '
  assieq(s,i)
  if ascn=61
    i++ : m=i
    endcontline(s,i)
    w1="{ return "+mid(s,m,i-m)+" }"
    inserts(s,w1,i) : ascn=123
  endif
  '
  nextinstruct(s,i)
  '
  '
  'FUNCTION() AS TYPE (..)
  '=======================
  '
  '
  'POSSIBLE {..BODY..}
  '===================
  '
  funbr=cbrencah(s,i,nd+1100)
  '
  if ert
    goto exitap
  endif
  '      '
  'END PROCEDURE BODY FORMATS
  '
  'PROCEDURE PROLOG
  '================
  '
  w1=""
  w2="."+wn
  '
  if (atf<>0)or(flbl<>0)
    w1+=w2+cr 'ADD PLAIN LABEL ABOVE
  endif
  '
  gpc++
  '
  if nd=13 'METHOD
    ' w2="."+mrcso(clsi,0)+"."+wn+sigs 'INCLUDING CLASS NAME
    w2+=sigs
  else 'SUBS ANDFUNCTIONS
    w2=w1+w2+sigs 'INCLUDE PLAIN LABEL
  endif
  '
  '
  'UNUSED PROCEDURES REMOVAL (PASS 3)
  '
  if tranpass=3
    '
    if funn=13 'METHOD
      w1=" "+mrcso(clsi,0)+"."+wn+sigs+" " 'SIGNATURE INCLUDES CLASS NAME + DOT
    else
      w1=" "+wn+sigs+" " 'NORMAL PROCEDURE SIGNATURE
    endif
    '
    a=instr(plp,proclist,w1)
    if a
      plp=a : endline(proclist,plp) : plp+=2 'NEXT PROCLIST RECORD
      if asc(proclist,a-1)=33
        'EXCLUDE BLOCK
        if funbr
          inserts(s,"{",i)
        endif
        captbody(s,i,a,3) 'BYPASS PROCEDURE BODY
        rps=0
        if a
          i=a
        endif
        'METHOD
        if funn=13
          'DELETE TABLE ENTRY IN CLASS HEADER
          w1=mrcso(clsi,3)
          a=instrevn(-1,w1,"|te "+wn+sigs+" ") 'FIND LATEST MATCH
          if a
            b=a
            endline(w1,a)
            a-=b 'length
            'b=drc(clsi).m3+3+b
            b=mrcsp(clsi,3,b)
            midspace(sps,b,b+a) 'BLANK TABLE ENTRY
          endif
        endif
        w1="" : goto nepilog
      endif ' EXCLUDED
    endif ' LOCATED
  endif 'TRANPASS 3 REMOVING PROCS
  '
  if atf=0
    w3="|yp "+cr
  else
    w3="" 'YP TAG PROCEDURE START
  endif
  appendt(w6+w3+"
jmp fwd _over_
|al 10
"+w2+sp)
  nest()
  '
  if ert
    goto exitap
  endif
  '
  mest=me 'LOCAL FENCE (SET BEFORE PARAMS AND LOCALS)
  '
  'GET PARAM OFFSET a
  '==================
  '
  a=2 'return-address and rbp on stack
  if atf
    a+=4 'saved rax rbx rsi rdi on stack
  endif
  a*=cpuw
  retb=a 'a is the offset to reference parameters [rbp+8]...
  '
  '
  'CHECK FOR 'THIS' IN METHODS
  '===========================
  '
  if clsi
    w1=mrcso(clsi,0) 'get name of class
  endif
  if nd=13
    if clsi=0
      ers="Unknown Class for "+ wn : ert=420 : goto exitap
    endif
    'SET THIS
    ths=mest
    vars(w1+" this at "+memreg(qebp,retb)+cr)
    '
    a=retb+cpuw
    lcl=1
  else
    if clsi
      ths=mest 'dummy enables access to static members 'itr virtual?
      vars(w1+"*this"+cr)'create dummy variable
    endif
  endif
  '
  if typp>=typh
    'SETUP RETURN VAR LOCATION
    w1=mrcso(typp-typh,0)
    retr=retb+cpuw
    ndstr=1
    vars(w1+" returnvar at "+memreg(qebp,retr)+cr)
    ndstr=0
    a=retr+cpuw
    lcl=1
  endif
  '
  'SET UP PARAMS
  '=============
  '
  c=ccp 'CALLING CONVENTION
  '
  if (c<>16)and(c<>17)
    vars("sys param at @"+memreg(qebp,a)+cr) 'generic param array
  endif
  '
  localvars()
  asce=1
  aoffl=a
  aoff=a
  '
  'ARGUMENTS
  if wva(2)<>""
    '
    'CHECK CALLING CONVENTION REQUIREMENTS
    if c=8 'PASCAL PARAMS IN REVERSE ORDER
      w2=wva(2) : wva(2)=""
      c=1 : d=1
      do
        endline(w2,c)
        wva(2)=mid(w2,d,c-d)+cr+wva(2)
        c+=2 : d=c
        if d>len(w2)
          exit do
        endif
      loop
    endif
    vars(wva(2))
    'lcl=1  'PARAMETERS
  endif
  '
  b=aoff-retb ' RETURN DUMPING N BYTES (STDCALL ETC)
  reto=b
  drc(mqf).b=b 'BYTE COUNT OF PROTOTYPE
  '
  'still localvars
  asce=-1
  prmf=0
  '
  if rps 'from vars(..)
    'print hiex
    inserts(s,hiex,i)
    rps=0
    hiex=""
  endif
  
  PrepForLocalSpace(pn)
  '
  'noprocparams
  '===========
  '
  wva(1)="" : wva(2)="" 'CLEAR LOCAL AND RETURN PARAMS
  '
  '
  goto mainloop
  'END OF PROCEDURE PROLOG
  '
  '
  '======
  notdim:
  '======
  '
  'nd=0
  '
  =========
  select md
  =========
  '
  '
  =======
  case 38 'RETURN C STYLE
  =======
  '
  if funi=0
    typp=cpuw
  endif
  '
  if isxn
    w1=cr 'NO RETURN PARAM GIVEN
    goto ncsreturn
  endif
  '
  typr=typp
  '
  select typr
  case 0x0               : typr=cpuw
  case 0x40              : typr=0x68 'fpu type treated as double
  case 0xe0 to 0xff      : typr-=32  'return bstring
  case typh to 999999999 : 'typr=0    'force return of address
    a=i
    endline(s,i)
    i+=2
    w1="function="+mid(s,a,i-a)+"exit function"+cr
    inserts(s,w1,i)
    w1=""
    goto mainloop 'REPROCESS
  end select
  '
  'THE RESULT IS LEFT IN THE ACCUM (CPU / FPU / SIMD )
  '
  op=0 : asg="" : c=0 : typ=0
  w3=wordahead(s,i) : b=nwd
  a=asc(s,nwd)
  if isx(a)
    a=asc(w3)
    if isq(a)
      w1=w3 'string literal
    else
      w1=mword(w3,1)
    endif
    if asc(w1)=91
      c=1
      if cpuw=8
        if (typ=typr)and(requiresimd(typ)<>0)
          i=b
          c=2
        endif
      endif
    endif
  endif
  '
  if c=2
    w1=loadsimd(w1,typr)
    goto ncsreturn
  endif
  'RETURNING BSTRINGS - AVOID THE CAT, AND MEMORY LEAKS FROM UNFREED BSTR
  'RETURNING STRINGS BY TRANSFER (REMOVE FROM GC LIST)
  a=(typr-typ) and 15
  if (c=1)and(isdstr(typ)<>0)and(a=0)
    if instr(w1,"[ebp-") 'LOCAL STRINGS ONLY
      if typ<0xe0
        w1=operi(1,cpuw,w1)  'RETURN BSTRING DIRECT
      else
        w1=medi+w1+cr+rtl(trbstra)  'TRANSFER STRING, NO GC
      endif
      i=b
      goto ncsreturn
    endif
  endif
  w1=express(s,i,typr) 'TEMP STRINGS NOT DELETED LATER IN EPILOG
  if requiresimd(typr)
    w1+=fputosimd(typr)
  else
    if (typr>=40)and(typr<0x4f)
      w1+=cpuquad
    endif    
  endif
  '
  ncsreturn:
  '
  if ert
    goto exitap
  endif
  if dts>0
    w1+=rtl(deltmpa)
    dts=-1 'deleted temp strings
  endif
  if funi
    w2="jmp fwd _return_"+cr
  else
    w2="jmp fwd _end_prog"+cr
  endif
  w1+=w2
  goto cleardown
  '
  '
  '
  '------------------------------
  'CHECK FOR START OF INNER SCOPE
  '==============================
  '
  =======
  case 41 'SCRIPT
  =======
  '
  icas=1
  wr=bword(s,i)
  if wr="resource"
    rss+=captureblock(s,i,"script")
  endif
  goto mainloop
  '
  =======
  case 42 'SCOPE 'INNER
  =======
  '
  cbrencah(s,i,md+1000)
  if ert
    goto exitap
  endif
  if ascn<>lbr
    inserts(s,sp,i) 'trigger nest
  endif
  goto mainloop
  '
  =======
  case 25 'EXIT
  =======
  '
  b=swd
  c=0
  '
  if (isn(ascn)=0)and(nisxn()<>0)
    wr=tword(s,i)
    c=dic(" function 1, sub 1, method 1, procedure 1, do 2, while 3, for 4, subroutine 5, if 6, when 6, ", wr)
    if nisxn
      if c=6
        wr="do"
      else
        w2=tword(s,i) : 'sink if / when
      endif
      w3=captsr(s,i)
      inserts(s,"if "+w3+cr+"exit "+wr+cr+"endif"+cr,i)
      goto mainloop 'REPROCESS
    endif
    select c
    case 1 : wr="proc" 'function 'sub 'method
    case 2 : 'do
    case 3 : wr="do" : c=2 'while
    case 4 : 'for
    case 5 : 'subroutine
      appendt("ret"+cr)
      goto mainloop
    case 0
      wr+="_exit"
      a=lookupm(wr) 'word_exit
      if a
        inserts(s,wr+" ",i)
        goto mainloop
      endif
    end select
  endif
  '
  if c
    if c>1 '2,3,4
      wr+=nsls(c)
    endif  
    appendt("jmp fwd _end_"+wr+cr)
  else
    endline(s,i)
    appendt(mid(s,b,i-b)+cr) 'asm exit n
  endif
  goto mainloop
  '
  '
  =======
  case 40 'SUBROUTINE
  =======
  '
  if nisxn
    lmtp=-29
    wr="jmp fwd _end_sub_"+cr+
    "."+tword(s,i)+sp
    inserts(s,wr,i)
  endif
  goto mainloop
  '
  '
  =======
  case 37 'METHODS OF
  =======
  '
  w1=tword(s,i)
  if w1="of"
    w1=tword(s,i) 'SWALLOW `OF`
  endif
  mp=lookupm(w1)
  clsi=mp : 'REMEMBER CLASS
  '
  if mp=0
    ers="class/type not found: "+w1 : ert=11
    goto exitap
  endif
  if drc(mp).a<>-3
    ers="not a class/type: "+w1 : ert=11
    goto exitap
  endif
  '
  if vew>0
    appendt(cr+cr+"'METHODS OF "+w1+cr)
  endif
  '
  'CAPTURE OR START SCOPE
  '
  cbrencah(s,i,md+1000)
  if ert
    goto exitap
  endif
  appendt(sp)           'support for static members in functions
  nest()
  if lclv
    staticvars()
  endif    '
  '
  goto mainloop
  '
  '
  '
  '   #########
  '  ###########
  ' ## CONTROL ##
  '  ###########
  '     ##
  '     ##
  '     ##
  '     ##
  '    ####
  '   ######
  '   ######
  '  ########
  '
  '
  '
  =============
  case 35 to 36 'GOTO / 'GOSUB
  =============
  '
  w1=pword(s,i) 'could e a variale or location
  '
  a=dic(" fwd 1, next 1, prev 2, prior 2, ",w1)
  if a
    if nisxn
      w1=tword(s,i)
      if a=1
        w1="fwd "+w1
      endif
    endif
  endif
  '
  select ascw
  case 48 to 57 : w1="_"+w1 'LINE NUMBERS
  end select
  '
  ========
  gowhere:
  ========
  '
  if nisxn
    wah=wordahead(s,i)
    a=dic(" if 1, when 1, ",wah)
    if a
      i=nwd
      w3=captsr(s,i)
      inserts(s,"if "+w2+w3+cr+wr+" "+w1+cr+"endif"+cr,i)
      goto mainloop
    endif
  endif
  '
  if md=35 'GOTO
    appendt(epfx+wpfx+"jmp "+w1+cr)
  else 'GOSUB
    'maintain stack alignment in 64 bit apps
    if cpuw=8
      appendt("|sp -8"+cr) 'ALIGNMENT
    endif
    appendt(epfx+wpfx+"call "+w1+cr)
    if cpuw=8
      appendt("|sp 8"+cr) 'ALIGNMENT
    endif
  endif
  epfx=""
  goto mainloop 'GOTO 'GOSUB
  '
  '
  =======
  case 13 'IF
  =======
  '
  nd=1 : w1="" : cnd=1
  '
  '
  =======
  case 21 'DO
  =======
  '
  if iss(ascn)=0 'DO SOMETHING ...
    if ascn=123 'DO {...} WHILE (...)
      capturi(s,m,b,i) : w2="do"+cr+mid(s,m,b)+cr
      inserts(s,w2+"loop ",i)
      goto mainloop
    endif
    w2=tword(s,i)
    if w2="until"
      w2="while not"
    endif
    inserts(s,w2+" ",i)
    goto mainloop
  endif
  nd=2 : w1="._do"+nsls(2)+1+cr
  '
  '
  =======
  case 23 'WHILE
  =======
  '
  nobr=123
  w2="" : w4=""
  w3=captsr(s,i)
  nobr=0
  if ascn=123
    i++
    w2="{"
  elseif not iss(ascn)
    w4=cr+captsr(s,i)+cr+"wend"+cr
    if ascn=58 or ascn=59 then i++
  endif
  inserts(s,"do"+w2+cr+"if not "+w3+exitdo+w4,i)
  goto mainloop
  '
  '
  =======
  case 31 'FOR
  =======
  '
  nd=4 : fro=1 : cnd=2 : w1=""
  '
  '
  =======
  case 27  'DEFAULT
  =======
  '
  a=cas and 3 'CASE / SWITCH FLAG
  if a=1
    appendt("jmp fwd _end_sel"+nsls(5)+cr+"._end_cas"+nsls(5)+cr) 'SELECT
  elseif a=3
    appendt("._end_cas"+nsls(5)+cr) 'SWITCH
  endif
  cas=0 : goto mainloop 'SAME AS 'CASE ELSE'
  '
  '
  =======
  case 28  'BREAK
  =======
  '
  if isxn
    if slx
      if cas>1
        appendt("jmp fwd _end_sel"+nsls(5)+cr) 'select/switch break
      endif
      goto mainloop
    endif
    a=0
  else
    a=1
  endif
  if a
    inserts(s,"exit ",i) ' do if when ...
  else
    appendt("jmp fwd _end_do"+nsls(2)+cr) 'do break
  endif
  goto mainloop
  '
  '
  =======
  case 29 'SELECT / 'SWITCH
  =======
  '
  slc(slx)=cas : sls(slx)=wc
  nd=5 : op=1 : b=0
  if ascn=0x63
    if wordahead(s,i)="case"
      i=nwd : skiplspace(s,i)
    endif
  endif
  if ascn=0x62
    if wordahead(s,i)="bit"
      i=nwd : b=8 'bitwise testing
    endif
  endif
  '
  skiplspace(s,i)
  if isxn
    wc="mov rax,0"+cr
    typg=cpuw
  else
    wc=express(s,i,0)
  endif
  '
  if isfloat(typg)
    a=typg
  elseif typg>=0x80
    ert=423 : ers="select on integer or float expression"
  else
    a=4 'default long
    wc+=cvtai(typg,a)
  endif
  slt(slx)=a
  w1=wc+cr
  typr=typg
  cas=b
  if wr="switch"
    cas or=2 'C STYLE SWITCH
  endif
  cbrencah(s,i,nd)
  slx++
  '
  '
  =======
  case 30 'CASE
  =======
  '
  'PREVIOUS CASE
  int aa
  aa=cas and 3 'SELECT / SWITCH FLAG
  if aa=1
    appendt("jmp fwd _end_sel"+
    nsls(5)+cr+"._end_cas"+nsls(5)+cr) 'SELECT
  elseif aa=3
    appendt("._end_cas"+nsls(5)+cr) 'SWITCH
  endif
  '
  '
  int iscf
  iscf=0
  '
  =========
  raltcase:
  =========
  '
  b=cas and 8 'BIT TESTING
  if b
    c=80 'BIT TESTING
  else
    c=3  'COMPARING
  endif
  '
  if wordahead(s,i)="else"
    i=nwd : skiplspace(s,i) : cas=0
    goto mainloop 'CASE ELSE (DEFAULT)
  endif
  '
  '
  'RELOAD REGISTER AFTER CASE (SWITCH ONLY)
  '
  w1=""
  'SWITCH OR USED +PREVIOUS EXPRESSION
  if aa=3 or xep=1
    'after first switch or an expression
    if cas and 4
      w1=wc  'RELOAD QEAX REGISTER
    else
      cas or= 4 'RELOAD IN NEXT CASE
    endif
  endif
  '
  d=slt(slx-1) 'TYPE
  wr=SolveCaseSym(s,i,d,f,g)
  if ert
    goto exitap
  endif
  if xep 'expression
    cas or= 4
    w1+=wr
    f=2
    g=5 'JZ
    if ctal=-16
      g=-1 'NO JMPS
      w4=""
    else
      w1+="._cnd"+cr
      if dts>0
        w1+=rtl(deltmpa) 'must go here before conditional branching
        dts=-1 'DONE TEMP STRING DELETION
      endif
    endif
  else 'constant
    w1+=wpfx+operi(c,d,wr)
  endif
  '
  '
  'ALTERNATIVE TESTING: CASE 10,13,32
  '==================================
  '
  w2=""
  '
  e=cas and 2 'TEST FOR 'SWITCH'
  'if ((e=2)and(f<>2))or(f=4)
  if f=4
    b=b xor 8 'OPPOSITE LOGIC
    w3=" fwd _is_cas"+nsls(5)
    iscf=1
  else
    w3=" fwd _end_cas"+nsls(5)
  endif
  '
  if f=4
    if b
      if isfloat(d)
        select g
        case 0 : w4="jz"
        case 1 : w4="jb"
        case 2 : w4="jz"
        case 3 : w4="jbe"
        case 4 : w4="ja"
        case 5 : w4="jnz"
        case 6 : w4="jae"
        end select
      else
        select g
        case 0 : w4="jz"
        case 1 : w4="jl"
        case 2 : w4="jz"
        case 3 : w4="jle"
        case 4 : w4="jg"
        case 5 : w4="jnz"
        case 6 : w4="jge"
        end select
      endif
      w3=w4+w3 'JZ CASE MATCH
    else 'BIT LOGIC ONLY
      w3="jnz"+w3  'JNZ CASE MATCH
    endif
    appendt(w1+w3+cr)
    goto raltcase
  endif
  '
  if f=3 'TO
    '
    'RANGE TESTING: CASE 1 TO 32
    '===========================
    ' 
    w3=" fwd _end_cas"+nsls(5)
    i=nwd
    c=0
    skiplspace(s,i)
    if ascn=60 '<
      i++
      skiplspace(s,i)
      c=1 'BOUNDARY FLAG
    endif
    wr=SolveCaseSym(s,i,d,f,g) 'o2sema.bas
    e=cas and 2
    if f=4 'or((e=2)and(f=2))
      w2="jmp fwd _is_cas"+nsls(5)+cr
      iscf=1
    else
      w2=""
    endif
    '
    if isfloat(d)
      w4="jb" 'BELOW
      w5="ja" 'ABOVE
    else
      w4="jl" 'LESS
      w5="jg" 'GREATER
    endif
    if c
      w5+="e" 'JUMP ABOVE OR EQUAL: CASE 1.0 TO < 2.0
    endif
    w1+=w4+w3+cr+wpfx+_
    operi(3,d,wr)+_
    w5+w3+cr+w2 'CASE X TO Y
    if f=4 'COMMA
      w1+="._end_cas"+nsls(5)+cr
      appendt(w1)
      goto raltcase 'MORE CASE EXPRESSIONS
    endif
    'end f=3
  elseif b
    '
    'BIT TESTING
    '===========
    '
    w1+="jz"+w3+cr  'JZ BIT TESTING
    '
  else
    '
    'COMPARING
    '=========
    '
    if isfloat(d)
      select g
      case 0 : w4="jnz"
      case 1 : w4="jae"
      case 2 : w4="jnz"
      case 3 : w4="ja"
      case 4 : w4="jbe"
      case 5 : w4="jz"
      case 6 : w4="jb"
      end select
    else 'not float
      select g
      case 0 : w4="jnz"
      case 1 : w4="jge"
      case 2 : w4="jnz"
      case 3 : w4="jg"
      case 4 : w4="jle"
      case 5 : w4="jz"
      case 6 : w4="jl"
      end select
    endif
    w1+=w4+w3+cr
    '
  endif
  '
  ' NEXT CASE FOLLOWS IMMEDIATELY?
  '
  if iscf
    w1+="._is_cas"+nsls(5)+cr
  endif
  skiplspace(s,i)
  cas or=1
  goto xcnd
  '
  '
  =======
  case 26 'CONTINUE / 'REDO / 'REPEAT
  =======
  '
  if nisxn
    w1=tword(s,i)+"_"+wr
    a=lookupm(w1) 'word_repeat etc
    if a
      inserts(s,w1+" ",i)
      goto mainloop
    endif
    i=swd
    skiplspace(s,i)
    w1=""
  endif
  if wr="repeat"
    if isa(ascn)=0 'not alpha
      if isn(ascn)
        wr+=" "+tword(s,i) 'level number
      endif
      appendt wr+cr
      goto mainloop 'asm
    endif
  endif
  b=iss(ascn) 'end of statement
  if b
    w1="do"+cr 'default continue do
    w3=""
  else
    w1=tword(s,i)
    w3=captsr(s,i)
  endif
  a=dic(" while 1, when 2, until 3, for 4, do 5, if 6, ",w1)
  if asc(w3)>47 'EXPRESSION FOLLOWS
    b=0
    w2="if "
    select a
    case 1 : b=1 'while
    case 2 : b=1 'when
    case 3 : b=1 : w2="if not " 'until
    case 6 : b=1 'if
    end select
    if b
      inserts(s,w2+w3+contdo,i)
      goto mainloop
    endif
  endif
  w2="jmp long _do"+nsls(2)
  select a
  case 1 : 'while
  case 4 : w2="jmp fwd _step"+nsls(4) 'for
  case 5 : 'do
  case else
    w2="repeat "+w3 'asm
  end select
  appendt(w2+cr)
  goto mainloop
  '
  '
  end select 'md
  '=============
  '
  '
  '===========
  allcontrols:
  '===========
  '
  if nd=0
    goto endcons
  endif
  '
  if w1
    appendt(epfx+w1) : epfx=""
  endif
  '
  'nd>0
  if nsl>=99
    ert=300 : ers="too many block nestings "+wr : goto exitap
  endif
  ctb(nsl)=nd
  a=i
  endline(s,a)
  cln(nsl)=lnmks+": "+mid(s,swd,a-swd)
  nsls(nd)++
  nsl++
  skiplspace(s,i)
  '
  if cnd=0
    goto mainloop
  endif
  '
  if fro
    gosub iterations 'FOR
    goto mainloop
  endif
  '
  ========
  elseifs:
  ========
  '
  if ctb(nsl-1)=1
    w3=" fwd _end_cnd"+nsls(1)+cr
  else
    w3=" fwd _end_do"+nsls(2)+cr
  endif
  '
  w4=""
  '
  '========
  jumpcond: 'w3 jump to 'set cnd sense 'ALSO W4 SET
  '========
  '
  ctal=0
  '
  'LOGICAL NOT
  '
  do
    wr=pword(s,i)
    if ascw=0x6e
      if wr="not"
        cnd=-cnd 'NOT CONDITION
        continue do
      endif
    endif
    exit do
  loop
  '
  if cnd<0
    w2="jnz "
  else
    w2="jz "
  endif
  '
  if isendofexpr(s,i)=0
    goto condexpression 'MORE TERMS
  endif
  if (varf>=8)or(typ>=typh)or(rps=1)
    goto condexpression 'MORE TERMS
  endif
  '
  'CHECK FOR 'THEN' AND IMPLIED 'GOTO'
  if ascn=0x74
    if wordahead(s,i)="then"
      i=nwd 'skip
      int ta=asc(s,i)
      if isn(ta) 'LITERAL LINE NUMBER
        inserts(s,"goto ",i)
      endif
    endif
  endif 'single word conditional
  '
  'REMOVE TEMP VAR
  if rps and 8
    a=instrevn(-1,hiex,"#snip")
    if a
      hiex=left(hiex,a-1)
      w1="or eax,eax"+cr : goto ccnd
    endif
  endif
  '
  w1=""
  '
  'check for numeric literal 'IF 1 IF NOT 0
  a=val(wr)
  if a
    if cnd<0
      cnd=0
    else
      goto xcnd
    endif
  elseif asc(wr)<=48
    if cnd<0
      goto xcnd
    else
      cnd=0
    endif
  endif
  '
  if cnd
    w1+=wpfx+operi(0x20,typ,wr)
  else
    w2="jmp "
  endif
  '
  goto ccnd
  '
  ===============
  condexpression:
  ===============
  '
  op=0 : parx=1024 : skiplspace(s,i)
  inserts(s,owa+" ",i) 'REINSERT ORIGINAL WORD
  epfx=""
  int csty=0
  if asc(owa)=lbr 'C style if (expr) ...
    nobr=123
    w1=captsr(s,i)
    nobr=0
    w1=express(w1,1,0)
    skiplspace(s,i)
    if not iss(ascn)
      csty=1
    endif
  else
    w1=express(s,i,0)
  endif
  '
  if ascn=0x74 
    if wordahead(s,i)="then"
      csty=0
      i=nwd
      int ta=asc(s,i)
      if isn(ta)
        inserts(s,"goto ",i)
      endif
    endif
  endif
  '
  if rps=1
    'ISTRUE
    w3="" : w5=""
    '
    if nd>0
      nsl--
      a=ctb(nsl)
      nsls(a)--
      'j=instrevn(j-1,t,"(") 'REMOVE NESTING FROM BUFFER
    endif
    select nd
    case -1 : 'ELSEIF
      if cnd=1
        w5="jz fwd _end_cnd"+nsls(1)
      else 'ELSEIF NOT
        w5="jnz fwd _end_cnd"+nsls(1)
      endif
      w3+="or eax,eax"+cr+w5
    case  1 : 'IF
      if cnd=1
        w3+="if eax" 'IF
      else
        w3+="if not eax"
      endif
      w3+=" then " 'support single line 'if'
    end select
    a=i : endline(s,i) : w3+=mid(s,a,i-a)+cr
    w1=epfx+w1 : epfx=""
    hiex+=storecode(w1)+w3
    cnd=0
    goto cleardown
  endif 'rps
  '
  'ACTION FOLLOWING CONDITIONAL EXPRESSION
  '
  if ctal=-16
    w2="" : goto ccnd
  endif
  '
  'OTHERWISE NO OPTIMISATION
  if isfloat(typg)
    w1+="fldz : fxch st1 : fcomip st1 : fstp st0"+cr+
    "setnz al : and eax,1 : neg eax"+cr
  endif
  '
  w1+="._cnd"+cr
  '
  if dts>0
    w1+=rtl(deltmpa) 'must go here before conditional branching
    dts=-1 'DONE TEMP STRING DELETION
  endif
  '
  if ((opg<>33)and(opg<>34))or(dts=-1) 'LOGIC OUTCOME FOR EAX
    w1+="or eax,eax"+cr
  endif
  '
  ccnd:
  '====
  '
  w1+=w2+w3+w4 'SKIP IF TRUE / IF FALSE
  '
  xcnd:
  '====
  '
  cnd=0
  ctal=0
  '
  skiplspace(s,i)
  a=0
  select ascn
  case sr1  : a=1 : i++
  case sr2  : a=1 : i++
  case 0x65 :
    if wordahead(s,i)="end"
      a=2
    endif
  end select
  if a
    inserts(s,cr,i)
    ascn=13
    d=1
  else
    d=ise(ascn)
  endif
  '
  if md=18
    nsl--
    a=ctb(nsl)
    nsls(a)--
    goto cleardown 'DO {..} WHILE ..
  endif
  '
  'IMPLICIT ENDIF AT END OF LINE
  '=============================
  '
  if nsl
    c=ctb(nsl-1)
    b=cbrencah(s,i,c)
    if (b=0)and(c=1)and(d=0)
      a=i
      if csty
        w2=captsr(s,i) 'single statement
      else
        endline(s,i)
        w2=mid(s,a,i-a)
      endif
      w2+=cr+"endif"
      inserts(s,w2,i)
    endif
  endif
  if d
    endline(s,i)
  endif
  csty=0
  '
  goto cleardown
  '
  'end of all controls
  '
  endcons: 'ENDDO ENDWHILE 'WEND
  '=============================
  '
  '
  skiplspace(s,i)
  nd=0 : cnd=0
  '
  select md
  '
  =======
  case 18 'ENDDO
  =======
  '
  'do {...} while ...
  b=i
  skipspace(s,i) 'must be continuity (no basic comments etc)
  if (ascw=125)and(wordahead(s,i)="while")
    i=nwd : skiplspace(s,i)
    w2=nsls(2)
    w3=" long _do"+w2
    w4="._end_do"+w2+cr
    cnd=-1
    goto jumpcond
  else
    i=b : skiplspace(s,i)
  endif
  nd=2 : appendt(exdo)
  '
  '
  =======
  case 19 'ENDWHILE
  =======
  '
  nd=2 : appendt(exdo)
  '
  '
  =======
  case 12 'LOOP
  =======
  '
  if isw(ascn)
    wah=wordahead(s,i)
    a=dic(" if 1, while 1, when 1, until 2, ",wah)
    if a
      i=nwd
      w3=captsr(s,i)
      if a=1
        w2="if not "
      else
        w2="if "
      endif
      inserts(s,w2+w3+exitdo+"loop"+cr,i)
    else
      m=i : endline(s,i)
      appendt "loop "+mid(s,m,i-m)+cr 'POSSIBLE ASM BRANCH
    endif
    goto mainloop
  endif
  nd=2 : appendt(exdo)
  '
  =======
  case 24 'WEND
  =======
  '
  nd=2 : appendt(exdo)
  '
  '
  =======
  case 34 'NEXT
  =======
  '
  nx--
  if nx<0
    ert=10 : ers="Too many nexts" : goto exitap
  endif
  if ascw<>125
    if iss(ascn)=0
      w2=tword(s,i) ' swallow iterator name: next i
    endif
  endif
  nd=4
  inserts(s,nxs(nx),i)
  '
  '
  =======
  case 20 'ENDSELECT / END SELECT / END SWITCH
  =======
  '
  slx--
  if slx<0
    ert=11 : ers="Too many end selects"
    goto exitap
  endif
  nd=5 : appendt("._end_cas"+nsls(5)+cr+"._end_sel"+nsls(5)+cr)
  wc=sls(slx) : cas=slc(slx) 'up select level
  '
  '
  =======
  case 15 'ELSE
  =======
  '
  if ise(ascn)=0
    w1=wordahead(s,i)
    'ELSE IF SPACED
    if w1="if"
      md=16 : i=nwd : skiplspace(s,i)
      if hei(nsl-1)=0
        appendt(exei) 'OTHERWISE SUPPRESS
      endif
      hei(nsl-1)=0
      cnd=1 : nd=-1 : w1=""
      goto elseifs 'treat as 'if'
    endif
  endif
  ' 
  b=i : nextinstruct(s,b)
  '
  if ascn=123
    cbrk(cbri)=1 : cbri++ : i=b+1
  else
    skiplspace(s,i)
  endif
  '
  appendt("jmp fwd _end_if"+nsls(1)+cr+"._end_cnd"+nsls(1)+cr)
  goto mainloop
  '
  '
  =======
  case 16 'ELSEIF
  =======
  '
  cnd=1 : nd=-1 : w1=""
  if hei(nsl-1)=0
    appendt(exei) 'OTHERWISE SUPPRESS
  endif
  hei(nsl-1)=0
  goto elseifs 'treat as 'if'
  '
  =======
  case 17 'endif
  =======
  '
  nd=1 : appendt("._end_cnd"+nsls(1)+cr+"._end_if"+nsls(1)+cr)
  'if sln
  '  sln-- 'SINGLE LINERS DECR NESTING
  'endif
  '
  =========
  case else
  =========
  '
  goto nendcons
  '
  end select
  '
  '===================
  'ALL CONTROL ENDINGS
  '===================
  '
  'ERROR CHECKS
  '
  if nsl<1
    ert=300 : ers="nesting error " : w1=" (no beginning)" : m=nd
  else
    nsl--
    m=ctb(nsl)
    if m=nd
      a=ctb(nsl)
      nsls(a)--
      goto mainloop 'OKAY
    endif
    ert=301 : w1=" expected"+cr+cln(nsl)
  endif
  '
  select m
  case 1 : ers+="`endif`"
  case 2 : ers+="`end do` "
  case 3 : ers+="`end while` or `wend` "
  case 4 : ers+="`next`"
  case 5 : ers+="`end select`"
  end select
  '
  ers+=w1+cr : goto exitap
  '
  =========
  nendcons:
  =========
  '
  '
  'O2H DIRECTIVES
  '
  select md
  '
  case 44 'INDEXBASE
    'supports negative and positive
    ixb=wdval(s,i,i)
    goto mainloop
    '
  case 51  '#MAJORMINOR
    arcm=0
    goto mainloop
    '
  case 52  '#MINORMAJOR
    arcm=1
    goto mainloop
    '
  case 46 'EXPORT
    atx or=1 : etx=1 : etxx=1 'super extern
    goto mainloop
    '
  case 47 'LIB 'LIBRARY
  '
  if isq(ascn)
    if asc(s,i+1)=ascn 'EMPTY QUOTE
      libr=""
      if atx or 1
        atx=etxx 'cancel/defer extern block
      endif
      i+=2 : goto mainloop
    endif
  endif
  inserts(s,"extern lib ",i) 'process as extern
  goto mainloop
  '
  case 48  'EXTERN
  '
  if nisxn
    w1=wordahead(s,i)
    a=identype(w1)
    if a
      goto mainloop 'extern int xyz(...
    endif
  endif
  '
  ccx=0 : crg=0 : crgd=0 : atx=1 : etx=etxx : libr=""
  'words in any order
  do
    w1=wordahead(s,i)
    if w1="export"
      i=nwd : etx=1
      continue do     'SET PROCEDURES FOR EXPORT
    endif
    a=dic(" virtual 2, preset 4, pure 8, com 8, ",w1)
    if a
      atx or=a
      i=nwd
      continue do
    endif
    if idword(" lib library ",w1)
      i=nwd
      atx or=2 'EXTERN VIRTUAL
      libr=rootpath(lpath+lexiword(s,i)) 'SET DEFAULT LIBRARY
      continue do
    endif
    a=readcc(w1,ccx)
    if a
      crg=crgd
      i=nwd
      continue do
    endif
    exit do
  loop
  goto mainloop
  '
  case 53 : nprec=1 : goto mainloop       '#NOPREC (transient)
  '
  case 55 : bref=0 : goto mainloop       '#BYVAL by default
  '
  case 56 : bref=1 : goto mainloop       '#BYREF by default
  '
  'case 63 : opers=lcase(mword(s,i)) : goto mainloop 'OPERATIONS
  '
  case 54 '#NOINIT FLAG FOR LOCAL VARS
  '
  yesno(s,i,noin) : goto mainloop 

  case 58 '#ASSIGN FLAG FOR C TYPE ASSIGNMENT OPERATOR (MUST US == FOR EQUALITY TEST)
  '
  yesno(s,i,casg) : goto mainloop 
  '
  case 60 '#ENDING
  '
  appe(epgs(brc),epgi(brc),captureblock(s,i,"")+cr)
  goto mainloop
  '
  end select
  '
  '
  end_o2h:
  '=======
  '
  '
  if mc<>-13
    newline=0 : goto addsrc
  endif
  '
  '
  '
  '#######################
  '
  '#######################
  '
  '     #####    ##### 
  '    #     #  #     #
  '    #     #        #
  '    #     #   ##### 
  '    #     #  #
  '    #     #  # 
  '     #####   #####O2
  '
  '######################
  '
  '#######################
  '
  '
  maino2:
  '======
  '
  '
  a=ascw
  '
  if mc=-13
    md=drc(mp).f
  else
    md=0
  endif
  '
  select md 'METATYPE 13
  '
  case 1 : incli=1 : continue do 'INCL
  '
  '
  case 7 'WITH
  '
  wths=captsr(s,i)
  wthf=len(wths)
  goto mainloop
  '
  case 8 'EXPAND
  '
  capturi(s,m,b,i)
  wr=mid(s,m,b)
  expandmac(wr)
  inserts(s,wr,i)
  goto mainloop
  '
  case 6,10 'ASM / O2 inline code
  '
  if md=6
    wr=""
  endif
  '
  ws=wr+sp+captureblock(s,i,wr)+ep+asg
  asg=""
  appendt(ws)
  goto mainloop
  '
  case 12 'BIND
  '
  wr=tword(s,i)
  if asc(s,i)=44
    i++ ' swallow comma
    skiplspace(s,i)
  endif
  wd=captureblock(s,i,"bind")
  nocomments(wd)
  bindrec(wd,wr)
  inserts(s,wd,i)
  goto mainloop
  '
  '
  case 23 'NAMESPACE
  '
  SetNameSpace(s,i)
  goto mainloop
  '
  case 21  'PACKED
  '
  pakd=1 
  newline=1
  continue do
  '
  '
  'BLOCK DECLARATIONS
  '==================
  '
  case 9 : 'ENUM (bit) aa (n) bb cc
    enums(s,i,0)
    if ert
      goto exitap
    endif
    goto mainloop
    '
  case 17 'VAR
    b=i
    endline(s,i)
    wr=mid(s,b,i-b)
    nocomments(wr)
    varsal(wr)
    if ert
      goto exitap
    endif
    goto mainloop
    '
  case 11 'STRUCT   
    w1=wordahead(s,i)
    if asc(s,nwd)=42
      i=nwd+1
      inserts(s,"sys ",i)
      goto mainloop
    endif
    typo=2  : unip=8

  case 13   : typo=2  : unip=16 'CLASS
  case 16   : typo=2  : unip=8  'TYPE
  case 38   : typo=2  : unip=9  'UNION
  case 37   : typo=2            'TYPEDEF
  case 15   : typo=17 : unip=0  'DEFF
  case 14   : typo=18 : unip=0  'DEF '#DEF
  case 22   : typo=19 : unip=0  'TERMINATION MACRO
  '
  case else 'NOT A TYPE / STRUCTURE
    goto ntypo
  end select
  '
  declarations2:
  '=============  
  '
  '  drc.
  '  m0 name
  '  m1 prepared macro / resolved structure for types
  '  m2 offset and array spec for vars / array spec for typedefs
  '  m3 vf table building code
  '  a  structure flag -3  ( -18 def -33 enum -3 type)
  '  b  length
  '  c  var offset / vtpointer spec for types
  '  d  number of params in macro (metatype -18)
  '  e  size of associated class vf table / var to be used in signature (1)
  '  f  type code for vars
  '
  m=swd
  '
  w1=wr ' TYPEDEF etc
  '
  wr=tword(s,i) 'COULD BE UNION STRUCT ENUM etc
  '
  if md=16 'TYPE
    if ascn=0x61 'a
      a=i
      if wordahead(s,i)="as"
        mid(s,i)="  " 'blank 'as'
        md=37 'TYPEDEF
        goto idtypedefs
      end if
    endif
  endif
  '
  if md<>37 'TYPEDEF
    goto isdefi 'exclude all except typedef
  endif
  '
  unip=dic(" struct 8, union 9, ",wr)
  if unip 'STRUCT / UNION
    tdst=1 : nextinstruct(s,i)
    indt=0
    if ascn=123
      wr="anon" 'ANON STRUCTURE
    else
      wr=tword(s,i) 'NAMED STRUCTURE
    endif
    nextinstruct(s,i)
    if ascn=123
      goto isdefi 'TYPEDEF STRUCT ST { ..}
    else 'ascn<>123
      'TYPEDEF STRUCT ST
      'no structure given
      indt=0
      b=0x10
      wn="void"
      'i=swd
      'skiplspace(s,i)
      goto rtypedef
    endif
  elseif wr="enum"
    'TYPEDEF ENUM..
    enums(s,i,1)
    if ert
      goto exitap
    endif
    indt=0
    if nisxn
      inserts(s,"dim int ",i)
    endif
    goto typesdone
  endif 'struct or union
  '
  ===========
  idtypedefs:
  ===========
  '
  i=swd
  tyd=1
  wn=mword(s,i)  'SUPPORTING MACROS
  tyd=0
  b=identype(wn) 'base type
  'indt now set
  if b
    goto rtypedef
  else 'b=0
    ers="unknown type"
    ert=69
    goto exitap
  endif
  '
  '
  '======
  isdefi:  'COMING FROM:  typedef struct or equates % $ 
  '======
  '
  w5=wr 'NAME
  '
  if ert
    goto exitap
  endif
  '
  if md=11
    if ascn=59
      wr=""
      goto nblock 'EMPTY STRUCT C STYLE
    endif
  endif
  '
  'CAPTURE BODY
  '
  nocapt=1
  wr=captureblock(s,i,w1)
  nocapt=0
  '
  'CLASS/TYPE DEFINITION ON SINGLE LINE
  'if instr(wr,cr)=0
  '  nocomments(wr)
  '  replacewd(wr," : ",cr,0)
  'endif
  '
  w3=""
  '
  if md=16
    md=13 'TYPE BECOMES CLASS
  endif
  '
  if md<>13
    goto nblock
  endif
  '
  =======
  mclass:
  =======
  '
  'SEPARATE TYPE AND METHODS WITHIN CLASS ENVELOPE
  mo=2 'mode 2 for class headers
  ' wr source block
  gosub MakeHeaders '(wr,w4,w3,2)
  ' wr header members
  ' w4 header methods
  ' w3 procedural code and internal
  '
  'COMPOSE VIRTUAL SECTION /\ BODY SECTION
  '
  if hasfun
    wr=w4+sectmk+wr 'prepend methods header
  endif
  '
  'class name in w5
  '
  '======
  nblock:
  '======
  '
  striplineno(wr)
  nocomments(wr)
  '
  if typo=18 'DEF '#DEF
    nofinalcr(wr)
  endif
  '
  '
  if defbuf
    if uniq
      defbuf="#unique off"+cr+hiex+"#unique on"+cr
    endif
    w3="methods of "+w5+cr+w3+"end methods '"+w5+cr+cr
    defbuf+="class "+w5+cr+wr+cr+"end class"+cr+w3+undefbuf
    inserts(s,defbuf,i)
    defbuf="" : undefbuf=""
    goto mainloop 'REPROCESS SRC
  endif
  '
  '
  '
  'dct=0 'each new type or class or union
  newrecord(w5)
  mrcsi(wr,me,1) 'MACRO BODY
  '
  select typo
  case 17,18,19,21
    drc(me).a=-typo 'METATYPE
    if typo=17
      drc(me).f=0x6a 'TYPE EXTENDED FLOATING POINT
    endif
    addme
    if ert
      goto exitap
    endif
    goto mainloop
  end select
    '
  incli=0
  '
  if typo<>2
    goto ntypo
  endif
  '
  gosub MakeTypes
  if ert then goto exitap
  '
  'CLASSES ONLY
  '============
  '
  'COMPOSE METHODS BLOCK AND INSERT BACK INTO SOURCE STREAM
  'the methods block is needed even if it is empty
  'itr functions have access to static members only /callback functions
  '
  if md=13
    '
    if (atx and 2) = 0 'not virtual
      a=len(w3)
      if (a>0) or ((tuc>0)and(ttc=0)) 
        inserts(s,cr+"methods "+w5+cr+cr+w3+"end methods"+cr+cr,i)
      endif
    endif
    goto typesdone
  endif
  '
  if ert
    goto exitap
  endif
  '
  'END OF STRUCTS
  '==============
  '
  skiplspace(s,i)
  '
  if isxn
    goto typesdone
  endif
  b=qme
  lent=drc(b).b
  wn=mrcso(b,0)
  b+=typh
  indt=0
  if tdst=0
    inserts(s,"dim "+wn+" ",i) 'INSTANTIATE FROM STRUCT
    goto typesdone
  endif
  '
  'derived types drop thru
  '
  'typedef struct xtag {...} x,*px
  '
  =========
  rtypedef: 
  =========
  '
  'LOOP FOR EACH NEW TYPE
  '
  'typedef float x,y,z,*b,c,d
  'typedef int *a,*b,c,d
  'typedef int (*getxyz)(int n)
  'typedef xyz* (?? ?? *getxyz)(int n)
  '
  'wn    'base name
  'mtp   'metatype
  'b     'base type
  'indt  'base indirection
  '
  c=indt
  int mtp
  mtp=0
  c+=isptr(s,i) 'POINTERS
  if ascn=lbr
    mtp=-5 'proc
    i++
    do
      skiplspace(s,i)    
      if ascn=rbr
        i++
        exit do
      endif
      if ascn=lbr
        capture(s,m,i,0) 'inner blocks
        continue do
      endif
      wr=tword(s,i) 'capture name
    loop
    nextinstruct(s,i)
  else
    wr=tword(s,i)
  endif
  '
  if wr=wn
    goto xtypedef
  endif
  '
  if ascn=0x70 'p ptr pointer
    c+=isptr(s,i)
  endif
  dct=0 'each typedef
  newrecord(wr)
  w2=""
  if ascn=lbr
    capture(s,m,i,0) 'params
    'w2+=mid(s,m,i-m)
    skiplspace(s,i)
  endif
  '
  if ascn=95
    w1=wordahead(s,i)
    '
    'ATTRIBUTE STUB
    'itr macros
    '
    if w1="__attribute__"
      i=nwd
      capture(s,m,i,a)
      skiplspace(s,i)
    endif
  endif
  '
  drc(me).a=-8    'METATYPE TYPEDEF
  drc(me).b=lent  'SIZE
  drc(me).d=c     'INDIRECTION
  drc(me).e=mtp   'METATYPE 0 or -5
  drc(me).f=b     'UDT OR PRIMITIVE / POINTER
  mrcsi(wn,me,1)  'BASE TYPE
  mrcsi(w2,me,2)  'FUNCTION PROTOTYPE / ARRAY
  addme
  if ert
    goto exitap
  endif
  '
  xtypedef:
  =========

  if ascn=44
    i++
    nextinstruct(s,i)
    goto rtypedef 'LOOP FOR NEXT DEF
  endif
  '
  'itr semicolons: treat as linebreaks
  'itr #define on next line requiring contin
  '
  '
  ==========
  typesdone:
  ==========
  '
  'RESUME MAIN PREP LOOP
  '
  pakd=0 : typo=0 : tdst=0 : unip=0 : w1=""
  '
  '
  'INCORPORATE ANY EMBEDDED #DEFINES
  '
  if definbuf
    inserts(s,definbuf,i) : definbuf=""
  endif
  goto cleardown
  '
  '
  ======
  ntypo: 'end of types
  ======
  '
  'resume cases
  '
  select md 'FOR METATYPE 13
  '
  '
  case 18 'INCLUDE '#INCLUDE
  '
  includefile(s,i)
  if ert
    goto exitap
  endif
  goto mainloop
  '
  case 2 '#SEMICOLON
  '
  w1=""
  if ise(ascn)=0
    w1=tword(s,i)
  endif
  if w1="comment"
    sr2=58 : ct2=59
  else
    sr2=59 : ct2=39
  endif
  goto mainloop
  '
  case 19 :                              : goto mainloop '#ASM 'ASM
  case 20 :                              : goto mainloop '#O2H 'O2H '#BASIC 'BASIC
  case 30 : paths(s,i,ipath)             : goto mainloop 'INCLUDEPATH
  case 31 : paths(s,i,lpath)             : goto mainloop 'LIBRARYPATH
  case 48 : endline(s,i) : appendt(cr)   : goto mainloop '#PRAGMA
  case 44 : yesno(s,i,relaxed)           : goto mainloop '#AUTODIM
  case 49 : yesno(s,i,uniq)              : goto mainloop '#UNIQUE
  case 50 : cnsl=1                       : goto mainloop '#CONSOLE
  '
  case 26  'REM 'REM{..}
  '
  captureb(s,i,0,0,"")
  appendt(cr)
  goto mainloop
  '
  case 46   '#ALERT
  '
  dv=metaval(s,i,ers,100)
  ert=md-45 : ow=""
  ers="ERROR:"+htb+ers+cr
  gosub errordetails
  print ers
  ert=0 : ers=""
  goto mainloop
  '
  case 47   '#ERROR
  '
  dv=metaval(s,i,ers,100)
  ert=md-45 : ow=""
  goto exitap
  '
  case 43 '#LOOKAHEAD
  '
  wr=mid(s,i)
  mo=1 'collect declarations
  gosub MakeHeaders '(wr,w4,w3,1)
  'w4 declarations
  inserts(s,w4,i)
  wr="" : w3="" : w4=""
  if ert
    goto exitap
  endif
  goto mainloop
  '
  case 51 '#SHOW
  '
  shd=1 '#show flag
  if ascn=34
    shf=lexiword(s,i)
  endif
  if tranpass=2
    bj=j 'mark Output code position
    shs=captsr(s,i)
    w1=shs+cr+chr(she) 'MARK END
    inserts(s,w1,i)
  else
    shf=""
  endif
  goto mainloop
  '
  '
  case 53 'ADDR 'pseudo-instruction
  '
  w2=""
  wr=pword(s,i)
  if mc<>-10
    w1=wr
    wr=qeax
  else
    if ascn=44
      i++
    endif
    w1=pword(s,i)
  endif
  w2=""
  w3=""
  if ascw=91
    w3=wpfx
    if w3
      replace(w3,qedi,wr)
    endif
    if isdstr(typ)
      w2="mov "+wr+cm+w1+cr
      if typ>=0xe0
        w2+="mov "+wr+cm+"["+wr+"]"+cr
      endif
    else
      replace(w1,qedi,wr)
      w2="lea "+wr+cm+w1+cr
    endif
  elseif isq(ascw)
    if wr<>qeax
      ers="string literals use register "+qeax+" not "+wr: ert=402 : goto exitap
    endif
    w2=stodata(w1)
   elseif (mc=-5)or(mc=-4) 'obtain possible vector
     w4=pword("@"+w1,1)
     if ascw=91
       w2="lea "+wr+cm+w4+cr
     else
       w2=linkadd(w1,wr) 'label
     endif
  else 'possible labels
    if isn(ascw)
      w1="_"+w1
    endif
    w2=linkadd(w1,wr)
  endif
  appendt(w3+w2)
  goto mainloop
  '
  case 54 '#COMPACT
  '
  yesno(s,i,compact)
  if tranpass<>2
    compact=0
  endif
  goto mainloop
  '
  case 55 '#CPOINTER
  '
  yesno(s,i,cpoint) : goto mainloop
  '
  case 40 '#FPNPRECISION
  '
  if nisxn
    wr=lcase(tword(s,i))
    fpnp=dic(" single 0, double 1, ",wr)
  endif
  goto mainloop
  '
  case 41 '#CASE
  '
  if nisxn
    wr=lcase(tword(s,i))
    casf=dic(" insensitive 1, sensitive 2, capital 3, capitalsensitive 3, ",wr)
  endif
  goto mainloop
  '
  case 34 '#FILE
  '
  if nisxn
    w1=lexiword(s,i)
    w2=lcase(right(w1,3))
    a=dic(" dll 1, exe 2, ",w2)
    if a=0
      ert=5 : ers="#file requires name.exe or name.dll " : goto exitap
    endif
    '
    pexn=w1
    pef=a
    independent=1 
    'no dependent mode apart from jit
    cpuw=4
    '
    do
      if isxn
        exit do
      endif
      w1=tword(s,i)
      a=val(w1)
      if a
        pem=a
        if a=64
          cpuw=8
        endif
      endif
    loop
    regnames() 'SET 32/64 BIT REG NAMES
  endif
  goto mainloop
  '
  case 35 'EMBEDFILE (REVOKED)
  '
  case 100 to 199 'META COMMANDS: #IFDEF ETC
  '
  metaco(s,i)
  if ert
    goto exitap
  endif
  goto mainloop
  '
  '
  case 200 to 299 'COMPILE TIME DIAGNOSTICS
  w1="" : w2="" : w3=""
  if isq(ascn)
    w3=lexiword(s,i)
  endif
  if ise(ascn)
    goto mainloop
  endif
  w1=tword(s,i) 'no macro expansion
  if tranpass<=2
    select md
    case 201 '#BLOCKDEPTH
      w2=" "+str(brc)
    case 202 '#RECORDOF
      a=lookupm(w1)
      if a
        w2=writestates(a,a)
        replace(w2,dfd,cr+"--------")
      else
        w2=w1+" Not found"
      endif
    case 203 '#LIST
      a=0 : b=0 : c=0 : d=0 : e=len(w1)
      if dtf
        w4=left(w1,dtf-1)
        c=lookupm(w4)
        if c
          d=drc(c).a
          if d>=typh
            d-=typh
          endif
          if d<=0
            d=c
          endif
          w2=mrcso(d,1) 'BODY OF TYPE / CLASS / MACRO
          a=me 'NO SCAN
          b=len(w2)
        endif
      endif
      do 'SCAN ALL SYMBOLS
        if c>=64
          exit do
        endif
        if a>=me
          exit do
        endif
        w4=mrcso(a,0)
        'if w1=left(w4,e)
        if instr(w4,w1)
          'itr original symbol case
          'itr secondary keywords / inherits as byref etc.
          g=drc(a).g
          w5=ssn(g)
          if not w5
            if a<mesb
              w5="(core)"
            else
              w5="(main source)"
            endif
          endif
          d=drc(a).l 'NAMESPACE
          if d
            w4=mrcso(d,0)+w4 'PREFIX
          endif
          w4+=" in "+w5
          appe(w2,b,w4+cr) : c++ 'BUFFER
        endif
        a++
      loop
      w2=left(w2,b)
    end select
    if w3
      putfile w3,w2
    else
      print w2 'LIST TO SCREEN
    endif
  endif
  goto mainloop
    '
  end select 'mc=-13
  '
  '
  '======
  addsrc:
  '======
  '
  '
  'ADD ANY UNPROCESSED CODE
  'PASS THRU UNPROCESSED WORDS
  'INCLUDE SINGLE CR/LF (NOT MULTIPLE CR)
  '
  wsg=wr
  appendt(wr)
  do
    skiplspace(s,i)
    if ascn<=13
      appendt(cr)
      exit do
    endif
    b=0
    if ascn=58
      b=1
      if asc(s,i+1)=91 ':[
        b=2
      endif
    elseif ise(ascn)
      endline(s,i)   
      b=1
    endif
    if b=1
      i++
      appendt(cr) 'treat as statement
      goto mainloop
    elseif b=2
      i++
      appendt("&"+mword(s,i)) 'asm prefixes
    else 'word other than colon
      appendt(" "+mword(s,i)) 'other asm operands
    endif
  loop
  a=ascn
  '
  newline=0
  '
  '
  '
  'END-OF-LINE CHECKS
  '==================
  '
  if a<=13
    '
    if a=0
      '
      'END OF CURRENT SOURCE STREAM
      'CHECK FOR OTHER STREAMS
      'INSERT NEXT INCLUDED CONTENT, IF ANY
      '
      if fq
        fq-- 'RESUME PREVIOUS SOURCE CODE
        i=1 : s=sst(fq)
        skiplspace(s,i)
        if fq
          wd=ssf(fq-1)
        else
          wd="main source"
        endif
        cfile=qu+wd+qu
        appendt("'_"+cfile+cr) 'EMBED CURRENT FILENAME FOR ASSEMBLERS
        goto mainloop
      endif
      '
      'DEFAULT TERMINATION CODING
      '
      if tranpass>1
        '
        if nsi
          appendt("o2 k0"+cr) 'RESUME GLOBAL NAMESPACE
        endif
        '
        '
        if tmnt=0
          if pef=1
'FINISH WHEN DLL IS UNLOADED
wva(3)+="
sub finish() external
  terminate
end sub

._end_prog
mov rax,1
"
          else 'pef=2
'FOR NON-PERSISTENT PROGS
wva(3)+="
._end_prog
terminate
"
          endif
          tmnt=1
        endif
        '
        if nsi
          appendt("o2 k0"+cr)
          nsi=0
        endif
        '
        'CHECK FOR REMAINING CODE
        '
        if epi=0
          a=lookupm("_epilog")
          if a
            wva(3)+=mrcso(a,1)
          endif
          epi=1
        endif
        '
      endif 'tranpass>1
      '
      nsi=0
      '
      if wva(3)
        s=wva(3)
        wva(3)=""
        i=1
        goto mainloop
      endif
      '
      '
      'EXHAUSTED ALL INPUT STREAMS
      '
      exit do ' no proc mapping
      '
    endif
    '
    goto mainloop
    '
  endif 'a<=13
  '
  '==========================
  loop 'FOR ANOTHER STATEMENT
  '==========================
  '
  '
  exitap: 'COMPILE TERMINATION AND ERROR HANDLING
  '======
  '
  '
  'REPORT ERRORS
  '=============
  '
  if ert=0
    if nsl
      ow=""
      nsl--
      select ctb(nsl)
      case 1 : w1="if..endif"
      case 2 : w1="do .. end do"
      case 3 : w1="while .. end while"
      case 4 : w1="for .. next"
      case 5 : w1="Select .. end select"
      end select
      ers="Unterminated blocks at end of script "+w1+cr+cln(nsl)
      ert=30
    elseif funi
      ow=""
      ers="unterminated procedure "+funm : ert=30
    elseif brc
      ow=""
      ers="unclosed brackets at end of script ("+str(brc)+")" : ert=29
    endif
  endif
  '
  if ert>0
    '
    w1="ERROR:"
    select ert
    case 1   : w1="ALERT: "
    case 101 : ers+="Macro undefined or out of scope"
    case 102 : ers+="Macro recursion suspected: "
    case 103 : ers+="Method/property element not implemented"
    case 104 : ers+="Method pointer must have a size of "+str(cpuw)+" bytes"
    end select
    '
    ers=w1+htb+ers+cr
    '
    gosub errordetails
    '
  endif

  '
  'REVERT TO DEFAULT PUNCTUATION
  '
  ct2=59
  sr2=58
  '
  t=left(t,j-1)
  '
  donetran:
  '========
  '
  if compact=0
    'final high pass only
    'putfile "t.txt",t
    'putfile "t.txt",hlis
    'putfile "t.txt",left(proclist,plistend)
  endif
  '
  ' "words processed ",wct
  '
  exit procedure 'exit translate



  '===========
  'SUBROUTINES
  '===========
  '
  uses subs
end procedure 'end translate

