Re:Shift.js: Swift to JavaScript Transpiler
by SneakerXZ on Friday November 06, 2015 @08:24PM
(#10523167)
It is a cool idea but I don't understand why you don't write your compiler in Swift so at some point you can compile your compiler with your own compiler.
Unfortunately, it is far from usable. It is unable to parse even basic Swift code.
Re:Shift.js: Swift to JavaScript Transpiler
by dchurchill on Friday November 06, 2015 @08:46PM
(#10523257)
Thanks. The project is still in active early development, so there are still a lot of bugs that need to be worked out. We have a good portion of the core language features covered so far, and are working on adding more.
Re:Shift.js: Swift to JavaScript Transpiler
by mikeash on Friday November 06, 2015 @11:06PM
(#10523647)
It looks like you're using built-in collection types in the resulting JavaScript without accounting for the fact that Swift collections are value types, not reference types. Do you plan to address this? There's another third-party Swift implementation out there focusing on Android which does the same thing and buries this drastic language change in the fine print, which is rather unfortunate.
Re:Shift.js: Swift to JavaScript Transpiler
by Dnld on Friday November 06, 2015 @11:32PM
(#10523719)
This is on the radar. The differences between the languages, especially regarding collections, are tricky. For example we're finalizing a data structure to mimic tuples that would allow value lookup by index and/or element name.
Re:Shift.js: Swift to JavaScript Transpiler
by mikeash on Friday November 06, 2015 @11:34PM
(#10523726)
Great! It must be pretty tricky to translate that across without destroying performance and interoperability. I just wanted to check, because the other one seemed to think it was no big deal to leave it this way.
Re:Shift.js: Swift to JavaScript Transpiler
by xixixao on Friday November 06, 2015 @09:44PM
(#10523430)
(transpiler) I think it's pretty useful. It signifies that the translation is "fairly" simple, as in the case of CoffeeScript, as opposed to traditional compilers targeting assembly or byte code, or even something like Emscripten. It implies that the translation is hand tuned to the target language to be minimal. (I believe Jeremy pretty much coined the term). See https://en.m.wikipedia.org/wiki/Source-to-source_compiler
Re:Shift.js: Swift to JavaScript Transpiler
by xixixao on Sunday November 08, 2015 @09:15AM
(#10528516)
That's quite the point, for a transpiler targeting another language is not just "a way to implement it". It is a conscious decision with many pros and cons and an impact on the transpiled language itself.
Re:Shift.js: Swift to JavaScript Transpiler
by andrewshatnyy on Friday November 06, 2015 @07:42PM
(#10523010)
Concept of compiling things is awesome. But I refuse to understand how making compiled language -> interpreted language is a thing... It should be other way around. I'd love to see something solid like js -> c compiler so my js code runs quick and efficient.
Re:Shift.js: Swift to JavaScript Transpiler
by TazeTSchnitzel on Friday November 06, 2015 @07:47PM
(#10523024)
It's easier to chuck away type information than mystically conjure it out of thin air.
An ahead-of-time compiler can't make JS fast because it lacks the type information needed to do so. That's why you need just-in-time compilation for JS: you can only discover what types go where by running the code.
Re:Shift.js: Swift to JavaScript Transpiler
by comex on Saturday November 07, 2015 @06:56AM
(#10524527)
Because JITs are able to generate code that optimistically assumes variables have certain types (with appropriate deoptimization checks), which is much less expensive than performing full dynamic lookups on every single operation.
Re:Shift.js: Swift to JavaScript Transpiler
by quux on Friday November 06, 2015 @09:48PM
(#10523438)
This is cool, but once swift is open sourced I'd imagine that you'll be able to use emscripten to generate JavaScript code instead of native asm. In fact you can probably do that today by havin swiftc emit llvm IR and imputing that into the emscripten backend like that guy did to get swift running on his android phone.
Re:Shift.js: Swift to JavaScript Transpiler
by dangoor on Friday November 06, 2015 @10:31PM
(#10523553)
There's a pretty big difference between emscripten and compilers that specifically target JS. The ones that target JS will generally use JS memory management and attempt to use JS language features whereas emscripten targets asm.js and manages memory itself within byte arrays.
Unfortunately, it is far from usable. It is unable to parse even basic Swift code.
Is there a solid technical or user requirement for that to be done? If there isn't, why do it?
Looks like an interesting project, though. I'll keep an eye on it.
It is a common design pattern to make the compiler output code in one of the OS SDK languages as a means to speed up development and ease prototyping.
It was just the output of the compiler.
Eiffel compilers are also transpilers as they use C as intermediate language.
Scheme compilers are also transpilers as many use C as intermediate language.
....
An ahead-of-time compiler can't make JS fast because it lacks the type information needed to do so. That's why you need just-in-time compilation for JS: you can only discover what types go where by running the code.
Have one field be an enum of its actual type. Or something along these lines.
I don't see why this is any more difficult than a normal jit that also doesnt have type information.
Most modern JavaScript engines incorporate a JIT compiler, for example.
Hmmmmm
Is it swift to ES5, 6 or 7?
Update: looks like ES5.
swift -> es6 -> es5