Skip to content

Commit

Permalink
updated espruinotools with string conversion bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Feb 6, 2024
1 parent 364b2c1 commit bd301be
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/espruinotools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// EspruinoTools bundle (https://github.com/espruino/EspruinoTools)
// Created with https://github.com/espruino/EspruinoWebIDE/blob/gh-pages/extras/create_espruinotools_js.sh
// Based on EspruinoWebIDE 0.78.12
// Based on EspruinoWebIDE 0.78.14
/**
Copyright 2014 Gordon Williams (gw@pur3.co.uk)

Expand Down Expand Up @@ -4840,7 +4840,7 @@ while (d!==undefined) {console.log(btoa(d));d=f.read(${CHUNKSIZE});}
if (ch<8) {
// if the next character is a digit, it'd be interpreted
// as a 2 digit octal character, so we can't use `\0` to escape it
if (nextCh>='0' && nextCh<='7') js += "\\x0"+ch;
if (nextCh>='0'.charCodeAt() && nextCh<='7'.charCodeAt()) js += "\\x0"+ch;
else js += "\\"+ch;
} else if (ch==8) js += "\\b";
else if (ch==9) js += "\\t";
Expand Down Expand Up @@ -5446,7 +5446,7 @@ To add a new serial device, you must add an object to
for (var i=0; i<str.length; i++) {
var ch = str.charCodeAt(i);
if (ch>=256) {
console.warn("Attempted to send non-8 bit character - code "+ch);
console.warn("serial> Attempted to send non-8 bit character - code "+ch);
ch = "?".charCodeAt(0);
}
bufView[i] = ch;
Expand Down Expand Up @@ -5680,8 +5680,8 @@ To add a new serial device, you must add an object to
// If we're supposed to reset Espruino before sending...
if (Espruino.Config.RESET_BEFORE_SEND) {
// reset Espruino
code = "\x10reset();\n"+code;
}
code = "\x10reset();\n"+code;
}

//console.log("Sending... "+data);
Espruino.Core.Serial.write(code, true, function() {
Expand Down Expand Up @@ -5723,7 +5723,7 @@ To add a new serial device, you must add an object to
for (var i=0;i<code.length;i++) {
var ch = code.charCodeAt(i);
if ((ch<32 || ch>255) && ch!=9/*Tab*/ && ch!=10/*LF*/ && ch!=13/*CR*/) {
console.warn("Funky character code "+ch+" at position "+i+". Replacing with ?");
console.warn("codewriter> Unexpected character code "+ch+" at position "+i+". Replacing with ?");
code = code.substr(0,i)+"?"+code.substr(i+1);
}
}
Expand Down Expand Up @@ -5775,7 +5775,7 @@ To add a new serial device, you must add an object to
while (tok!==undefined) {
var previousString = code.substring(lastIdx, tok.startIdx);
var tokenString = code.substring(tok.startIdx, tok.endIdx);
//console.log("prev "+JSON.stringify(previousString)+" next "+tokenString);
//console.log("codewriter> prev "+JSON.stringify(previousString)+" next "+tokenString);

/* Inserting Alt-Enter newline, which adds newline without trying
to execute */
Expand All @@ -5792,7 +5792,7 @@ To add a new serial device, you must add an object to
tok.str=="catch" || // catch on newline - part of try..catch
lastTok.str=="catch"
) {
//console.log("Possible"+JSON.stringify(previousString));
//console.log("codewriter> Possible"+JSON.stringify(previousString));
previousString = previousString.replace(/\n/g, "\x1B\x0A");
}

Expand Down Expand Up @@ -33561,6 +33561,10 @@ global.esmangle = require('../lib/esmangle');
// When code is sent to Espruino, search it for modules and add extra code required to load them
Espruino.addProcessor("transformForEspruino", function(code, callback) {
if (!Espruino.Config.PRETOKENISE) return callback(code);
if (Espruino.Config.SAVE_ON_SEND == 0) {
console.log("pretokenise> Can't pretokenise code sent to REPL (RAM)");
return callback(code);
}
pretokenise(code, callback);
});
// When code is sent to Espruino, search it for modules and add extra code required to load them
Expand Down Expand Up @@ -33827,6 +33831,8 @@ global.esmangle = require('../lib/esmangle');
var isFlashUpload = Espruino.Config.SAVE_ON_SEND == 1 || isFlashPersistent || isStorageUpload;
if (!isFlashUpload) return callback(code);

var asJS = Espruino.Core.Utils.toJSONishString;

// Check environment vars
var hasStorage = false;
var ENV = Espruino.Core.Env.getData();
Expand All @@ -33847,7 +33853,7 @@ global.esmangle = require('../lib/esmangle');
code = "";
} else {
Espruino.Core.Notifications.error("You have pre-1v96 firmware. Upload size is limited by available RAM");
code = "E.setBootCode("+JSON.stringify(code)+(isFlashPersistent?",true":"")+");load()\n";
code = "E.setBootCode("+asJS(code)+(isFlashPersistent?",true":"")+");load()\n";
}
} else { // new style
var filename;
Expand All @@ -33862,7 +33868,6 @@ global.esmangle = require('../lib/esmangle');
var CHUNKSIZE = 1024;
var newCode = [];
var len = code.length;
var asJS = Espruino.Core.Utils.toJSONishString;
newCode.push('require("Storage").write('+asJS(filename)+','+asJS(code.substr(0,CHUNKSIZE))+',0,'+len+');');
for (var i=CHUNKSIZE;i<len;i+=CHUNKSIZE)
newCode.push('require("Storage").write('+asJS(filename)+','+asJS(code.substr(i,CHUNKSIZE))+','+i+');');
Expand Down

0 comments on commit bd301be

Please sign in to comment.