Skip to content

Commit

Permalink
Ensure we don't pretokenise code that's being sent to RAM, as the REP…
Browse files Browse the repository at this point in the history
…L can't handle it
  • Loading branch information
gfwilliams committed Jan 31, 2024
1 parent df37e9d commit cf60c6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions core/codeWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
// 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 @@ -92,7 +92,7 @@
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 @@ -144,7 +144,7 @@
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 @@ -161,7 +161,7 @@
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
2 changes: 1 addition & 1 deletion core/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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
4 changes: 4 additions & 0 deletions plugins/pretokenise.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
// 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

0 comments on commit cf60c6f

Please sign in to comment.