Yes you can!
A simple compiled JavaScript function:
function foo() {
"compiled";
console.log("hello world");
return 0;
}
foo();
/* Using up arrow several times in left pane one finds the code below
var foo=E.nativeCall(1,'JsVar()',atob('Len/QR1IGUt4RJhHBK5G+AQNB0YaSEzy/WN4RJhHFEuARphHBUYTTEBGoEcVSShGeUQAIkz2eTOYRwAhASMqRo3oSAALRk3yDVaARrBHBkZARqBHKEagRzhGoEcwRqBHBUsAIJhHBLC96PCBsbACAHU9AQChqwIAhS8BAHwAAAB2AAAAaAAAAGhlbGxvIHdvcmxkAGNvbnNvbGUAbG9nAA=='));
*/
Run the program and use the up arrow in the left pane a couple of times to get the native call string.
Using that string one can load it as thumb code in spare memory and call it.
fooHelloThmbcode.js
//used foohello.js to get the string
/* Using up arrow several times in left pane one finds the code below
var foo=E.nativeCall(1,'JsVar()',atob('Len/QR1IGUt4RJhHBK5G+AQNB0YaSEzy/WN4RJhHFEuARphHBUYTTEBGoEcVSShGeUQAIkz2eTOYRwAhASMqRo3oSAALRk3yDVaARrBHBkZARqBHKEagRzhGoEcwRqBHBUsAIJhHBLC96PCBsbACAHU9AQChqwIAhS8BAHwAAAB2AAAAaAAAAGhlbGxvIHdvcmxkAGNvbnNvbGUAbG9nAA=='));
*/
var data = atob('Len/QR1IGUt4RJhHBK5G+AQNB0YaSEzy/WN4RJhHFEuARphHBUYTTEBGoEcVSShGeUQAIkz2eTOYRwAhASMqRo3oSAALRk3yDVaARrBHBkZARqBHKEagRzhGoEcwRqBHBUsAIJhHBLC96PCBsbACAHU9AQChqwIAhS8BAHwAAAB2AAAAaAAAAGhlbGxvIHdvcmxkAGNvbnNvbGUAbG9nAA==');
//var addr = process.memory().stackEndAddress-data.length;
var addr = process.memory().stackEndAddress;
for(var i=0;i<data.length;i++){
poke8(addr+i,data.charCodeAt(i));
console.log((addr+i).toString(16)+","+peek8(addr+i).toString(16));
}
addr++;
var foo= E.nativeCall(addr, 'JsVar()');
foo();
foo();
and the output
20009bda,67
20009bdb,0
hello world
=undefined
>echo(1)
=undefined
>foo();
hello world
=0
>foo();
hello world
=0
>foo();
hello world
=0
>foo();
hello world
=0
>
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes you can!
A simple compiled JavaScript function:
Run the program and use the up arrow in the left pane a couple of times to get the native call string.
Using that string one can load it as thumb code in spare memory and call it.
fooHelloThmbcode.js
and the output
2 Attachments