Open RossComputerGuy opened 6 years ago
TL;DR: You can't run on the m328, It won't work. You might want to look at uLua
There isn't any explicit support for the AVR platform, if you go to mjs.c
line 33 (or so if things have changed), you will see where CS_PLATFORM
is defined.
Later on in the file you will see various #ifdef
statements that use CS_PLATFORM to configure the environment to the given platform. You would need to do this work for the AVR platform. It doesn't look horrible, but it will be a bit of work.
However there may be some other challenges porting to the m328 specifically. The stated code size of mJS is 50K, and the m328 only has 32K of flash. Additionally because the AVR is an 8-bit platform the generated code would likely be even larger than 50K.
Then you have RAM. You only have 2K of of it on the m328. While mJS can startup in 800 bytes (and again this may be larger on the 8-bit AVR), any JS program is likely to need much of what is left for it's own variable space.
This means your JS code would have to live in either flash (which you don't have enough of), or in EEPROM. The m328 has 2K of that, though you would need to write custom functions to access it.
In short: You might be able to port mJS to the m644 (which has 4K of RAM), but the m1284 (16K) would be more likely. This is a much bigger chip, and more expensive, but it could be done.
If you are looking for a scripting language that can run on an AVR take a look at uLua: https://github.com/deemess/uLua
For those curious, there is a JS Engine that works on the 328p: https://github.com/getfilament/throwback
Does is work on m328 ? Their readme mentions 2k RAM requirement.
to @SpaceboyRoss01 - look at common/platform stuff, add headers for the AVR and re-amalgamate, that shouldn't be hard.
Yes, the m328 has 2K of RAM. The whole project is structured as an Arduino IDE library, and has a simple Arduino test program. It looks like they are executing out of the string which would be held in flash.
Yeah, executing directly from a source is a nice idea. mjs in its early stages (now it's the 5th iteration of refactoring) did the same.
Yeah, there are tradeoffs to it. The biggest code size and the fact that you have to publish the source. Still it is an impressive little project.
Should this issue be closed?
I'm working on a project and I'm using AVR Libc and AVR GCC to compile it. I'm needing a JavaScript engine, so I am using this one. However, whenever I compile, I get lots of errors. Output: