• If the first statement is a string saying "compiled", it'll have a go at it. It's pretty basic :)

    I got a bit carried away... If you now do:

    function a(b) { "compiled";return b+1; }
    

    it's compiled to:

    var a = E.asm("JsVar (JsVar)",
      "  ldr r0, const_0",
      "  bl jspeiFindInScopes",
      "  push {r0}",
      "  ldr r0, const_1",
      "  bl jsvNewFromInteger",
      "  push {r0}",
      "  pop {r0}",
      "  pop {r1}",
      "  movs r2, #43",
      "  bl jsvMathsOp",
      "  push {r0}",
      "  pop {r0}",
      "  bx lr",
      "jspeiFindInScopes:",
      "jsvNewFromInteger:",
      "jsvNewFromFloat:",
      "jsvNewFromString:",
      "jsvMathsOp:",
      "const_0:",
      "  .word 0x62",
      "const_1:",
      "  .word 0x1");
    

    which is then assembled to:

    var ASM_BASE=process.memory().stackEndAddres­s;
    var ASM_BASE1=ASM_BASE+1/*thumb*/;
    [0x4807,0xf000,0xf80d,0xb401,0x4806,0xf0­00,0xf809,0xb401,0xbc01,0xbc02,0x222b,0x­f000,0xf803,0xb401,0xbc01,0x4770,0x62,0x­0,0x1,0x0].forEach(function(v) { poke16((ASM_BASE+=2)-2,v); });
    var a = E.nativeCall(ASM_BASE1, "JsVar (JsVar)")
    

    It still needs a lot of work - like getting the function pointers for jsvNewFromInteger, and also being aware of which variables are parameters/local, but actually it's very promising indeed.

About

Avatar for Gordon @Gordon started