{$APPTYPE CONSOLE}
program Project1;
uses
  PaxCompiler, PaxProgram, PaxRegister,
  IMPORT_u1, IMPORT_u2;
var
  PaxCompiler1, PaxCompiler2: TPaxCompiler;
  PaxProgram: TPaxProgram;
  PaxPascalLanguage: TPaxPascalLanguage;
  ImportTable1, ImportTable2: Pointer;
begin
  ImportTable1 := CreateNewImportTable;
  ImportTable2 := CreateNewImportTable;

  SetImportTable(ImportTable1); // redirect import to ImportTable1
  RegisterIMPORT_u1;            // register import to ImportTable1

  SetImportTable(ImportTable2); // redirect import to ImportTable2
  RegisterIMPORT_u2;            // register import to ImportTable2

  PaxCompiler1 := TPaxCompiler.Create(nil);
  PaxCompiler2 := TPaxCompiler.Create(nil);

  PaxProgram := TPaxProgram.Create(nil);
  PaxPascalLanguage := TPaxPascalLanguage.Create(nil);

  try
    with PaxCompiler1 do
    begin
      Reset;
      AssignImportTable(ImportTable1);
      RegisterLanguage(PaxPascalLanguage);
      AddModule('1', 'Pascal');
      AddCodeFromFile('1', 'script1.txt');
      if Compile(PaxProgram) then
        PaxProgram.Run
      else
        writeln(ErrorMessage[0]);
    end;

    with PaxCompiler2 do
    begin
      Reset;
      AssignImportTable(ImportTable2);
      RegisterLanguage(PaxPascalLanguage);
      AddModule('1', 'Pascal');
      AddCodeFromFile('1', 'script2.txt');
      if Compile(PaxProgram) then
        PaxProgram.Run
      else
        writeln(ErrorMessage[0]);
    end;

  finally
    PaxCompiler1.Free;
    PaxCompiler2.Free;

    PaxProgram.Free;
    PaxPascalLanguage.Free;
  end;
  writeln('Press any key...');
  Readln;
end.
