
Shift.js: Swift to JavaScript Transpiler - Dnld
https://github.com/shift-js/shift-js
======
SneakerXZ
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.

~~~
dchurchill
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.

~~~
mikeash
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.

~~~
Dnld
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.

~~~
mikeash
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.

------
flipgimble
Whats the benefit of this compared to using
[https://github.com/kripken/emscripten](https://github.com/kripken/emscripten)
?

~~~
Dnld
In short: fewer steps in the conversion process so it is easier to debug the
output, which inevitably happens when using a transpiler.

------
mwcampbell
This word, "transpiler", must die. Call it a translator or a compiler; there's
no need for a new word in this case.

Looks like an interesting project, though. I'll keep an eye on it.

~~~
mckoss
A transpiler is specifically a "source-to-source" language translator.

~~~
pjmlp
So a C compiler is a transpiler, given that classical C compilers just
outputted Assembly that was processed further by the Assembler.

Eiffel compilers are also transpilers as they use C as intermediate language.

Scheme compilers are also transpilers as many use C as intermediate language.

....

------
andrewshatnyy
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.

~~~
spion
A js -> c compiler would actually be much, much slower than current JITs
because of the lack of type information.

~~~
randyrand
Just declare a C union of an int, float, string, etc. All functions take these
unions as function parameters.

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.

~~~
comex
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.

------
petegrif
If something can be written in or for js, it will be.

------
quux
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.

Hmmmmm

~~~
dangoor
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.

------
billylindeman
Does this support classes or protocols yet?

~~~
Dnld
Not yet, classes and structs are planned for the next big push. Protocols
shortly after that.

------
tomelders
Not got time to look at this in depth right now, but glad to see somethibg
like this.

Is it swift to ES5, 6 or 7?

Update: looks like ES5.

~~~
dchurchill
We decided to stick with ES5, since there are still many browser compatibility
issues with ES6.

~~~
theodorton
Why not transpile down to ES6/2015 and rely on Babel for transpilation to ES5?

~~~
rlander
You're asking why he doesn't want to add yet another compilation step? Isn't
that obvious?

swift -> es6 -> es5

~~~
jbigelow76
If you need code written in Language X but insist on using Language Y "yet
another step" probably isn't the deal breaker you imagine it to be.

------
liujoycec
Awesome project, I hope to make some contributions to it on Github in the
future!

------
kairyan
This is a very awesome project, how can I get in..

~~~
geuis
make commits, issue pull requests.

------
Exuma
Why not just learn swift? I never understood this random language -> other
random language...

~~~
supster
I'm guessing so you could use swift to write web front end code. And this goes
from Swift -> JS, so you would still need to learn Swift

~~~
wellsjohnston
yeah, but that seems ridiculous

