如何为Arduino或类似的微控制器编写JavaScript编译器? [英] How can I write a JavaScript compiler for Arduino or similar microcontroller?

查看:81
本文介绍了如何为Arduino或类似的微控制器编写JavaScript编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这个问题会引起人们的注意,并且我意识到JavaScript在传统上是一种解释型语言,请让我解释一下:

我是专门从事Web应用程序(特别是.NET堆栈)的软件工程师.作为一种爱好,我喜欢创建在基于Arduino的组件上运行的 RC UAV .>

我还想用Arduino做其他几件事,但是坦率地说,C/C ++不是我最强的语言,我不想花有限的业余时间在C上读书.

我(以及我敢肯定的其他许多人)已经想到,如果使用Arduino/嵌入式生态系统接口的语言更为普遍,它将变得更加丰富.对我来说,JavaScript似乎是一个不错的选择,因为大多数软件开发人员都知道它,并且在JavaScript世界中构建开源框架和插件的文化非常牢固.

因此,回到我的第一个问题:如果我希望能够使用JavaScript为Arduino编写和编译代码,我将如何开始?当然,我正在构想一个开源项目,但是我需要一些帮助以吸引人.我从来没有编写过编译器,因此不胜感激.

解决方案

这是一个很大的问题,Arduino UNO,LEO等中的微控制器是ATmega328p,它具有32K的闪存用于程序存储,2K的RAM,和2K的EEPROM(用于永久存储).对于像Java语言这样的语言来说,这是非常严格的.

现在有人写了用于ATmega128的Javascript编译器,您可以在Arduino Mega,具有4K RAM和更多闪存.

如果您升级到Arduino DUE,Arduino Zero或Teensy 3.x(所有这些都是基于ARM的),则可以查看 Espruino 是用于ARM的JavaScript版本,但是您仍然必须将其移植到Arduino硬件.

因此,如果您真正想要的是可以运行JavaScript的嵌入式板,那么我只看一下Esprino板本身.

最后,如果您仍然对ATmega328p的JavaScript感兴趣,那么应该考虑为JavaScript语言的子集编写JavaScript到C ++转换器.这样做的范围超出了SO答复的范围,所以我建议从著名的《龙书》 ,因为它仍然可能是学习如何编写编译器的最佳资源.

I realize that this question will raise some eyebrows, and I realize that JavaScript is traditionally an interpreted language, please let me explain:

I am software engineer specializing in web applications (.NET stack specifically). As a hobby, I enjoy creating RC UAVs that run on Arduino-based components.

There are several other things I would like to do with Arduino as well but, frankly, C / C++ is not my strongest language and I don't want to spend limited spare time reading books on C.

It has occurred to me--and many others I am sure--that the Arduino / embedded ecosystem would be far richer if the language used to interface with it were a more common one. JavaScript seems like a good candidate to me because most software developers know it and the culture of building open source frameworks and plugins is very strong in the JavaScript world.

So, back to my first question: If I wanted to be able to write and compile code for my Arduino in JavaScript, how would I get started? I am envisioning an open-source project of course, but I need some help getting traction. I have never written a compiler, so any help is appreciated.

解决方案

This is quite an ask, the microcontroller in the Arduino UNO, LEO, etc is the ATmega328p, which has 32K of flash for program storage, 2K of RAM, and 2K of EEPROM (for persistent storage). That is quite tight for a language like Javascript.

Now someone has written a Javascript compiler for the ATmega128, which you will find in the Arduino Mega, which has 4K of RAM and much more flash.

If you move up to the Arduino DUE, the Arduino Zero, or the Teensy 3.x — all of which are ARM based — then you can look into Espruino which is a version of JavaScript for ARM, but you will still have to port it to the Arduino hardware.

So if what you really want is an embedded board that can run JavaScript then I would just look at the Esprino board itself.

Finally if you are still set on JavaScript for the ATmega328p, then you should look into writing a JavaScript to C++ translator for a subset of the JavaScript language. The scope of doing this is well outside of a SO reply, so I would suggest starting with the famous Dragon Book as it is still probably the best resource for learning how to write compilers.

这篇关于如何为Arduino或类似的微控制器编写JavaScript编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆