Feasibility of Swift for Arduino

arduino

(Matthijs Hollemans) #1

Hi all,

Just out of curiosity, how feasible would it be to get swiftc working as a cross-compiler for Arduino microcontrollers?

Currently the Arduino is programmed in C/C++ and seeing as Swift is positioned as a replacement for those languages, I’m wondering if it could live up to this task already.

Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code generator for this CPU is required. But my main concern is the requirements of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How much of that would be taken up by the Swift runtime?

Any insights would be appreciated!

-Matthijs


(Dmitri Gribenko) #2

The runtime and the standard library currently take much more than 32
kB. Also, the runtime and the standard library in many places rely on
having an OS providing a POSIX API. I'm also unsure about the state
of the LLVM backend for ATmega. I'm not saying that running on a
small 8-bit microcontroller is completely infeasible, but it will
certainly require a major engineering effort across the whole stack,
starting from LLVM.

Dmitri

···

On Fri, Dec 4, 2015 at 5:37 AM, Matthijs Hollemans <mail@hollance.com> wrote:

Hi all,

Just out of curiosity, how feasible would it be to get swiftc working as a cross-compiler for Arduino microcontrollers?

Currently the Arduino is programmed in C/C++ and seeing as Swift is positioned as a replacement for those languages, I’m wondering if it could live up to this task already.

Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code generator for this CPU is required. But my main concern is the requirements of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How much of that would be taken up by the Swift runtime?

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/


(Steven Hepting) #3

Matthijs, perhaps another option for Microcontroller work with Swift would
be the Raspberry Pi. It runs a full version of Linux and has the $5
Raspberry Pi Zero option now.

I'd love to hear of any progress on that front.

···

On Fri, Dec 4, 2015 at 9:26 AM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Fri, Dec 4, 2015 at 5:37 AM, Matthijs Hollemans <mail@hollance.com> > wrote:
> Hi all,
>
> Just out of curiosity, how feasible would it be to get swiftc working as
a cross-compiler for Arduino microcontrollers?
>
> Currently the Arduino is programmed in C/C++ and seeing as Swift is
positioned as a replacement for those languages, I’m wondering if it could
live up to this task already.
>
> Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code
generator for this CPU is required. But my main concern is the requirements
of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How
much of that would be taken up by the Swift runtime?

The runtime and the standard library currently take much more than 32
kB. Also, the runtime and the standard library in many places rely on
having an OS providing a POSIX API. I'm also unsure about the state
of the LLVM backend for ATmega. I'm not saying that running on a
small 8-bit microcontroller is completely infeasible, but it will
certainly require a major engineering effort across the whole stack,
starting from LLVM.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

--
Steven Hepting
iOS Developer


(Dmitri Gribenko) #4

We don't have plans on working on that now, but we have an issue in
the bug tracker for the Raspberry Pi port:
https://bugs.swift.org/browse/SR-40 . Feel free to subscribe!

Dmitri

···

On Fri, Dec 4, 2015 at 11:17 AM, Steven Hepting <shepting@twitter.com> wrote:

Matthijs, perhaps another option for Microcontroller work with Swift would
be the Raspberry Pi. It runs a full version of Linux and has the $5
Raspberry Pi Zero option now.

I'd love to hear of any progress on that front.

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/