
Ask HN: Is it feasible to port Apple's Swift to the ESP8266? - schappim
Is it feasible to port Apple&#x27;s Swift to the ESP8266?<p>What would be involved?<p>Does the fact that it&#x27;s so intertwined with LLVM make a difference? Or is it just a case of writing a new interpreter, and the LLVM-ness doesn&#x27;t really make a difference.<p>I&#x27;m a simple web programmer and out of my depth here.<p>I&#x27;m posting this off the back of reading the HN post on &quot;A Kickstarter for funding Micropython port to ESP8266&quot;[1].<p>[1] https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10993953
======
sklogic
One would have to write an Xtensa lx106 backend for LLVM. Given that this
architecture is pretty simple, just another typical RISC, it should be
possible to rewrite, say, a MIPS backend instead of starting from scratch. I'd
say it's about a month of a part-time work for a single developer.

~~~
schappim
Awesome thanks!

------
Tomte
Swift is not an interpreted language, AFAIK.

So you mostly need an LLVM backend for your microcontroller. It might even
exist already.

That has almost nothing in common with the MicroPython situation.

~~~
schappim
Swift can be interpreted in it's repl.[1]

[1]
[https://developer.apple.com/swift/blog/?id=18](https://developer.apple.com/swift/blog/?id=18)

~~~
sklogic
REPL is not an "interpreter" in any way. These are orthogonal concepts.

~~~
schappim
Not that orthogonal...

Like Python, Swift's interpreter is also it's repl. See:
[http://dev.iachieved.it/iachievedit/using-swift-as-a-
scripti...](http://dev.iachieved.it/iachievedit/using-swift-as-a-scripting-
language/)

~~~
sklogic
REPL is not an _interpreter_. 'E' in REPL does not imply any particular
execution mode. It can be anything - direct interpretation, mixed mode
(compilation + VM interpretation), native compilation - whatever.

And, also, the notion of 'scripting' is orthogonal to these two. It got
nothing to do with both a REPL functionality and interpretation. Scripting is
a mode of using a language, not a runtime semantics.

~~~
schappim
All I'm saying is the same binary is acting as the interpreter and REPL for
swift and Python, this is different to other languages. A good example is Ruby
which has it's repl as a seperate binary 'irb'.

~~~
sklogic
There is no interpreter for Swift. At least not yet.

~~~
schappim
If /usr/bin/swiftc is the "swift compiler" what would you call the binary:
/usr/bin/swift ?

~~~
schappim
To answer my own question:

"swift" or "swiftc" w/o -frontend invokes the driver, which launches both the
-frontend and other tools like ld.

The Swift REPL (Read-Eval-Print-Loop) acts like an interpreter. Valid
statements, expressions, and declarations are immediately compiled and
executed.

------
mianos
You would want an xtensa llvm back end first. The biggest issue I think would
be the lack of available ram. Micropython is written from scratch to be very
focussed on being very small and uses a simplistic trace garbage collector
whereas swift uses reference counting that tends to need more ram and more
CPU. Possible but unlikely to be practical.

