views:

308

answers:

7

Performance considerations aside, is there any known way to take existing C, C++, or Objective C code and run it directly in the browser? For example, a compiler that converts all the code into some interpreted language that can be run in the browser. Like Javascript, or Actionscript and the Flash player, or I suppose Java and the JVM.

I recognize there are higher level languages like HaXe that can be compiled to different targets. And on the other side there are projects like Cappuccino and GWT that attempt to make Javascript development more like traditional desktop development.

But I was wondering if you had an application that worked on a desktop or an existing code base done in C, C++, or Objective C could it easily be converted to a web based application?

Is there work being done on this front? Is there any practical reason to do this? Basically turn the browser into the OS?

Beside the performance issues, and the entrenchment of OS vendors, are there any technical reasons this couldn't be accomplished? Could this kind of C like code be shoehorned into a virtual machine hosted in a browser?

+3  A: 

I think the closest thing you are looking for is Google Native Client. It is still in early development stages though.

Brian R. Bondy
+9  A: 

Google's Native Client (NaCl) uses a tweaked compiler to create x86 object code that can be verified by the browser and run in a sandbox, without a major performance hit - pretty cool stuff. They've compiled Quake under it.

This Matasano article has a good run-down on how it works.

caf
This is very interesting. Thank you very much.
the_drow
+4  A: 

Here is a C compiler which targets a number of other languages, including Javascript:

http://cluecc.sourceforge.net/

Not sure what state it's in - last I spoke to the author, it handled pure C89 (subject to the limitations of the compiler frontend). AFAIK there are no plans for it ever to support a GUI.

I was wondering if you had an application that worked on a desktop or an existing code base done in C, C++, or Objective C could it easily be converted to a web based application?

That's sort of what Silverlight is for (C# rather than Objective-C, of course), since it makes the .NET runtime available. Porting a desktop app is usually as much about the GUI as it is about the language - if you have a Cocoa app and you want to port it to another environment (whether that's a browser or Windows), then you'd need more than just an Objective-C cross-compiler, you need the Application Kit and so on. WINE being a notable counter-example, it's pretty rare for these OS-specific libraries to be available at all on other platforms, let alone efficiently. And even where they are available, there are look-and-feel and usability problems when the conventions of one UI are bolted on top of another. So people tend to either use portable frameworks to start with, or else completely rewrite the presentation layer of the app.

Basically turn the browser into the OS?

There are several projects underway to turn the browser into a fully-featured environment for applications (not sure whether or not this is what you mean by "OS"). Flash and AIR, Silverlight, HTML 5. None of them plan to provide C as a programming language, as far as I'm aware.

Steve Jessop
+2  A: 

You may be interested in LLVM, the Low Level Virtual Machine. It would be possible to implement an LLVM inside a Java applet, Flash applet, or even in Javascript (I wouldn't be surprised if somebody hasn't already done some or all of the above).

Converting an existing application is a completely different kettle of fish, however. The paradigms of user interaction are so completely different between a "desktop" app and a "browser" app that a lot of it will have to be redesigned before a port is reasonable.

Greg Hewgill
Yeah I was reading about about LLVM on Ars Technica about OS X Snow Leopard. That is kind of what prompted the question. And wondering if it would be able to write a Cocoa app and target OS X, and the browser from the same source.
Gordon Potter
+1  A: 

It seems to me that the major challenges are not related to the language being used. I suspect C would be a very difficult language to implement in JavaScript, but it is possible. It just seems like a bad idea to me.

First off, I would not write a desktop application in C, much less a web application. Second, web applications require a completely different architecture than desktop applications. Simply cross compiling a desktop application will not make it a web application. If it is portability you are looking for, I suggest using a high-level language targeting the JVM.

Jørgen Fogh
+1  A: 

This is possible with an ActiveX control, but this works only in microsoft internet explorer.

codymanix
+2  A: 

Check out Adobe Alchemy (formerly known as FlaCC), which uses LLVM to compile C/C++ to Flash.

Christoph