drozd's comments

drozd | 3 years ago | on: A bare metal programming guide

The linker script specifies that .data section starts where 192k RAM region starts - in other words, addresses of all variables, etc, are in the RAM memory range.

But the firmware image (that resides on flash), which has .text and .data concatenated, has that .data section in Flash region, obviously. So we have .data section residing in Flash region, but all its addresses in the RAM memory range. That's why it is necessary to copy it over manually.

Hope this is clear... Let me know if not!

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

Embedded environment in this context means hardware low on resources, e.g. microcontrollers. Your perception of that word is "embedded into the C/C++ program". These are two different things. I agree that Lua (like some other languages) were designed to be embedded into C/C++ apps.

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

Duktape is nice, and I've mentioned it in the article. However it's quite fat, and can't be used on some boards like ESP8266. It's flash footprint is Megabytes, whereas mJS flash footprint is ~25k.

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

I recall that very much the same opinions were expressed about the JS and backend programming, until node.js appeared. Now the reality is different.

To be honest, we do not think that JS is a good language for embedded. Like any other existing popular scripting language. Perhaps scripted Go would be a better choice.

The point is that in many, many cases scripting brings a lot of benefits to the embedded environment. It all depends on a specific tasks - for some tasks, scripting will never be appropriate.

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

There is no yacc code in either V7 or mJS.

V7 uses hand-written recursive-descent parser. Initially, it was using ordinary C functions, and that created a problem on systems with low stack size. E.g. each '(' starts statement parsing from the top, so 1 + (2 + (3 + (4 + 5))) consumed stack, and sometimes resulted in stack overflow in e.g. interrupt handlers or network callbacks.

Therefore we have rewritten recursive descent using C coroutines, and that is extremely sophisticated piece of work. See https://raw.githubusercontent.com/cesanta/v7/master/v7.c , search for #line 1 "v7/src/parser.c"

mJS on the other hand uses lemon parser generator - the one from sqlite project. It generates a LALR parser which is quite efficient in terms of memory.

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

The ability to script without the need of rebuilding/reflashing the whole firmware is often fairly useful. The most value is not in JS per se, but in the ability to script.

drozd | 9 years ago | on: mJS – A new approach to embedded scripting

Currently, mJS FFI is limited to functions only. And, to simple enough functions.

On how to access memory from mJS: write an accessor function!

    // C
    void setmem(uint8_t *ptr, int index, int value) {
      ptr[index] = value;
    }

    // mJS
    let setmem = ffi('void setmem(void *, int, int)');
    let malloc = ffi('void *malloc(int)');
    let mem = malloc(10);
    setmem(mem, 3, 5);
page 1