home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / IDOL.LZH / IDOLMAIN.ICN < prev    next >
Text File  |  1991-07-18  |  6KB  |  216 lines

  1. #
  2. # Idol: Icon-derived object language, version 8.0
  3. #
  4. # SYNOPSIS:
  5. #
  6. #   idol -install
  7. #   idol prog[.iol] ... [-x args ]
  8. #   prog
  9. #
  10. # FILES:
  11. #
  12. #   ./prog.iol                       : source file
  13. #   ./prog.icn                     : Icon code for non-classes in prog.iol
  14. #   ./idolcode.env/i_object.*      : Icon code for the universal object type
  15. #   ./idolcode.env/classname.icn   : Icon files are generated for each class
  16. #   ./idolcode.env/classname.u[12] : translated class files
  17. #   ./idolcode.env/classname       : class specification/interface
  18. #
  19. # SEE ALSO:
  20. #
  21. #   "Programming in Idol: An Object Primer"
  22. #   (U of Arizona Dept of CS Technical Report #90-10)
  23. #   serves as user's guide and reference manual for Idol
  24. #
  25. ### Global variables
  26. #
  27. # FILES  : fin = input (.iol) file, fout = output (.icn) file
  28. # CSETS  : alpha = identifier characters, nonalpha = everything else
  29. #          alphadot = identifiers + '.'
  30. #          white = whitespace, nonwhite = everything else
  31. # TAQUES : classes in this module
  32. # FLAGS  : comp if we should try to make an executable from args[1]
  33. #          strict if we should generate paranoic encapsulation protection
  34. #          loud if Idol should generate extra console messages
  35. #          exec if we should run the result after translation
  36. # LISTS  : links = names of external icon code to link to
  37. #          imports = names of external classes to import
  38. #          compiles = names of classes which need to be compiled
  39. #
  40. global fin,fout,fName,fLine,alpha,alphadot,white,nonwhite,nonalpha
  41. global classes,comp,exec,strict,links,imports,loud,compiles,compatible,ct
  42. global icontopt,tempenv
  43.  
  44. #
  45. # initialize global variables
  46. #
  47. procedure initialize()
  48.   loud     := 1
  49.   comp     := 0
  50.   alpha    := &ucase ++ &lcase ++ '_' ++ &digits
  51.   nonalpha := &cset -- alpha
  52.   alphadot := alpha ++ '.'
  53.   white    := ' \t\f'
  54.   nonwhite := &cset -- white
  55.   classes  := taque()
  56.   links    := []
  57.   imports  := []
  58.   compiles := []
  59.   sysinitialize()
  60. end
  61.  
  62. procedure main(args)
  63.     initialize()
  64.     if *args = 0 then write("usage: idol files...")
  65.     else {
  66.       if (!args ~== "-version") &
  67.       not tryenvopen(filename("i_object",".u1")) then { 
  68.           tempenv := 0
  69.           install(args)
  70.       }
  71.       every i := 1 to *args do {
  72.     if \exec then next            # after -x, args are for execution
  73.     if args[i][1] == "-" then {
  74.       case map(args[i]) of {
  75.         "-c"   : {
  76.         sysok := &null
  77.         if comp = 0 then comp := -1        # don't make exe
  78.         }
  79.         "-ic"     : compatible := 1
  80.         "-quiet"  : loud := &null
  81.         "-strict" : strict := 1
  82.         "-s"      : sysok := &null
  83.         "-t"      : comp := -2                      # don't translate
  84.         "-version": return write("Idol version 8.0 of 10/6/90") & 0
  85.         "-x"      : exec := i
  86.         default   : icontopt ||:= args[i] || " "
  87.       }
  88.         }
  89.         else {
  90.       \tempenv +:= 1
  91.       if args[i] := fileroot(args[i],".cl") then {
  92.           push(imports,args[i])
  93.       }
  94.       else if args[i] := fileroot(args[i],".icn") then {
  95.           push(links,args[i])
  96.           icont(" -c "||args[i])
  97.       }
  98.       else if args[i] := fileroot(args[i],".u1") then {
  99.           push(links,args[i])
  100.       }
  101.       else if (args[i] := fileroot(args[i],".iol")) |
  102.           tryopen(filename(args[i],".iol"),"r") then {
  103.           /exe := i
  104.           args[i] := fileroot(args[i],".iol")
  105.           /fout := sysopen(filename(args[i],".icn"),"w")
  106.           readinput(filename(args[i],".iol"),1)
  107.           } else {
  108.                   #
  109.               # look for an appropriate .icn, .u1 or class file
  110.               #
  111.           if tryopen(filename(args[i],".icn"),"r") then {
  112.               push(links,args[i])
  113.               icont(" -c "||args[i])
  114.           }
  115.           else if tryopen(filename(args[i],".u1")) then {
  116.               push(links,args[i])
  117.           }
  118.           else if tryenvopen(args[i]) then {
  119.               push(imports,args[i])
  120.           }
  121.           }
  122.       }
  123.       }
  124.       if gencode() then {
  125.       close(\fout)
  126.       if comp = 1 & (not makeexe(args,exe)) then
  127.           stop("Idol exits after errors creating executable")
  128.       } else {
  129.       close(\fout)
  130.       stop("Idol exits after errors translating")
  131.       }
  132.     }
  133.     #
  134.     # if we built an executable without separate compilation AND
  135.     # there's no IDOLENV class environment AND
  136.     # we had to install an environment then remove the environment
  137.     #
  138.     if (comp = 1) & (\tempenv < 2) & not mygetenv("IDOLENV") then uninstall()
  139. end
  140.  
  141. #
  142. # tell whether the character following s is within a quote or not
  143. #
  144. procedure notquote(s)
  145.   outs := ""
  146.   #
  147.   # eliminate escaped quotes.
  148.   # this is a bug for people who write code like \"hello"...
  149.   s ? {
  150.     while outs ||:= tab(find("\\")+1) do move(1)
  151.     outs ||:= tab(0)
  152.   }
  153.   # see if every quote has a matching endquote
  154.   outs ? {
  155.     while s := tab(find("\""|"'")+1) do {
  156.     if not tab(find(s[-1])+1) then fail
  157.     }
  158.   }
  159.   return
  160. end
  161.  
  162. #
  163. # A contemplated addition: shorthand $.foo for self.foo ?
  164. #
  165. #procedure selfdot(line)
  166. #  i := 1
  167. #  while ((i := find("$.",line,i)) & notquote(line[1:i])) do line[i]:="self"
  168. #end
  169.  
  170. #
  171. # error/warning/message handling
  172. #
  173. procedure halt(args[])
  174.   errsrc()
  175.   every writes(&errout,!args)
  176.   stop()
  177. end
  178.  
  179. procedure warn(args[])
  180.   errsrc()
  181.   every writes(&errout,!args)
  182.   write(&errout)
  183. end
  184.  
  185. procedure errsrc()
  186.   writes(&errout,"\"",\fName,"\", line ",\fLine,": Idol/")
  187. end
  188. #
  189. # System-independent, but system related routines
  190. #
  191. procedure tryopen(file,mode)
  192.   if f := open(file,mode) then return close(f)
  193. end
  194. procedure tryenvopen(file,mode)
  195.   return tryopen(envpath(file),mode)
  196. end
  197. procedure sysopen(file,mode)
  198.   if not (f := open(file,mode)) then
  199.       halt("Couldn't open file ",file," for mode ",mode)
  200.   return f
  201. end
  202. procedure envopen(file,mode)
  203.   return sysopen(envpath(file),mode)
  204. end
  205. procedure writelink(s)
  206.   write(fout,"link \"",s,"\"")
  207. end
  208. procedure icont(argstr,prefix)
  209. static s
  210. initial { s := (mygetenv("ICONT")|"icont") }
  211.   return mysystem((\prefix|"") ||s||icontopt||argstr)
  212. end
  213. procedure mygetenv(s)
  214.   return if &features == "environment variables" then getenv(s)
  215. end
  216.