[Mono-list] Javascript and Mono

Miguel de Icaza miguel@ximian.com
06 Jan 2003 12:59:32 -0500


> Looking at the .NET class libraries & compilers (and what's in mono CVS) 
> I see the following:
> Microsoft.CSharp/JScript/VisualBasic/Vsa/Win32
> Is it correct to assume that Microsoft.CSharp/JScript/VisualBasic contain:
> * runtime for JScript and VisualBasic
> * compilation / code generation classes (for all)

I would have to take a deeper look at this, but here is more or less
what is included:

	* A command line compiler (jsc).

	* An embeddable compiler (so you can compile code on the
	  flight and run it).

	* An interface to expose some of your internals and let JScript
	  consume them.

	* A CodeDOM "provider", that would let you generate javascript
	  code from the CodeDOM API.

The embeddable compiler is required, because even if you compile the
code in advance:

	jsc proggie.js

proggie.js might need to dynamically evaluate some code, so the
resulting code will actually call into the compiler.

My suggestion on how to make Janet a jsc replacement is to start by
slowly adding the command line handling (for jsc.exe) so it remains
compatible;  Writing the backend that uses reflection.emit to generate
the code, and as we go, compare the output of our compiler with their

The last step is important because their compiler will likely call into
the runtime for "support" methods and functions.  To allow full
compatibility, we need to have those methods as well, and use those
methods as well (this is to achieve the `copy js-program.exe to linux
and run').

Writing compilers with Reflection.Emit is not only easy, but a lot of
fun, so you should not be worried about it.  Trust me, its the easiest
way of writing a compiler ever.  Every kid in the block assumes you are
some kind of master of the universe. 

> If so, is this being done yet? (and why is Microsoft.VisualBasic and 
> Microsoft.CSharp not in the same parent directory?)

I do not understand this question ;-)

> I assume the Microsoft.VisualBasic/CSharp/JScript will function in a 
> similar way, is that correct? (is there code in CSharp/VisualBasic we 
> can re-use for JScript?)

I am not sure about what lives in Microsoft.CSharp;  But what lives in
Microsoft.VisualBasic is runtime support.  

For example, when the compiler finds "a + b" in Visual Basic, a number
of things might happen:

	a and b are known types.
	one of a or b is a known type.
	none of them are a known type.

Depending on that information the compiler will try to call the best
method.  Lets assume (for simplicity) that they might be integers:

	a and b integers: generate IL code directly.

	a or b unknown: generate "call Microsoft.VisualBasic.AddTwoThings"

`AddTwoThings' is just a helper function.  And the whole assembly is
packed with helper functions that the compiler uses.

C# uses very very very few helper functions from assemblies.

> ps. how are we going to name the mono JScript compiler?

`janet' or `jsc' for the command line compiler sounds good.  

> ps2. I assume we are also prototyping this compiler in the janet module 
> (so I need to add new directories)?

Yes, this should be done in the janet module.