Most recent activity
-
Just had a glance at it and it looks neat.
Currently my Espruinos have a small 'bootloader' set viaE.setBootCode
(I think I understand now how to tokenise it). It receives strings via TCP and evals them - large strings with class definitions, instantiation etc. Does the code processed by eval get pretokenised, provided the flag is set?(side note: I once had a Sinclair ZX81 with 1kB of RAM. The code was immediately entered as tokens.)
-
-
It doesn't seem to work from the console neither from the IDE.
AfterE.setFlags({pretokenise:1}) function test() {print('Hallo')} dump()
function test ...
is shown as plain text, no tokens.
The output of E.getFlags() is>E.getFlags() ={ deepSleep: 0, pretokenise: 1, unsafeFlash: 0, unsyncFiles: 0 }
Version is 2v02, Espruino Wifi.
There seems to be something I'm missing. -
-
I've stumbled upon the pretokenise flag (
E.setFlags({pretokenise:1})
) and I'm wondering if it's worth setting it on an Espruino Puck or WiFi.
As far as I can guess pretokenised JS code doesn't need to get eval'ed anymore, which has the potential to speed up execution significantly.
Does it accelerate the execution of long running code, or has the code already been pretokenised after a while?
Are there any gotchas except of readability and changeability of the tokenised code?
Any comments are appreciated.- Steffen
- Steffen
-
-
Socket instances don't seem to use the attached 'error' listener on error:
>s = net.connect({host: 'xxx', port: 1883}, print) >s.on('error', (e)=>print('EEE',e)) >s.end() >s =Socket: { type: 0, "#onconnect": function () { [native code] }, opt: { host: "neptune", port: 1883 }, conn: false, "#onerror": function (e) { ... }, clsNow: true, cls: true, endd: true } >s.write('x') Uncaught Error: This socket is closed. at line 1 col 12 s.write('x') ^
Is this expected behaviour?
I'm asking because in NodeJS, when an error listener is attached, no exception is thrown but the listener called (with the exception message) instead. If Espruino did the same, the last line should read like this:
EEE Error: This socket is closed. ...
(EEE because the listener prints it, then the error.)
Glad to hear eval does it :)
I've actually grabbed your pretokenise.js from EspruinoTools and done something similar already. First the code was not executable because "return" is defined twice, as LEX_R_BREAK and as LEX_R_RETURN. The returns from a function need to be tokenised as the latter one, but the pretokenise routine returns the first one. After obfuscating the token for LEX_R_BREAK (as "XXreturn") everything runs fine.
The pre-tokenised code uses many of the tokens including class, new, switch/case, try/catch and some bit shift operators.