On 26 Mar 2011, at 10:31, David Chisnall wrote: > This weekend I've been playing with the clang libraries and working on > compiling Objective-C to JavaScript. It's actually a lot easier than I was > expecting - the clang AST is very easy to work with. There are some things > in C that won't map at all to JS, but I think we can get most of ObjC working > without a huge amount of effort. > > Ideally, I'd like to then implement DO top of WebSocket (maybe with some > fallback to async XML requests), so we can just compile view classes to JS > and run them in the browser, and run model classes on the server, without > developers having to think too hard about where the separation goes.
I've committed this code in Languages/ObjC2JS. It builds as a clang plugin, which uses clang to generates an abstract syntax tree and then walks it emitting JavaScript. I think C is now pretty much done, aside from bitfields (which are horrible!) and 64-bit integers (not easy, might not bother). Objective-C is supported in the core, but not everything works. There may be some corner cases that I have missed, but everything that I've tested works, including: - 'Stack' and 'heap' allocations (all really backed by GC'd JavaScript objects) - Structures - Unions - Arrays - Pointers to any of the above, including aliasing and pointer arithmetic. - C primitive types (except [unsigned] long long), including correct overflow semantics. - Enumerated types and typedefs. - Declaring Objective-C classes / categories / ivars / properties / methods - Sending Objective-C messages - Casting pointers to integers and doing comparisons on them. One thing doesn't work and probably never will (unless JavaScript gets weak references): - Casting integers to pointers. Some things that are nicer than a native implementation: - Returning a pointer to a variable declared with automatic storage, the pointee remains valid until the pointer no longer points there. - Automatic bounds checking on all array accesses, even via pointer arithmetic Most of the remaining work is now in the run time support layer - rewriting code Objective-C and C functionality in JavaScript (for example, I already have a skeleton NSObject, malloc(), and a few others) and then recompiling the GNUstep / Étoilé versions of code that uses these. Implementing the drawing-related classes in terms of canvas operations is also going to be required to get the various view classes working. David -- Sent from my IBM 1620 _______________________________________________ Etoile-dev mailing list Etoile-dev@gna.org https://mail.gna.org/listinfo/etoile-dev