You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Well, at the moment your code is executed from flash, but 'executing' here is means that the function declaration is being executed from flash (but then the execution of the declaration loads it into RAM).

    While Espruino could store the code in flash directly, if you then did fl.erasePage(...) the whole thing would just stop working - it seemed like a bit of a scary thing to do automatically, especially as E.memoryArea could easily also point to RAM. I guess it could be enabled by default, I'd just be worried about it.

    So what you could do is:

    fl.write("t1 = t.toUpperCase(); console.log('hello', t1); ", 487424)
    function hello(t) {
     return eval(E.memoryArea(0x40200000+487424, ??));
    }
    

    Or actually you could do some fixup code like:

    var base = 0x40200000+487424;
    var s = E.memoryArea(base, 72);
    eval(s);
    for (var i in global) {
      if (typeof global[i] == "function") {
        var f = global[i];
        if ("\xFFcod" in f && s.indexOf(f["\xFFcod"])>=0) {
          var c = f["\xFFcod"];
          f["\xFFcod"] = E.memoryArea(base+s.indexOf(c), c.length);
        }
      }
    }
    

    Not tested, but something like that should work.

About

Avatar for Gordon @Gordon started