<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Hi</span></div><div class=""><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">This is a general suggestion, but one I’ve pondered about for quite a long time.</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);">In short, it would be great if the Swift compiler could target embedded systems, and specifically the ARM Cortex M4 architecture (or later).</span></div></blockquote><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Rationale:</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">To date, Swift is ported to x86 and ARM Cortex A architectures (and there may be others in the pipeline)</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">There are billions of low-power devices out there running "single process - multithreaded applications" on ARM Cortex M class devices (<a href="https://en.wikipedia.org/wiki/ARM_Cortex-M" class="">https://en.wikipedia.org/wiki/ARM_Cortex-M</a>). This is typically the world of the hidden embedded computer, be that antilock braking systems, lightbulbs, instrumentation, toys, consumer products, peripherals devices (accelerometers, gps, wifi, bluetooth, gyros, power management, screen controllers, huid) and white goods etc. The list goes on.</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);">These are by far the most pervasive computers in the world, yet we are still writing embedded software in (older versions of) C and C++.</span></div></blockquote><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Now, with IoT, they are being increasingly connected to the internet - security and vulnerabilities are a big concern for IoT (yes, the first fridge has been hacked - <a href="http://www.cnet.com/uk/news/fridge-caught-sending-spam-emails-in-botnet-attack/" class="">http://www.cnet.com/uk/news/fridge-caught-sending-spam-emails-in-botnet-attack/</a>!)</span></div></blockquote><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Cortex M devices are typically used for sense, control and real-time tasks, but now also IoT applications as M-class devices become more capable. </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Of course, as with anything connected to the Internet, IoT applications are potentially vulnerable. </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div></blockquote><span style="background-color: rgba(255, 255, 255, 0);">If you look at mbed 3 from ARM <a href="https://www.mbed.com/en/" class="">https://www.mbed.com/en/</a> (which ARM seem to be pushing quite hard), as I understand it, you see only the Cortex M featured (others might be featured, but MBED 2 was certainly M-class only).<br class=""></span><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">(Also, in the education space, where embedded computing is taught, Cortex M commonly features - the mbed 2 C++ abstraction libraries were originally designed for education and are excellent for prototyping).</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Java ME has recently moved into this space, although I’ve no figures on uptake or how many platforms are supported.</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Most embedded software is still written in C and C++. C is widely viewed to be simply unsafe; safer versions of C++ exist but adoption is slow, and performance is getting slower as I understand it. Also, as a language for humans to write and maintain, it has legacy issues and does not benefit from the complete recent design you get with Swift.</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Swift has a promise to be all things, and coupled with ARC, would seem to be an ideal candidate embedded language?</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div></blockquote><span style="background-color: rgba(255, 255, 255, 0);">Now I’m no compiler engineer (I just happen to teach iOS and real-time embedded computing). </span><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">My take on this is as follows: </span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">For this to happen, Swift + Swift Std. Libs. would need to target the Cortex M instruction set (I suggest M4 or later) and live with more limited protection. </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Maybe it would require an “embedded Swift” variant? </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Some quirks of embedded software: Embedded software often allows, but avoids dynamic memory allocation; there is only one process, but possibly multiple threads; it would need to target the reduced M instruction set; memory is much more limited; direct hardware access is available and required at some level, although most manufacturers (including mbed) provide some abstraction layers (a very good thing).</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div></blockquote><div class=""><div class=""><div class=""><span style="background-color: rgba(255, 255, 255, 0);">I think it would be great if platforms such as mbed 3 could offer Swift as an alternative to C++. I know which language I would rather write.</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">I'm not best placed to say what technical issues might/might not prevent the Swift compiler from targeting Cortex M devices. What’s the view of the community on this?</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);">Nick Outram</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div></div></div></div><span style="background-color: rgba(255, 255, 255, 0);">Plymouth University</span></div></body></html>