[comp.unix.shell] shell compiler

pfeiffer@irit.fr (Daniel Pfeiffer) (04/09/91)

Is there a compiler for Bourne shell or any other shell?  If not, is
anybody working on this?

Such a beast should draw frequent yet simple commands such as test,
cat, fgrep etc. into the C code (presumably) generated.  If there are
no traps, the last command should just be exec-ed w/o forking while
the others should have a hard wired fork/exec/wait.  When variable
substitutions are necessary they should have strcat or other calls in
place, and internal (i.e. assigned and not exported) variables should
just be char *.

Of course, if it's called upon to compile something like eval $1 `$2`
I suppose things get pretty hopeless.

--
-- Daniel Pfeiffer				<pfeiffer@cix.cict.fr>
-- Tolosa (Toulouse), Midi-Pyrenees, Europe	<pfeiffer@irit.fr>
-- "Beware - polyglot esperantist"		<pfeiffer@frcict81.bitnet>
--

      N
    _---_
   /	 \	NEWS, it goes around the world.
W (-------) E	(sorry, my bitmap doesn't have a world-class resolution)
   \_	_/
     ---
      S

tchrist@convex.COM (Tom Christiansen) (04/16/91)

As I continually point out, an sh compiler will help you very little.  You
need to decompose and recompose your program to minimize execs and
redundant data passes and then recast it in a more suitable language, like
[gn]awk (maybe), perl, or C (as a last resort).  Merely compiling the
conditionals buys you nearly nothing.

--tom

cek@wsc-sun.boeing.com (Conrad Kimball) (04/17/91)

In article <1991Apr16.032713.21502@convex.com>, tchrist@convex.COM (Tom Christiansen) writes:
|> As I continually point out, an sh compiler will help you very little.  You
|> need to decompose and recompose your program to minimize execs and
|> redundant data passes and then recast it in a more suitable language, like
|> [gn]awk (maybe), perl, or C (as a last resort).  Merely compiling the
|> conditionals buys you nearly nothing.

You are right that the primary goal is to minimize execs and such.  BUT,
I believe that a reasonable shell compiler would convert many of the
"shell language" components that are now execs into C function calls that
are semantically equivalent.  For example I have some elaborate scripts
that use lots of "expr" and "tr" commands.  If these were compiled into C
the result would run many, many times faster.

Sure, I could recode the script into another language, but why?  Scripts
are an easy-to-use coding language for incremenntally developing small to
medium size programs.

I liken the issue to that of compiling ordinary languages.  I've got a
program written in the XYZ language that currently executes correctly
but slowly in an interpreted fashion.  I would like a compiler for the
XYZ language that produces highly optimized machine-level object code.
To do this the compiler quite often (especially for vector computers)
recognizes specific constructs in the XYZ language and maps them into
special machine language sequences or calls to special internal functions
that are optimized for speed.  Now, in this case the special constructs
to be recognized are simply some of the commonly used Unix filters.  Note
that in the DOS world there are several "batch file" compilers that
essentially do just this.


--
Conrad Kimball 		 Boeing Computer Services     (206) 865-6410   
Email: cek@wsc-sun.boeing.com or cek%wsc-sun@atc.boeing.com
UUCP:  uw-beaver!bcsaic!wsc-sun!cek