Re: Javascript: Time Traveller From the Year 1962!

[prev] [thread] [next] [lurker] [Date index for 2005/04/10]

From: Michael G Schwern
Subject: Re: Javascript: Time Traveller From the Year 1962!
Date: 00:50 on 10 Apr 2005
On Sat, Apr 09, 2005 at 06:09:06PM -0500, Peter da Silva wrote:
> > Ahh, the fundamental difference here is that the include in C goes into the
> > source code but the include in JS goes into the thing USING the source code.
> 
> That's because in "C" it's preprocessed before the compiler sees it.
> 
> Run your javascript through the preprocessor.
> 
> If that's too hard, then hide it, make it automatic, like it is in C. It's
> a function of the hosting environment, not the language.

"Adding a build step for a preprocessor would be clunky and artificial."

ie. I can do it, but it sucks and I hate it.  (See?  Hate.  Thus on-topic. :)

Or maybe I'm not understanding how it would remain a single build/run step
instead of a two step 1. build  2. run as C requires.


> Because this is done at EXECUTE time, and prevents you from writing a JS
> compiler EVEN IF YOU WANTED TO.
> 
> This stuff has to exist OUTSIDE the eval loop. Putting it IN the eval loop
> would prevent Javascript from being usable as anything but a scripting
> language, ever, and it's too good for that.

Assuming by "compiler" you mean "translate to machine-code"...

The compiler can do a pre-processing pass replacing uses of include() with 
the appropriate pasted code.  It then compiles the result.


PS  Somebody earlier had said that JavaScript does not have I/O.
http://www.njs-javascript.org/manual/js_2.html#SEC50
http://www.njs-javascript.org/manual/js_2.html#SEC51
Apparently its a Netscape feature that didn't make it into EMCAscript.

I noticed it because while looking for a Javascript compiler I found
this blurb about a JavaScript compiler and wondered "well how is it writing
a file?"
http://www.njs-javascript.org/manual/js_9.html

"The JavaScript compiler is implemented in the JavaScript language... The 
compiler compiles JavaScript source code to byte-code and it returns a 
fixed byte-code file as the result."

This compiler goes to byte-code not machine code and its implementation of
JavaScript does include an eval() extension.
http://www.njs-javascript.org/manual/js_2.html#SEC62

Generated at 12:00 on 12 Apr 2005 by mariachi 0.52