tags:

views:

50

answers:

2

Is there a way I can create a virtual instance of gcc compiler on the client browser when the client opens my website??
By doing so, I can directly pass the user .c file as argument to my compiler instance and then execute it without having to make a POST call to server and execute the file there???

+2  A: 

Originally I userstood your question to be targeting the native platform on which the browser is running:

Consider that Browsers may be running on many different platforms, operatinng systems and processor architectures. Compiling C in the way you describe might be technically doable, but practically infeasible.

I was basing "practically infeasible" on the difficulty of supporting the plethora of widely used browser platforms.

Now I understand that you are thinking more on the lines of targeting a virtual environment. I'll amend practically infeasible to "a large amount of work".

If I understand your intent it is to run a C compiler which emits, shall we say, x86 compiled code and executes it. So to do that we need an emulation of the x86 environment in, say, JavaScript. What's more I think your intent is that the conmpiler itself execute in this environment, so that you can re-use gcc. So you'll need to emulate a file-system too. It's "obvious" that this could be done, but it really is a lot of work. Is it really worth it?

Competition code is small (I guess) even with lots of programmers the number of simultaneous compiles can't be so huge with a decent queued request system, a touch of Ajax, and a bit of back-end scaling how costly is it to support the expected population? What's the ratio of developers to back end systems?

Anyway, if I were to address this problem I'd go for taking the code for an opensource browser and melding in the gcc code. Produce a compiler/browser hybrid. Give that to the developers and tell them "Use this and get zippy compilation speeds, or use your own browser and join the queue."

djna
Of course you don't make a native binary for the local machine. You compile the C to run on a virtual machine written in javascript. Of course writing a C compiler in javascript will be a bit of work.. :-)
R..
An alternative (much easier but slower) would be writing a x86 virtual machine in javascript and running gcc on that...
R..
+1 - I like the deduction practically infeasible.
Praveen S
@djna :-Why is it practically infeasible??i guess you didn't get the whole idea of what i am trying to do.
Silver Spoon
Can i create an instance of my gcc compiler and send it to the client at the time of loading.
Silver Spoon
@Silver Spoon - I was a tad hasty, amended my answer.
djna
@djna :- "Anyway, if I were to address this problem I'd go for taking the code for an opensource browser and melding in the gcc code. Produce a compiler/browser hybrid. Give that to the developers and tell them "Use this and get zippy compilation speeds, or use your own browser and join the queue."...........Can you elaborate on this a little bit...I am unable to understand that.
Silver Spoon
@djna :- And I dnt really need to emulate my file system the way i am thinking about it now...I might be wrong. Can you elaborate a little bit on the need to emulate the file system.
Silver Spoon
File-systems: compilation will reference headers, need to read files. Browser may not permit access to native file system, or it might use different file naming conventions. Your own browser: If the browser includes the gcc code it's running natively on the developer's machine, no limits to what it can do. No need to virtualise anything.
djna
GCC running on an emulator running as javascript or on a JVM in a browser is going to be very painful for all but very small C source files. I'd bet that the memory usage of this would be sky high and the garbage collection would rarely know that it could free memory.
nategoose
A: 

You're not going to use GCC as it is written for this. AT BEST, you could accomplish something simalar if you had a compiler written in Java that targeted the JVM and could be ran as an applet. I don't know what it would take to get something like this working but, I suspect it would take a bit work to get it up and going. As far as I know nothing currently exist that does this.

NoMoreZealots