You are reading a single comment by @FManga and its replies. Click here to read the full conversation.
  • By using Flash module it is doable. If you would allocate writable data separately in JS and pass it as pointers to code stored to flash it needs no changes. some js code to manage free internal flash blocks so you would know where the code is loaded shouldn't be hard. the code is position independent. Also you can use your local EspruinoCompiler and distribute just the compiled output as part of your app (with sources somewhere and guide how to recompile it).

  • If you would allocate writable data separately in JS and pass it as pointers to code stored to flash it needs no changes.

    Something like this?

    function malloc(size) {
      return E.getAddressOf(new Uint8Array(size), true);
    }
    

    Can that be called from C? Also, does the GC know when it is safe to free the Uint8Array?
    Would I need to keep references to the Uint8Array in JS to keep it from being collected?

    const blocks = [];
    function malloc(size) {
      let block = new Uint8Array(size);
      blocks.push(block);
      return E.getAddressOf(block, true);
    }
    function free(addr) {
      for (let i = 0; i < blocks.length; ++i) {
        if (addr == E.getAddressOf(blocks[i], true)) {
          let last = blocks.pop();
          if (blocks.length != i) blocks[i] = last;
          return;
        }
      }
    }
    

    Edit: To call that from C it seems what I need is jspGetNamedVariable and jspeFunctionCall.

    Edit2: It might make sense to have a libespruino that implements malloc/free/sin/cos/sinf/cosf/etc by calling the JS implementations.

About

Avatar for FManga @FManga started