Skip to content

Commit

Permalink
Ensure that delay between Storage.write lines applies correctly even …
Browse files Browse the repository at this point in the history
…when line numbers are added.

Also don't add line numbers when uploading to storage as there's no point (fix #179)
  • Loading branch information
gfwilliams committed Sep 2, 2024
1 parent 8eb606c commit ecb16b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
25 changes: 15 additions & 10 deletions core/codeWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@

/// Parse and fix issues like `if (false)\n foo` in the root scope
function reformatCode(code) {
var APPLY_LINE_NUMBERS = false;
var lineNumberOffset = 0;
var ENV = Espruino.Core.Env.getData();
if (ENV && ENV.VERSION_MAJOR && ENV.VERSION_MINOR) {
if (ENV.VERSION_MAJOR>1 ||
ENV.VERSION_MINOR>=81.086) {
if (Espruino.Config.STORE_LINE_NUMBERS)
APPLY_LINE_NUMBERS = true;
}
}
var APPLY_LINE_NUMBERS = false;
var lineNumberOffset = 0;
var ENV = Espruino.Core.Env.getData();
if (ENV && ENV.VERSION_MAJOR && ENV.VERSION_MINOR) {
if (ENV.VERSION_MAJOR>1 ||
ENV.VERSION_MINOR>=81.086) {
if (Espruino.Config.STORE_LINE_NUMBERS)
APPLY_LINE_NUMBERS = true;
}
}
/* There's only any point writing line numbers when we're saving to RAM. Otherwise we just
end up applying line numbers to require("Storage").write lines. see https://github.com/espruino/EspruinoTools/pull/179 */
if (Espruino.Config.SAVE_ON_SEND != 0) {
APPLY_LINE_NUMBERS = false;
}
// Turn cr/lf into just lf (eg. windows -> unix)
code = code.replace(/\r\n/g,"\n");
// First off, try and fix funky characters
Expand Down
8 changes: 4 additions & 4 deletions core/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ To add a new serial device, you must add an object to
return prev;
}
split = findSplitIdx(split, /\x03/, 250, "Ctrl-C"); // Ctrl-C
split = findSplitIdx(split, /reset\(\);\n/, 250, "reset()"); // Reset
split = findSplitIdx(split, /load\(\);\n/, 250, "load()"); // Load
split = findSplitIdx(split, /Modules.addCached\("[^\n]*"\);\n/, 250, "Modules.addCached"); // Adding a module
split = findSplitIdx(split, /\x10require\("Storage"\).write\([^\n]*\);\n/, 500, "Storage.write"); // Write chunk of data
split = findSplitIdx(split, /reset\(\);?\n/, 250, "reset()"); // Reset
split = findSplitIdx(split, /load\(\);?\n/, 250, "load()"); // Load
split = findSplitIdx(split, /Modules.addCached\("[^\n]*"\);?\n/, 250, "Modules.addCached"); // Adding a module
split = findSplitIdx(split, /require\("Storage"\).write\([^\n]*\);?\n/, 500, "Storage.write"); // Write chunk of data
}
// Otherwise split based on block size
if (!split.match || split.end >= writeData[0].blockSize) {
Expand Down

0 comments on commit ecb16b6

Please sign in to comment.