(* DIRACT.PAS: Please read the bottom of DRAAK.PAS for Copyright details.  *)

procedure handleDira(acts: PAct; syns: PSyn);
var i: byte; actLn: PChar;
begin
 iid := 0; while acts^.asmLn[iid] = ' ' do iid := iid+1;
 case acts^.asmLn[iid+1] of
  'i': diraIf(acts, syns);
  'l': diraCheat := -diraCheat;
  'e': diraCheat := 0;
  '+': if diraCheat = 1 then
   begin actLn := replaceSyn(acts^.asmLn, syns);
    if gdefChar = '!' then writeLn(outCode, strPas(actLn+1));
    if gdefChar = '@' then writeLn(outData, strPas(actLn+1));
   end;
  'u': if diraCheat > -1 then
   begin
    i := 0;
    while jmpQue[i] <> 0 do i := i+1;
    jmpQue[i] := jmpNum;
    jmpNum := jmpNum+1;
   end;
  'o': if diraCheat > -1 then
   begin
    i := 0; while jmpQue[i] <> 0 do i := i+1; i := i -1;
    writeln(outCode, '$l' + stra(jmpQue[i])+'$:');
    jmpQue[i] := 0;
   end;
  'g': if diraCheat > -1 then getStuff(acts, syns);
 end;
end;

procedure diraIf(acts: PAct; syns: PSyn);
var i: byte; actLn: PChar;
begin
 case acts^.asmLn[iid+2] of
  {String Nil?}
  'n':
   begin
    {i := iid+3; while acts^.asmLn[i] = ' ' do i := i+1;}
    actLn := replaceSyn(acts^.asmLn, syns);
    i := 2; while ((actLn[i] <> #0) AND (actLn[i] = ' ')) do i := i+1;
    if actLn[i] = #0 then diraCheat := 1 else diraCheat := -1;
   end;
  {Jmp Que empty?}
  'j': if jmpQue[0] = 0 then diraCheat := 1 else diraCheat := -1;
 end;
end;

procedure getStuff(acts: PAct; syns: PSyn);
var dsyn: PSyn; tempStr: string;
 temp: PChar; pp: word;
 i, o: byte; dvars: PVar;
begin
 case acts^.asmLn[iid+2] of
 'j': {Get last que jump}
  begin
   dsyn := syns;
   while dsyn^.nextSyntax <> nil do dsyn := dsyn^.nextSyntax;
   new(dsyn^.nextSyntax); dsyn := dsyn^.nextSyntax;
   getMem(dsyn^.synType, 5); strcopy(dsyn^.synType, 'word');
   i := 0; while jmpQue[i] <> 0 do i := i+1; i := i -1;
   tempStr := '$l'+stra(jmpQue[i])+'$';
   getMem(dsyn^.synVal, length(tempStr)); strpcopy(dsyn^.synVal, tempStr);
   dsyn^.nextSyntax := nil;
  end;
 'J': ; {Get new jump}
 't':
  begin
   i := iid; while ((acts^.asmLn[i] <> '%') AND (acts^.asmLn[i] <> #0)) do i := i+1;
   if acts^.asmLn[i] = #0 then error(3)
    else i := i+1;
   dsyn := syns;
   for o := 1 to vala(acts^.asmLn+i) do
    dsyn := dsyn^.nextSyntax;
   dvars := momVars;
   while ((strComp(dvars^.varVal, dsyn^.synVal) <> 0) AND (dvars <> nil)) do
    dvars := dvars^.nextVar;
   if dvars = nil then error(7);
   while dsyn^.nextSyntax <> nil do dsyn := dsyn^.nextSyntax;
   new(dsyn^.nextSyntax); dsyn := dsyn^.nextSyntax;
   getMem(dsyn^.synVal, strLen(dvars^.varType)+1);
   temp := dsyn^.synVal; o := 0;
    pp := determineSize(dvars^.varType);
    if pp = 1 then begin temp[o] := 'b'; temp[o+1] := 'y';
     temp[o+2] := 't'; temp[o+3] := 'e'; o := o+4; end;
    if pp = 2 then begin temp[o] := 'b'; temp[o+1] := 'y';
     temp[o+2] := 't'; temp[o+3] := 'e'; o := o+4; end;
    if pp = 4 then begin temp[o] := 'b'; temp[o+1] := 'y';
     temp[o+2] := 't'; temp[o+3] := 'e'; o := o+4; end;
    if pp = 8 then begin temp[o] := 'b'; temp[o+1] := 'y';
     temp[o+2] := 't'; temp[o+3] := 'e'; o := o+4; end;

{   strCopy(dsyn^.synVal, );}
  end;
 end;
end;








{}