atop1.clu 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. % ATOP1 CLU
  2. %
  3. % CLUMAC assembler: top level
  4. _BIO = 7;
  5. start_up = proc ();
  6. jcl: str := sys$jcl();
  7. if jcl = ""
  8. then return; end;
  9. assem(jcl);
  10. quit_();
  11. end start_up;
  12. assem = proc (s: str);
  13. sec, msec, usec: int := runt();
  14. e: env := value$id(".assem_env");
  15. e.err := false;
  16. ins, outs: str, erf: file := process_line(s);
  17. e.output := erf;
  18. do_lines(e, ins);
  19. if ~e.err
  20. then fs: filespec := filespec$resolve(outs);
  21. c: chan := sys$open1(fs, _BIO);
  22. env$dump(e, c);
  23. chan$close(c);
  24. end;
  25. except when open_failed: file$puts(erf, "couldn't open binary file!\n"); end;
  26. sec1, msec1, usec1: int := runt();
  27. sec, msec, usec := longsub(sec1, msec1, usec1, sec, msec, usec);
  28. file$puts(erf, "time = ");
  29. file$puts(erf, time_format(sec, msec, usec));
  30. file$putc(erf, '\n');
  31. file$close(erf);
  32. end assem;
  33. process_line = proc (s: str) returns (str, str, file);
  34. line: ac := str$s2ac(s);
  35. ins: str := peel_string(line);
  36. outs: str;
  37. if '_' = scan$deblank(line)
  38. then ac$reml(line);
  39. outs := fix_filename(ins);
  40. ins := fixup_filename(peel_string(line), "clumac");
  41. else ins := fixup_filename(ins, "clumac");
  42. outs := make_output(ins, "bin");
  43. end;
  44. erf: file;
  45. if '(' = scan$deblank(line)
  46. then erf := file$open_write(make_output(ins, "err"));
  47. else erf := file$tyo();
  48. end;
  49. except when open_failed: erf := file$tyo(); end;
  50. return(ins, outs, erf);
  51. end process_line;
  52. peel_string = proc (line: ac) returns (str);
  53. a: ac := ac$predict(1, ac$size(line));
  54. scan$deblank(line);
  55. while true do
  56. c: char := ac$bottom(line);
  57. if c = '_' cor c = '('
  58. then break;
  59. elseif c = '\021'
  60. then ac$reml(line); end;
  61. ac$addh(a, ac$reml(line));
  62. end;
  63. except when bounds: ; end;
  64. return(str$ac2s(a));
  65. end peel_string;
  66. fixup_filename = proc (fs: str, nm2: str) returns (str);
  67. if str$indexc(':', fs) = 0
  68. then fs := "dsk:" || fs; end;
  69. if str$indexc(';', fs) = 0
  70. then fs := str$append(sname(), ';') || fs; end;
  71. fs := fix_filename(fs);
  72. if str$indexc(' ', fs) = 0
  73. then fs := str$append(fs, ' ');
  74. ns: str := fs || nm2;
  75. if file$exists(ns)
  76. then fs := ns;
  77. else fs := str$append(fs, '>');
  78. end;
  79. end;
  80. return(fs);
  81. end fixup_filename;
  82. make_output = proc (fs: str, nm2: str) returns (str);
  83. if str$indexs("dsk:", fs) = 0
  84. then i: int := str$indexc(';', fs);
  85. j: int := str$indexc(':', fs) + 1;
  86. if i < j
  87. then fs := str$substr(fs, 1, i) || "dsk:" || str$rest(fs, j);
  88. else fs := "dsk:" || str$rest(fs, j);
  89. end;
  90. end;
  91. if nm2 = "" then return(fs); end;
  92. i: int := str$indexc(' ', fs);
  93. if i > 0
  94. then return(str$substr(fs, 1, i) || nm2);
  95. else return(fs || " " || nm2);
  96. end;
  97. end make_output;